-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlarge.html
473 lines (431 loc) · 13.8 KB
/
large.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<!DOCTYPE html>
<html>
<head>
<script>
/*************************/
// Hard-coded paramters
//var starfieldWidth = 1750;
//var starfieldHeight = 1090;
var starfieldWidth = 1240;
var starfieldHeight = 1370;
var initialSize1Count = 383;
var initialSize2Count = 96;
var initialSize3Count = 36;
var initialSize4Count = 12;
var initialEdgeFadeOut = 150;
var initialBorder = 0;
// Optional background image
//var bgImage = "constellations.png";
var bgImage = "";
/*************************/
</script>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<style>
body, h3 {
margin: 0;
background: #000;
color: #bbb;
}
input {
background: #000;
color: #aaa;
border: 1px solid #555;
}
input[type=submit] {
background: #555;
color: #aaa;
border: 1px solid #aaa;
}
input[disabled] {
background: #222;
color: #555;
border: 1px solid #555;
}
a {
color: #aaa;
}
canvas {
float: left;
margin-right: 20px;
border: solid #000;
}
#config {
padding-top: 5px;
}
#currentParams {
position: absolute;
padding: 10px;
margin: 10px;
background-color: #000;
border: 1px solid #fff;
color: #fff;
display: none;
font-family: 'Courier New', Monospace;
}
</style>
<script src="perlin.js"></script>
<script src="p5.min.js"></script>
<script>
var processingInstance;
var seedHistory = new Array();
var seedHistoryPtr = 0;
function newSeed() {
var seed = parseInt(Math.random() * 99999);
document.getElementById('seed').value = seed;
seedHistoryPtr = seedHistory.length;
seedHistory[seedHistoryPtr] = seed;
updateSeedHistButtons();
update();
}
function prevSeed() {
seedHistoryPtr--;
document.getElementById('seed').value = seedHistory[seedHistoryPtr];
updateSeedHistButtons();
update();
}
function nextSeed() {
seedHistoryPtr++;
document.getElementById('seed').value = seedHistory[seedHistoryPtr];
updateSeedHistButtons();
update();
}
function updateSeedHistButtons () {
document.getElementById('prevSeed').disabled = (seedHistoryPtr == 0);
document.getElementById('nextSeed').disabled = (seedHistoryPtr+1 == seedHistory.length);
}
var clusterMaskSeedHistory = new Array();
var clusterMaskSeedHistoryPtr = 0;
function newClusterMaskSeed() {
var clusterMaskSeed = parseInt(Math.random() * 99999);
document.getElementById('clusterMaskSeed').value = clusterMaskSeed;
clusterMaskSeedHistoryPtr = clusterMaskSeedHistory.length;
clusterMaskSeedHistory[clusterMaskSeedHistoryPtr] = clusterMaskSeed;
updateClusterMaskSeedHistButtons();
update();
}
function prevClusterMaskSeed() {
clusterMaskSeedHistoryPtr--;
document.getElementById('clusterMaskSeed').value = clusterMaskSeedHistory[clusterMaskSeedHistoryPtr];
updateClusterMaskSeedHistButtons();
update();
}
function nextClusterMaskSeed() {
clusterMaskSeedHistoryPtr++;
document.getElementById('clusterMaskSeed').value = clusterMaskSeedHistory[clusterMaskSeedHistoryPtr];
updateClusterMaskSeedHistButtons();
update();
}
function updateClusterMaskSeedHistButtons () {
document.getElementById('prevClusterMaskSeed').disabled = (clusterMaskSeedHistoryPtr == 0);
document.getElementById('nextClusterMaskSeed').disabled = (clusterMaskSeedHistoryPtr+1 == clusterMaskSeedHistory.length);
}
function update() {
var width = parseInt(document.getElementById('fieldWidth').value);
var height = parseInt(document.getElementById('fieldHeight').value);
processingInstance.resizeCanvas(width, height);
processingInstance.redraw();
}
function generatePNG() {
if (!processingInstance) {
processingInstance = Processing.getInstanceById('starfield');
}
processingInstance.save("starfield.png");
}
window.saveParamsFlag = false;
function saveParams() {
if (!processingInstance) {
processingInstance = Processing.getInstanceById('starfield');
}
window.saveParamsFlag = true;
processingInstance.redraw();
window.saveParamsFlag = false;
}
if (bgImage != '') {
window.imgloader = window.setInterval(update, 100);
}
let p5Instance = function(p) {
var width = window.starfieldWidth;
var height = window.starfieldHeight;
p.setup = function() {
if (bgImage != '') {
imported_image = p.loadImage(bgImage);
}
var canvas = p.createCanvas(width, height);
canvas.parent('starfield');
p.noLoop();
};
p.draw = function() {
var fadeout = parseInt(document.getElementById('fadeout').value);
var border = parseInt(document.getElementById('border').value);
document.getElementById('starfield').style.borderWidth = border + 'px';
var seed = parseInt(document.getElementById('seed').value);
if (isNaN(seed) || seed == 0) {
newSeed();
seed = parseInt(document.getElementById('seed').value);
}
p.randomSeed(seed);
if (bgImage != '' && imported_image != null && imported_image.loaded) {
window.clearTimeout(window.imgloader);
p.image(imported_image, 0, 0, width, height);
} else {
p.background(0, 0, 0);
}
var cc = document.getElementById('cc').checked;
var doShapecode = document.getElementById('shapecode').checked;
var doObstacles = document.getElementById('obstacles').checked;
var size1count = parseInt(document.getElementById('size1').value);
var size2count = parseInt(document.getElementById('size2').value);
var size3count = parseInt(document.getElementById('size3').value);
var size4count = parseInt(document.getElementById('size4').value);
var stars = [
{
size: 1,
count: size1count,
color: cc ? [255, 0, 0] : [255, 255, 255]
},
{
size: 2,
count: size2count,
color: cc ? [0, 255, 0] : [255, 255, 255]
},
{
size: 3,
count: size3count,
color: cc ? [0, 0, 255] : [255, 255, 255]
},
{
size: 4,
count: size4count,
color: cc ? [255, 255, 0] : [255, 255, 255]
}
];
var showsize = [
document.getElementById('showsize1').checked,
document.getElementById('showsize2').checked,
document.getElementById('showsize3').checked,
document.getElementById('showsize4').checked
];
var clusterMaskSeed = parseInt(document.getElementById('clusterMaskSeed').value);
if (isNaN(clusterMaskSeed) || clusterMaskSeed == 0) {
newClusterMaskSeed();
clusterMaskSeed = parseInt(document.getElementById('clusterMaskSeed').value);
}
// spaceAmount 0->100 clusterMaskThreshold 1.0->0.3
var spaceAmount = parseInt(document.getElementById('spaceAmount').value);
if (spaceAmount < 0) { spaceAmount=0; }
if (spaceAmount> 100) { spaceAmount = 100; }
var clusterMaskThreshold = (100 - spaceAmount) * 0.006 + 0.4;
var clusterAmount = parseInt(document.getElementById('clusterAmount').value);
if (clusterAmount < 0) { clusterAmount=0; }
if (clusterAmount > 100) { clusterAmount = 100; }
var clusterMaskScale = parseInt(document.getElementById('clusterMaskScale').value);
if (isNaN(clusterMaskScale) || clusterMaskScale < 1) { clusterMaskScale = 1; } clusterMaskScale /= 100; for (var
i = 0; i < stars.length; i++) {
p.strokeWeight(stars[i].size); for (var c = 0; c < stars[i].count; c++) {
do {
do {
x = Math.floor(p.random(0, width)); y = Math.floor(p.random(0, height)); var xn = x / width; var yn = y / height;
n = PerlinNoise.noise(xn / clusterMaskScale, yn / clusterMaskScale, clusterMaskSeed);
} while (n >
clusterMaskThreshold);
var bTryAgain = false;
// Fade out cluster edges?
if (clusterAmount > 0 && p.random(0, clusterAmount) > Math.abs(n - clusterMaskThreshold) * 100) {
bTryAgain = true;
}
// Fade out borders?
if (fadeout > 0) {
var xEdgeDistance = x < width / 2 ? x : width - x; var yEdgeDistance = y < height / 2 ? y : height - y; var
edgeDistance = xEdgeDistance < yEdgeDistance ? xEdgeDistance : yEdgeDistance; if (edgeDistance < fadeout) {
var fadeChance = edgeDistance / fadeout; if (p.random(0, fadeout) > edgeDistance) {
bTryAgain = true;
}
}
}
} while (bTryAgain);
if (showsize[i]) {
p.stroke(stars[i].color[0], stars[i].color[1], stars[i].color[2]);
if (doShapecode){
switch (i) {
case 0:
case 1:
p.point(x, y);
break;
case 2:
p.triangle(x, y, x - 2, y + 4, x + 2, y + 4);
break;
case 3:
p.fill(stars[i].color[0], stars[i].color[1], stars[i].color[2]);
p.square(x, y, i * 2);
}
} else {
p.point(x, y);
}
}
}
}
if (window.saveParamsFlag) {
var currentParams = '';
currentParams += 'Random seed: ' + seed + "<br>";
currentParams += '0.50mm fibres: ' + size1count + "<br>";
currentParams += '0.75mm fibres: ' + size2count + "<br>";
currentParams += '1.00mm fibres: ' + size3count + "<br>";
currentParams += '1.50mm fibres: ' + size4count + "<br>";
currentParams += 'Colour-code fibre sizes: ' + (cc ? 'yes' : 'no') + "<br><br>";
currentParams += 'Shape-code fibre sizes: ' + (shapecode ? 'yes' : 'no') + "<br><br>";
currentParams += 'Sparser towards edges: ' + fadeout + "<br>";
currentParams += 'Black border: ' + border + "<br><br>";
currentParams += 'Space/cluster seed: ' + clusterMaskSeed + "<br>";
currentParams += 'Space/cluster scale: ' + clusterMaskScale * 100 + "<br>";
currentParams += 'Space amount: ' + spaceAmount + "<br>";
currentParams += 'Cluster amount: ' + clusterAmount + "<br>";
document.getElementById('currentParams').innerHTML = currentParams;
document.getElementById('currentParams').style.display = 'block';
} else {
document.getElementById('currentParams').style.display = 'none';
}
if (doObstacles){
// Draw ceiling light
p.noFill();
p.ellipseMode(p.CENTER);
p.stroke(0, 0, 255, 128);
//p.circle(797,555,65);
p.circle(643,688,65);
// Draw joists
p.stroke(0,255,0,128);
p.strokeWeight(1);
for (var x=180;x<1750;x+=240) { // 24" joists
p.rect(x, 0, 15, height);
}
// Draw Extra grids
p.line(0,360,1240,360);
p.line(0,1010,1240,1010);
}
};
};
processingInstance = new p5(p5Instance);
</script>
</head>
<body>
<div id=currentParams></div>
<div id="starfield"></div>
<div id=config>
<h3>Starfield generator by <a href="http://burnit.co.uk/" target="_blank">Seb Francis</a></h3>
<br>
<table>
<tr>
<td>Field width:</td>
<script>
document.write('<td><input type=text id=fieldWidth value="' + starfieldWidth + '" size=5 maxlength=5 onfocusout="update();"></td>');
</script>
<td>Field height:</td>
<script>
document.write('<td><input type=text id=fieldHeight value="' + starfieldHeight + '" size=5 maxlength=5 onfocusout="update();"></td>');
</script>
</tr>
<tr>
<td>Random seed:</td>
<td><input type=text id=seed size=4 maxlength=5 onkeyup="update();"></td>
<td><input type=submit value="New seed" onclick="newSeed();">
<input type=submit value="<" id=prevSeed onclick="prevSeed();" disabled><input type=submit value=">" id=nextSeed onclick="nextSeed();" disabled></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>0.50mm fibres:</td>
<script>
document.write('<td><input type=text id=size1 value="'+initialSize1Count+'" size=4 maxlength=4 onkeyup="update();"></td>');
</script>
<td><input type=checkbox id=showsize1 checked onclick="update();"></td>
</tr>
<tr>
<td>0.75mm fibres:</td>
<script>
document.write('<td><input type=text id=size2 value="'+initialSize2Count+'" size=4 maxlength=4 onkeyup="update();"></td>');
</script>
<td><input type=checkbox id=showsize2 checked onclick="update();"></td>
</tr>
<tr>
<td>1.00mm fibres:</td>
<script>
document.write('<td><input type=text id=size3 value="'+initialSize3Count+'" size=4 maxlength=4 onkeyup="update();"></td>');
</script>
<td><input type=checkbox id=showsize3 checked onclick="update();"></td>
</tr>
<tr>
<td>1.50mm fibres:</td>
<script>
document.write('<td><input type=text id=size4 value="'+initialSize4Count+'" size=4 maxlength=4 onkeyup="update();"></td>');
</script>
<td><input type=checkbox id=showsize4 checked onclick="update();"></td>
</tr>
<tr>
<td>Colour-code fibre sizes:</td>
<td><input type=checkbox id=cc onclick="update();"></td>
</tr>
<tr>
<td>Shape-code fibre sizes:</td>
<td><input type=checkbox id=shapecode onclick="update();"></td>
</tr>
<tr>
<td>Draw obstacles:</td>
<td><input type=checkbox id=obstacles onclick="update();"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Sparser towards edges:</td>
<script>
document.write('<td><input type=text id=fadeout value="'+initialEdgeFadeOut+'" size=4 maxlength=3 onkeyup="update();"></td>');
</script>
<td>(pixels)</td>
</tr>
<tr>
<td>Black border:</td>
<script>
document.write('<td><input type=text id=border value="'+initialBorder+'" size=4 maxlength=3 onkeyup="update();"></td>');
</script>
<td>(pixels)</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Space/cluster seed:</td>
<td><input type=text id=clusterMaskSeed size=4 maxlength=5 onkeyup="update();"></td>
<td><input type=submit value="New seed" onclick="newClusterMaskSeed();">
<input type=submit value="<" id=prevClusterMaskSeed onclick="prevClusterMaskSeed();" disabled><input type=submit value=">" id=nextClusterMaskSeed onclick="nextClusterMaskSeed();" disabled></td>
</tr>
<tr>
<td>Space/cluster scale:</td>
<td><input type=text id=clusterMaskScale value="15" size=4 maxlength=3 onkeyup="update();"></td>
<td>(>= 1)</td>
</tr>
<tr>
<td>Space amount:</td>
<td><input type=text id=spaceAmount value="60" size=4 maxlength=3 onkeyup="update();"></td>
<td>(0 to 100)</td>
</tr>
<tr>
<td>Cluster amount:</td>
<td><input type=text id=clusterAmount value="5" size=4 maxlength=3 onkeyup="update();"></td>
<td>0 to 100)</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
To get a better idea what the space/cluster parameters are doing, set a high number of fibres for a dense starfield. Warning: high values of "Space amount" can be slow with a lot of stars.<br>
<br>
To save as an image: <input type=submit value="Generate PNG" onclick="generatePNG();"><br>
<br>
To copy parameters to clipboard: <input type=submit value="Show parameters as text" onclick="saveParams();"><br>
<br>
<form method=get>
<input type=submit value="Reset parameters to default values">
</form>
</div>
</body>
</html>