forked from LingDong-/shan-shui-inf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
4361 lines (4035 loc) · 124 KB
/
index.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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<script id="PRNG">
var Prng = new function() {
this.s = 1234;
this.p = 999979; //9887//983
this.q = 999983; //9967//991
this.m = this.p * this.q;
this.hash = function(x) {
var y = window.btoa(JSON.stringify(x));
var z = 0;
for (var i = 0; i < y.length; i++) {
z += y.charCodeAt(i) * Math.pow(128, i);
}
return z;
};
this.seed = function(x) {
if (x == undefined) {
x = new Date().getTime();
}
var y = 0;
var z = 0;
function redo() {
y = (Prng.hash(x) + z) % Prng.m;
z += 1;
}
while (y % Prng.p == 0 || y % Prng.q == 0 || y == 0 || y == 1) {
redo();
}
Prng.s = y;
console.log(["int seed", Prng.s]);
for (var i = 0; i < 10; i++) {
Prng.next();
}
};
this.next = function() {
Prng.s = (Prng.s * Prng.s) % Prng.m;
return Prng.s / Prng.m;
};
this.test = function(f) {
var F =
f ||
function() {
return Prng.next();
};
var t0 = new Date().getTime();
var chart = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (var i = 0; i < 10000000; i++) {
chart[Math.floor(F() * 10)] += 1;
}
console.log(chart);
console.log("finished in " + (new Date().getTime() - t0));
return chart;
};
}();
Math.random = function() {
return Prng.next();
};
Math.seed = function(x) {
return Prng.seed(x);
};
</script>
<script>
function parseArgs(key2f) {
var par = window.location.href.split("?")[1];
if (par == undefined) {
return;
}
par = par.split("&");
for (var i = 0; i < par.length; i++) {
var e = par[i].split("=");
try {
key2f[e[0]](e[1]);
} catch (e) {
console.log(e);
}
}
}
SEED = "" + new Date().getTime();
parseArgs({
seed: function(x) {
SEED = x == "" ? SEED : x;
},
});
Math.seed(SEED);
console.log(Prng.seed);
</script>
<script id="PerlinNoise">
//https://raw.githubusercontent.com/processing/p5.js/master/src/math/noise.js
var Noise = new function() {
var PERLIN_YWRAPB = 4;
var PERLIN_YWRAP = 1 << PERLIN_YWRAPB;
var PERLIN_ZWRAPB = 8;
var PERLIN_ZWRAP = 1 << PERLIN_ZWRAPB;
var PERLIN_SIZE = 4095;
var perlin_octaves = 4;
var perlin_amp_falloff = 0.5;
var scaled_cosine = function(i) {
return 0.5 * (1.0 - Math.cos(i * Math.PI));
};
var perlin;
this.noise = function(x, y, z) {
y = y || 0;
z = z || 0;
if (perlin == null) {
perlin = new Array(PERLIN_SIZE + 1);
for (var i = 0; i < PERLIN_SIZE + 1; i++) {
perlin[i] = Math.random();
}
}
if (x < 0) {
x = -x;
}
if (y < 0) {
y = -y;
}
if (z < 0) {
z = -z;
}
var xi = Math.floor(x),
yi = Math.floor(y),
zi = Math.floor(z);
var xf = x - xi;
var yf = y - yi;
var zf = z - zi;
var rxf, ryf;
var r = 0;
var ampl = 0.5;
var n1, n2, n3;
for (var o = 0; o < perlin_octaves; o++) {
var of = xi + (yi << PERLIN_YWRAPB) + (zi << PERLIN_ZWRAPB);
rxf = scaled_cosine(xf);
ryf = scaled_cosine(yf);
n1 = perlin[of & PERLIN_SIZE];
n1 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n1);
n2 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
n2 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n2);
n1 += ryf * (n2 - n1);
of += PERLIN_ZWRAP;
n2 = perlin[of & PERLIN_SIZE];
n2 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n2);
n3 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
n3 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n3);
n2 += ryf * (n3 - n2);
n1 += scaled_cosine(zf) * (n2 - n1);
r += n1 * ampl;
ampl *= perlin_amp_falloff;
xi <<= 1;
xf *= 2;
yi <<= 1;
yf *= 2;
zi <<= 1;
zf *= 2;
if (xf >= 1.0) {
xi++;
xf--;
}
if (yf >= 1.0) {
yi++;
yf--;
}
if (zf >= 1.0) {
zi++;
zf--;
}
}
return r;
};
this.noiseDetail = function(lod, falloff) {
if (lod > 0) {
perlin_octaves = lod;
}
if (falloff > 0) {
perlin_amp_falloff = falloff;
}
};
this.noiseSeed = function(seed) {
var lcg = (function() {
var m = 4294967296,
a = 1664525,
c = 1013904223,
seed,
z;
return {
setSeed: function(val) {
z = seed = (val == null ? Math.random() * m : val) >>> 0;
},
getSeed: function() {
return seed;
},
rand: function() {
z = (a * z + c) % m;
return z / m;
},
};
})();
lcg.setSeed(seed);
perlin = new Array(PERLIN_SIZE + 1);
for (var i = 0; i < PERLIN_SIZE + 1; i++) {
perlin[i] = lcg.rand();
}
};
}();
</script>
<script id="PolyTools">
var PolyTools = new function() {
this.midPt = function() {
var plist =
arguments.length == 1 ? arguments[0] : Array.apply(null, arguments);
return plist.reduce(
function(acc, v) {
/* if (v == undefined || acc == undefined){
console.log("ERRR");
console.log(plist)
return [0,0]
} */
return [v[0] / plist.length + acc[0], v[1] / plist.length + acc[1]];
},
[0, 0],
);
};
this.triangulate = function(plist, args) {
//return []
var args = args != undefined ? args : {};
var area = args.area != undefined ? args.area : 100;
var convex = args.convex != undefined ? args.convex : false;
var optimize = args.optimize != undefined ? args.optimize : true;
function lineExpr(pt0, pt1) {
var den = pt1[0] - pt0[0];
var m = den == 0 ? Infinity : (pt1[1] - pt0[1]) / den;
var k = pt0[1] - m * pt0[0];
return [m, k];
}
function intersect(ln0, ln1) {
var le0 = lineExpr(...ln0);
var le1 = lineExpr(...ln1);
var den = le0[0] - le1[0];
if (den == 0) {
return false;
}
var x = (le1[1] - le0[1]) / den;
var y = le0[0] * x + le0[1];
function onSeg(p, ln) {
//non-inclusive
return (
Math.min(ln[0][0], ln[1][0]) <= p[0] &&
p[0] <= Math.max(ln[0][0], ln[1][0]) &&
Math.min(ln[0][1], ln[1][1]) <= p[1] &&
p[1] <= Math.max(ln[0][1], ln[1][1])
);
}
if (onSeg([x, y], ln0) && onSeg([x, y], ln1)) {
return [x, y];
}
return false;
}
function ptInPoly(pt, plist) {
var scount = 0;
for (var i = 0; i < plist.length; i++) {
var np = plist[i != plist.length - 1 ? i + 1 : 0];
var sect = intersect(
[plist[i], np],
[pt, [pt[0] + 999, pt[1] + 999]],
);
if (sect != false) {
scount++;
}
}
return scount % 2 == 1;
}
function lnInPoly(ln, plist) {
var lnc = [[0, 0], [0, 0]];
var ep = 0.01;
lnc[0][0] = ln[0][0] * (1 - ep) + ln[1][0] * ep;
lnc[0][1] = ln[0][1] * (1 - ep) + ln[1][1] * ep;
lnc[1][0] = ln[0][0] * ep + ln[1][0] * (1 - ep);
lnc[1][1] = ln[0][1] * ep + ln[1][1] * (1 - ep);
for (var i = 0; i < plist.length; i++) {
var pt = plist[i];
var np = plist[i != plist.length - 1 ? i + 1 : 0];
if (intersect(lnc, [pt, np]) != false) {
return false;
}
}
var mid = PolyTools.midPt(ln);
if (ptInPoly(mid, plist) == false) {
return false;
}
return true;
}
function sidesOf(plist) {
var slist = [];
for (var i = 0; i < plist.length; i++) {
var pt = plist[i];
var np = plist[i != plist.length - 1 ? i + 1 : 0];
var s = Math.sqrt(
Math.pow(np[0] - pt[0], 2) + Math.pow(np[1] - pt[1], 2),
);
slist.push(s);
}
return slist;
}
function areaOf(plist) {
var slist = sidesOf(plist);
var a = slist[0],
b = slist[1],
c = slist[2];
var s = (a + b + c) / 2;
return Math.sqrt(s * (s - a) * (s - b) * (s - c));
}
function sliverRatio(plist) {
var A = areaOf(plist);
var P = sidesOf(plist).reduce(function(m, n) {
return m + n;
}, 0);
return A / P;
}
function bestEar(plist) {
var cuts = [];
for (var i = 0; i < plist.length; i++) {
var pt = plist[i];
var lp = plist[i != 0 ? i - 1 : plist.length - 1];
var np = plist[i != plist.length - 1 ? i + 1 : 0];
var qlist = plist.slice();
qlist.splice(i, 1);
if (convex || lnInPoly([lp, np], plist)) {
var c = [[lp, pt, np], qlist];
if (!optimize) return c;
cuts.push(c);
}
}
var best = [plist, []];
var bestRatio = 0;
for (var i = 0; i < cuts.length; i++) {
var r = sliverRatio(cuts[i][0]);
if (r >= bestRatio) {
best = cuts[i];
bestRatio = r;
}
}
return best;
}
function shatter(plist, a) {
if (plist.length == 0) {
return [];
}
if (areaOf(plist) < a) {
return [plist];
} else {
var slist = sidesOf(plist);
var ind = slist.reduce(
(iMax, x, i, arr) => (x > arr[iMax] ? i : iMax),
0,
);
var nind = (ind + 1) % plist.length;
var lind = (ind + 2) % plist.length;
try {
var mid = PolyTools.midPt([plist[ind], plist[nind]]);
} catch (err) {
console.log(plist);
console.log(err);
return [];
}
return shatter([plist[ind], mid, plist[lind]], a).concat(
shatter([plist[lind], plist[nind], mid], a),
);
}
}
if (plist.length <= 3) {
return shatter(plist, area);
} else {
var cut = bestEar(plist);
return shatter(cut[0], area).concat(
PolyTools.triangulate(cut[1], args),
);
}
};
}();
</script>
<script id="Util">
function unNan(plist) {
if (typeof plist != "object" || plist == null) {
return plist || 0;
} else {
return plist.map(unNan);
}
}
//console.log(unNan([[undefined,[NaN,NaN],null],false,1]))
function distance(p0, p1) {
return Math.sqrt(Math.pow(p0[0] - p1[0], 2) + Math.pow(p0[1] - p1[1], 2));
}
function mapval(value, istart, istop, ostart, ostop) {
return (
ostart + (ostop - ostart) * (((value - istart) * 1.0) / (istop - istart))
);
}
function loopNoise(nslist) {
var dif = nslist[nslist.length - 1] - nslist[0];
var bds = [100, -100];
for (var i = 0; i < nslist.length; i++) {
nslist[i] += (dif * (nslist.length - 1 - i)) / (nslist.length - 1);
if (nslist[i] < bds[0]) bds[0] = nslist[i];
if (nslist[i] > bds[1]) bds[1] = nslist[i];
}
for (var i = 0; i < nslist.length; i++) {
nslist[i] = mapval(nslist[i], bds[0], bds[1], 0, 1);
}
}
function randChoice(arr) {
return arr[Math.floor(arr.length * Math.random())];
}
function normRand(m, M) {
return mapval(Math.random(), 0, 1, m, M);
}
function wtrand(func) {
var x = Math.random();
var y = Math.random();
if (y < func(x)) {
return x;
} else {
return wtrand(func);
}
}
function randGaussian() {
return (
wtrand(function(x) {
return Math.pow(Math.E, -24 * Math.pow(x - 0.5, 2));
}) *
2 -
1
);
}
function bezmh(P, w) {
w = w == undefined ? 1 : w;
if (P.length == 2) {
P = [P[0], PolyTools.midPt(P[0], P[1]), P[1]];
}
var plist = [];
for (var j = 0; j < P.length - 2; j++) {
var p0;
var p1;
var p2;
if (j == 0) {
p0 = P[j];
} else {
p0 = PolyTools.midPt(P[j], P[j + 1]);
}
p1 = P[j + 1];
if (j == P.length - 3) {
p2 = P[j + 2];
} else {
p2 = PolyTools.midPt(P[j + 1], P[j + 2]);
}
var pl = 20;
for (var i = 0; i < pl + (j == P.length - 3); i += 1) {
var t = i / pl;
var u = Math.pow(1 - t, 2) + 2 * t * (1 - t) * w + t * t;
plist.push([
(Math.pow(1 - t, 2) * p0[0] +
2 * t * (1 - t) * p1[0] * w +
t * t * p2[0]) /
u,
(Math.pow(1 - t, 2) * p0[1] +
2 * t * (1 - t) * p1[1] * w +
t * t * p2[1]) /
u,
]);
}
}
return plist;
}
function poly(plist, args) {
var args = args != undefined ? args : {};
var xof = args.xof != undefined ? args.xof : 0;
var yof = args.yof != undefined ? args.yof : 0;
var fil = args.fil != undefined ? args.fil : "rgba(0,0,0,0)";
var str = args.str != undefined ? args.str : fil;
var wid = args.wid != undefined ? args.wid : 0;
var canv = "<polyline points='";
for (var i = 0; i < plist.length; i++) {
canv +=
" " +
(plist[i][0] + xof).toFixed(1) +
"," +
(plist[i][1] + yof).toFixed(1);
}
canv +=
"' style='fill:" +
fil +
";stroke:" +
str +
";stroke-width:" +
wid +
"'/>";
return canv;
}
</script>
<script>
console.log("************************************************");
function stroke(ptlist, args) {
var args = args != undefined ? args : {};
var xof = args.xof != undefined ? args.xof : 0;
var yof = args.yof != undefined ? args.yof : 0;
var wid = args.wid != undefined ? args.wid : 2;
var col = args.col != undefined ? args.col : "rgba(200,200,200,0.9)";
var noi = args.noi != undefined ? args.noi : 0.5;
var out = args.out != undefined ? args.out : 1;
var fun =
args.fun != undefined
? args.fun
: function(x) {
return Math.sin(x * Math.PI);
};
if (ptlist.length == 0) {
return "";
}
vtxlist0 = [];
vtxlist1 = [];
vtxlist = [];
var n0 = Math.random() * 10;
for (var i = 1; i < ptlist.length - 1; i++) {
var w = wid * fun(i / ptlist.length);
w = w * (1 - noi) + w * noi * Noise.noise(i * 0.5, n0);
var a1 = Math.atan2(
ptlist[i][1] - ptlist[i - 1][1],
ptlist[i][0] - ptlist[i - 1][0],
);
var a2 = Math.atan2(
ptlist[i][1] - ptlist[i + 1][1],
ptlist[i][0] - ptlist[i + 1][0],
);
var a = (a1 + a2) / 2;
if (a < a2) {
a += Math.PI;
}
vtxlist0.push([
ptlist[i][0] + w * Math.cos(a),
ptlist[i][1] + w * Math.sin(a),
]);
vtxlist1.push([
ptlist[i][0] - w * Math.cos(a),
ptlist[i][1] - w * Math.sin(a),
]);
}
vtxlist = [ptlist[0]]
.concat(
vtxlist0.concat(vtxlist1.concat([ptlist[ptlist.length - 1]]).reverse()),
)
.concat([ptlist[0]]);
var canv = poly(
vtxlist.map(function(x) {
return [x[0] + xof, x[1] + yof];
}),
{ fil: col, str: col, wid: out },
);
return canv;
}
function blob(x, y, args) {
var args = args != undefined ? args : {};
var len = args.len != undefined ? args.len : 20;
var wid = args.wid != undefined ? args.wid : 5;
var ang = args.ang != undefined ? args.ang : 0;
var col = args.col != undefined ? args.col : "rgba(200,200,200,0.9)";
var noi = args.noi != undefined ? args.noi : 0.5;
var ret = args.ret != undefined ? args.ret : 0;
var fun =
args.fun != undefined
? args.fun
: function(x) {
return x <= 1
? Math.pow(Math.sin(x * Math.PI), 0.5)
: -Math.pow(Math.sin((x + 1) * Math.PI), 0.5);
};
var reso = 20.0;
var lalist = [];
for (var i = 0; i < reso + 1; i++) {
var p = (i / reso) * 2;
var xo = len / 2 - Math.abs(p - 1) * len;
var yo = (fun(p) * wid) / 2;
var a = Math.atan2(yo, xo);
var l = Math.sqrt(xo * xo + yo * yo);
lalist.push([l, a]);
}
var nslist = [];
var n0 = Math.random() * 10;
for (var i = 0; i < reso + 1; i++) {
nslist.push(Noise.noise(i * 0.05, n0));
}
loopNoise(nslist);
var plist = [];
for (var i = 0; i < lalist.length; i++) {
var ns = nslist[i] * noi + (1 - noi);
var nx = x + Math.cos(lalist[i][1] + ang) * lalist[i][0] * ns;
var ny = y + Math.sin(lalist[i][1] + ang) * lalist[i][0] * ns;
plist.push([nx, ny]);
}
if (ret == 0) {
return poly(plist, { fil: col, str: col, wid: 0 });
} else {
return plist;
}
}
function div(plist, reso) {
var tl = (plist.length - 1) * reso;
var lx = 0;
var ly = 0;
var rlist = [];
for (var i = 0; i < tl; i += 1) {
var lastp = plist[Math.floor(i / reso)];
var nextp = plist[Math.ceil(i / reso)];
var p = (i % reso) / reso;
var nx = lastp[0] * (1 - p) + nextp[0] * p;
var ny = lastp[1] * (1 - p) + nextp[1] * p;
var ang = Math.atan2(ny - ly, nx - lx);
rlist.push([nx, ny]);
lx = nx;
ly = ny;
}
if (plist.length > 0) {
rlist.push(plist[plist.length - 1]);
}
return rlist;
}
var texture = function(ptlist, args) {
var args = args != undefined ? args : {};
var xof = args.xof != undefined ? args.xof : 0;
var yof = args.yof != undefined ? args.yof : 0;
var tex = args.tex != undefined ? args.tex : 400;
var wid = args.wid != undefined ? args.wid : 1.5;
var len = args.len != undefined ? args.len : 0.2;
var sha = args.sha != undefined ? args.sha : 0;
var ret = args.ret != undefined ? args.ret : 0;
var noi =
args.noi != undefined
? args.noi
: function(x) {
return 30 / x;
};
var col =
args.col != undefined
? args.col
: function(x) {
return "rgba(100,100,100," + (Math.random() * 0.3).toFixed(3) + ")";
};
var dis =
args.dis != undefined
? args.dis
: function() {
if (Math.random() > 0.5) {
return (1 / 3) * Math.random();
} else {
return (1 * 2) / 3 + (1 / 3) * Math.random();
}
};
var reso = [ptlist.length, ptlist[0].length];
var texlist = [];
for (var i = 0; i < tex; i++) {
var mid = (dis() * reso[1]) | 0;
//mid = (reso[1]/3+reso[1]/3*Math.random())|0
var hlen = Math.floor(Math.random() * (reso[1] * len));
var start = mid - hlen;
var end = mid + hlen;
start = Math.min(Math.max(start, 0), reso[1]);
end = Math.min(Math.max(end, 0), reso[1]);
var layer = (i / tex) * (reso[0] - 1);
texlist.push([]);
for (var j = start; j < end; j++) {
var p = layer - Math.floor(layer);
var x =
ptlist[Math.floor(layer)][j][0] * p +
ptlist[Math.ceil(layer)][j][0] * (1 - p);
var y =
ptlist[Math.floor(layer)][j][1] * p +
ptlist[Math.ceil(layer)][j][1] * (1 - p);
var ns = [
noi(layer + 1) * (Noise.noise(x, j * 0.5) - 0.5),
noi(layer + 1) * (Noise.noise(y, j * 0.5) - 0.5),
];
texlist[texlist.length - 1].push([x + ns[0], y + ns[1]]);
}
}
var canv = "";
//SHADE
if (sha) {
for (var j = 0; j < texlist.length; j += 1 + (sha != 0)) {
canv += stroke(
texlist[j].map(function(x) {
return [x[0] + xof, x[1] + yof];
}),
{ col: "rgba(100,100,100,0.1)", wid: sha },
);
}
}
//TEXTURE
for (var j = 0 + sha; j < texlist.length; j += 1 + sha) {
canv += stroke(
texlist[j].map(function(x) {
return [x[0] + xof, x[1] + yof];
}),
{ col: col(j / texlist.length), wid: wid },
);
}
return ret ? texlist : canv;
};
var Tree = new function() {
this.tree01 = function(x, y, args) {
var args = args != undefined ? args : {};
var hei = args.hei != undefined ? args.hei : 50;
var wid = args.wid != undefined ? args.wid : 3;
var col = args.col != undefined ? args.col : "rgba(100,100,100,0.5)";
var noi = args.noi != undefined ? args.noi : 0.5;
reso = 10;
var nslist = [];
for (var i = 0; i < reso; i++) {
nslist.push([Noise.noise(i * 0.5), Noise.noise(i * 0.5, 0.5)]);
}
var leafcol;
if (col.includes("rgba(")) {
leafcol = col
.replace("rgba(", "")
.replace(")", "")
.split(",");
} else {
leafcol = ["100", "100", "100", "0.5"];
}
var canv = "";
var line1 = [];
var line2 = [];
for (var i = 0; i < reso; i++) {
var nx = x;
var ny = y - (i * hei) / reso;
if (i >= reso / 4) {
for (var j = 0; j < (reso - i) / 5; j++) {
canv += blob(
nx + (Math.random() - 0.5) * wid * 1.2 * (reso - i),
ny + (Math.random() - 0.5) * wid,
{
len: Math.random() * 20 * (reso - i) * 0.2 + 10,
wid: Math.random() * 6 + 3,
ang: ((Math.random() - 0.5) * Math.PI) / 6,
col:
"rgba(" +
leafcol[0] +
"," +
leafcol[1] +
"," +
leafcol[2] +
"," +
(Math.random() * 0.2 + parseFloat(leafcol[3])).toFixed(1) +
")",
},
);
}
}
line1.push([nx + (nslist[i][0] - 0.5) * wid - wid / 2, ny]);
line2.push([nx + (nslist[i][1] - 0.5) * wid + wid / 2, ny]);
}
canv +=
poly(line1, { fil: "none", str: col, wid: 1.5 }) +
poly(line2, { fil: "none", str: col, wid: 1.5 });
return canv;
};
this.tree02 = function(x, y, args) {
var args = args != undefined ? args : {};
var hei = args.hei != undefined ? args.hei : 16;
var wid = args.wid != undefined ? args.wid : 8;
var clu = args.clu != undefined ? args.clu : 5;
var col = args.col != undefined ? args.col : "rgba(100,100,100,0.5)";
var noi = args.noi != undefined ? args.noi : 0.5;
var leafcol;
if (col.includes("rgba(")) {
leafcol = col
.replace("rgba(", "")
.replace(")", "")
.split(",");
} else {
leafcol = ["100", "100", "100", "0.5"];
}
var canv = "";
for (var i = 0; i < clu; i++) {
canv += blob(
x + randGaussian() * clu * 4,
y + randGaussian() * clu * 4,
{
ang: Math.PI / 2,
col: "rgba(100,100,100,0.8)",
fun: function(x) {
return x <= 1
? Math.pow(Math.sin(x * Math.PI) * x, 0.5)
: -Math.pow(Math.sin((x - 2) * Math.PI * (x - 2)), 0.5);
},
wid: Math.random() * wid * 0.75 + wid * 0.5,
len: Math.random() * hei * 0.75 + hei * 0.5,
col: col,
},
);
}
return canv;
};
this.tree03 = function(x, y, args) {
var args = args != undefined ? args : {};
var hei = args.hei != undefined ? args.hei : 50;
var wid = args.wid != undefined ? args.wid : 5;
var ben =
args.ben != undefined
? args.ben
: function(x) {
return 0;
};
var col = args.col != undefined ? args.col : "rgba(100,100,100,0.5)";
var noi = args.noi != undefined ? args.noi : 0.5;
reso = 10;
var nslist = [];
for (var i = 0; i < reso; i++) {
nslist.push([Noise.noise(i * 0.5), Noise.noise(i * 0.5, 0.5)]);
}
var leafcol;
if (col.includes("rgba(")) {
leafcol = col
.replace("rgba(", "")
.replace(")", "")
.split(",");
} else {
leafcol = ["100", "100", "100", "0.5"];
}
var canv = "";
var blobs = "";
var line1 = [];
var line2 = [];
for (var i = 0; i < reso; i++) {
var nx = x + ben(i / reso) * 100;
var ny = y - (i * hei) / reso;
if (i >= reso / 5) {
for (var j = 0; j < (reso - i) * 2; j++) {
var shape = function(x) {
return Math.log(50 * x + 1) / 3.95;
};
var ox = Math.random() * wid * 2 * shape((reso - i) / reso);
blobs += blob(
nx + ox * randChoice([-1, 1]),
ny + (Math.random() - 0.5) * wid * 2,
{
len: ox * 2,
wid: Math.random() * 6 + 3,
ang: ((Math.random() - 0.5) * Math.PI) / 6,
col:
"rgba(" +
leafcol[0] +
"," +
leafcol[1] +
"," +
leafcol[2] +
"," +
(Math.random() * 0.2 + parseFloat(leafcol[3])).toFixed(3) +
")",
},
);
}
}
line1.push([
nx + (((nslist[i][0] - 0.5) * wid - wid / 2) * (reso - i)) / reso,
ny,
]);
line2.push([
nx + (((nslist[i][1] - 0.5) * wid + wid / 2) * (reso - i)) / reso,
ny,
]);
}
var lc = line1.concat(line2.reverse());
canv += poly(lc, { fil: "white", str: col, wid: 1.5 });
canv += blobs;
return canv;
};
var branch = function(args) {
var args = args != undefined ? args : {};
var hei = args.hei != undefined ? args.hei : 300;
var wid = args.wid != undefined ? args.wid : 6;
var ang = args.ang != undefined ? args.ang : 0;
var det = args.det != undefined ? args.det : 10;
var ben = args.ben != undefined ? args.ben : Math.PI * 0.2;
var tlist;
var nx = 0;
var ny = 0;
tlist = [[nx, ny]];
var a0 = 0;
var g = 3;
for (var i = 0; i < g; i++) {
a0 += (ben / 2 + (Math.random() * ben) / 2) * randChoice([-1, 1]);
nx += (Math.cos(a0) * hei) / g;
ny -= (Math.sin(a0) * hei) / g;
tlist.push([nx, ny]);
}
var ta = Math.atan2(
tlist[tlist.length - 1][1],
tlist[tlist.length - 1][0],
);
for (var i = 0; i < tlist.length; i++) {
var a = Math.atan2(tlist[i][1], tlist[i][0]);
var d = Math.sqrt(
tlist[i][0] * tlist[i][0] + tlist[i][1] * tlist[i][1],
);
tlist[i][0] = d * Math.cos(a - ta + ang);
tlist[i][1] = d * Math.sin(a - ta + ang);
}
var trlist1 = [];
var trlist2 = [];
var span = det;
var tl = (tlist.length - 1) * span;
var lx = 0;
var ly = 0;
for (var i = 0; i < tl; i += 1) {
var lastp = tlist[Math.floor(i / span)];
var nextp = tlist[Math.ceil(i / span)];
var p = (i % span) / span;
var nx = lastp[0] * (1 - p) + nextp[0] * p;
var ny = lastp[1] * (1 - p) + nextp[1] * p;
var ang = Math.atan2(ny - ly, nx - lx);
var woff = ((Noise.noise(i * 0.3) - 0.5) * wid * hei) / 80;
var b = 0;
if (p == 0) {
b = Math.random() * wid;
}
var nw = wid * (((tl - i) / tl) * 0.5 + 0.5);
trlist1.push([
nx + Math.cos(ang + Math.PI / 2) * (nw + woff + b),
ny + Math.sin(ang + Math.PI / 2) * (nw + woff + b),
]);
trlist2.push([
nx + Math.cos(ang - Math.PI / 2) * (nw - woff + b),
ny + Math.sin(ang - Math.PI / 2) * (nw - woff + b),
]);
lx = nx;
ly = ny;
}
return [trlist1, trlist2];
};
var twig = function(tx, ty, dep, args) {
var args = args != undefined ? args : {};
var dir = args.dir != undefined ? args.dir : 1;
var sca = args.sca != undefined ? args.sca : 1;
var wid = args.wid != undefined ? args.wid : 1;
var ang = args.ang != undefined ? args.ang : 0;
var lea = args.lea != undefined ? args.lea : [true, 12];
var canv = "";
var twlist = [];