-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvg_app.bundle.js
More file actions
2846 lines (2344 loc) · 94.1 KB
/
Copy pathsvg_app.bundle.js
File metadata and controls
2846 lines (2344 loc) · 94.1 KB
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
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 53);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.randItem = randItem;
exports.randomInRange = randomInRange;
exports.randomInt = randomInt;
exports.shuffle = shuffle;
exports.setAttrs = setAttrs;
exports.resetTransform = resetTransform;
exports.rotateCanvas = rotateCanvas;
exports.getGradientFunction = getGradientFunction;
exports.getLocalGradientFunction = getLocalGradientFunction;
exports.getSolidColorFunction = getSolidColorFunction;
exports.hexToRgb = hexToRgb;
exports.colorDistanceArray = colorDistanceArray;
exports.closestColor = closestColor;
exports.scalarVec = scalarVec;
exports.getAngle = getAngle;
exports.getVector = getVector;
exports.averagePoints = averagePoints;
exports.pointsToPath = pointsToPath;
exports.mapKeywordToVal = mapKeywordToVal;
exports.friendlyBoolean = friendlyBoolean;
exports.Note = Note;
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
// random Array member
function randItem(arr) {
return arr[Math.floor(arr.length * Math.random())];
}
function randomInRange(min, max) {
if (max === undefined) {
max = min;
min = 0;
}
return min + (max - min) * Math.random();
}
function randomInt(min, max) {
return Math.round(randomInRange(min, max));
}
// fisher-yates, from https://bost.ocks.org/mike/shuffle/
function shuffle(array) {
var m = array.length,
t,
i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
function setAttrs(el, attrs) {
var a;
if (el && el.setAttribute) {
for (a in attrs) {
if (attrs.hasOwnProperty(a)) {
el.setAttribute(a, attrs[a]);
}
}
}
}
// reset canvas transformations
function resetTransform(ctx) {
ctx.setTransform(1, 0, 0, 1, 0, 0);
}
// rotate canvas around center point
function rotateCanvas(ctx, w, h, angle) {
ctx.translate(w / 2, h / 2);
ctx.rotate(angle);
ctx.translate(-w / 2, -h / 2);
}
function getGradientFunction(palette) {
var p = [].concat(palette);
return function (ctx, w, h) {
var bias = Math.random() - 0.5;
var coords = [];
if (bias) {
coords = [randomInRange(0, w), 0, randomInRange(0, w), h];
} else {
coords = [0, randomInRange(0, h), w, randomInRange(0, h)];
}
var grad = ctx.createLinearGradient.apply(ctx, _toConsumableArray(coords));
grad.addColorStop(0, randItem(p));
grad.addColorStop(1, randItem(p));
return grad;
};
}
function getLocalGradientFunction(palette) {
var p = [].concat(palette);
return function (ctx, x, y, size) {
var bias = Math.random() - 0.5;
var coords = [];
if (bias) {
coords = [randomInRange(x - size, x + size), y - size, randomInRange(x - size, x + size), y + size];
} else {
coords = [x - size, randomInRange(y - size, y + size), x + size, randomInRange(y - size, y + size)];
}
var grad = ctx.createLinearGradient.apply(ctx, _toConsumableArray(coords));
grad.addColorStop(0, randItem(p));
grad.addColorStop(1, randItem(p));
return grad;
};
}
// Creates a function that returns a different random entry
// from @palette each time it is called.
function getSolidColorFunction(palette) {
var refresh = function refresh() {
// clone palette before providing func to avoid
// operating on the input array.
return [].concat(palette).sort(function (a, b) {
return Math.random() - 0.5;
});
};
var p = refresh();
return function () {
// if we run out of colors, start with a new shuffled palette
if (!p.length) p = refresh();
// otherwise pop a color
return p.pop();
};
}
// converts @hex to 8-bit array [r, g, b]
function hexToRgb(hex) {
if (hex[0] === '#') {
hex = hex.slice(1);
}
if (hex.length === 3) {
hex = '' + hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
function toN(hexFrag) {
return parseInt(hexFrag, 16);
}
return [toN(hex.slice(0, 2)), toN(hex.slice(2, 4)), toN(hex.slice(4, 6))];
}
// Supply @c1, @c2 as [r,g,b] colors.
// Return r,g,b distance components, and a scalar distance as [r,b,g,distance]
// Scalar diff is 0-765
function colorDistanceArray(c1, c2) {
var dr = void 0,
dg = void 0,
db = void 0;
var _r = (c1[0] + c2[0]) / 2;
dr = c2[0] - c1[0];
dg = c2[1] - c1[1];
db = c2[2] - c1[2];
// dc = scalar diff
var dc = Math.sqrt(dr * dr * (2 + _r / 256) + dg * dg * 4 + db * db * (2 + (255 - _r) / 256));
return [dr, dg, db, dc];
}
// args are rgb in 8 bit array form
// returns {diff, color}
function closestColor(sample, palette) {
var diffs = palette.map(function (p) {
return {
diff: colorDistanceArray(p, sample),
color: p
};
});
diffs = diffs.sort(function (a, b) {
return a.diff[3] - b.diff[3];
});
return diffs[0];
}
// util for scaling color errors in dithering, but could be useful
function scalarVec(vec, scalar) {
return vec.map(function (x) {
return x * scalar;
});
}
// util
// get angle between @a and @b of form [x, y]
// returns in radians
function getAngle(a, b) {
var dx = b[0] - a[0];
var dy = b[1] - a[1];
return Math.atan2(dy, dx);
}
// util
// get vector between @a and @b of form [x, y]
// return object with x, y = @a, angle, length
function getVector(a, b) {
var dx = b[0] - a[0];
var dy = b[1] - a[1];
var theta = Math.atan2(dy, dx);
var length = Math.sqrt(dx * dx + dy * dy);
return {
x: a[0],
y: a[1],
angle: theta,
length: length
};
}
// get the average coordinates from an array of
// @points in [x,y] form
function averagePoints(points) {
var avg = [0, 0];
for (var i = 0; i < points.length; i++) {
avg[0] += points[i][0];
avg[1] += points[i][1];
}
avg[0] /= points.length;
avg[1] /= points.length;
return avg;
}
// Create a path in @ctx by stepping through the points
// in @points, which are in [x,y] array form
function pointsToPath(ctx, points) {
// copy the points list, so we don't mutate
var pts = points.concat([]);
ctx.beginPath();
ctx.moveTo.apply(ctx, _toConsumableArray(pts.shift()));
while (pts.length) {
ctx.lineTo.apply(ctx, _toConsumableArray(pts.shift()));
}
ctx.closePath();
return ctx;
}
// map named values of props, e.g. low, med, high…
// to values, as defined in the obj @props
// If values are arrays, use @accessor function to pick.
// Respect 'auto' as special case for @name
function mapKeywordToVal(props) {
var accessor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : randomInRange;
var names = Object.keys(props);
return function (name) {
var label = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'param';
if (name === 'auto' || name === 'AUTO') {
name = randItem(names);
console.log(label + ': auto picked ' + name);
}
if (props[name] === undefined) {
name = names[0];
console.log(label + ': fell back to ' + name);
}
var val = props[name];
if (Array.isArray(val)) {
return accessor.apply(undefined, _toConsumableArray(val));
} else {
return val;
}
};
}
// Get boolean value, but be friendly to "false" passed as string
function friendlyBoolean(prop) {
if (prop === 'false') return false;
return !!prop;
}
function Note() {
var divider = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
var time = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var msgs = [];
var start_ts = new Date().getTime();
var end_ts = start_ts;
this.add = function (t) {
msgs.push(t);
};
this.first = function (t) {
msgs.unshift(t);
};
this.print = function () {
return msgs.join('\n');
};
this.log = function () {
if (time) {
end_ts = new Date().getTime();
this.add('> Ran in ' + (end_ts - start_ts) + 'ms');
}
if (divider) {
this.first('------------------------------');
}
console.log(this.print());
};
return this;
}
/***/ }),
/***/ 1:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
// in use
var palettes = {
ultra: ['#15d6d0', '#4481fc', '#bb19d8', '#f22f1c', '#ffa300', '#fff200'],
high_contrast: ['#111111', '#444444', '#dddddd', '#f9f9f9'],
low_contrast: ['#555555', '#777777', '#999999', '#cccccc', '#dddddd'],
black_white_red: ['#111111', '#444444', '#dddddd', '#ffffff', '#880000', '#dd0000'],
south_beach: ['#0c3646', '#11758e', '#89bed3', '#e4ca49', '#cabd9d', '#f2f0ea'],
north_beach: ['#1d282e', '#4b4f52', '#0089ad', '#6e92b4', '#b9a583', '#f1e1d1'],
twilight_beach: ['#030408', '#0c3646', '#4a828f', '#af8c70', '#aaadac', '#ffffff'],
admiral: ['#0a131c', '#072444', '#3b6185', '#361313', '#c47423', '#b88d40', '#f3efec'],
plum_sauce: ['#3C2E42', '#B4254B', '#FF804A', '#E8D1A1', '#A5C9C4'],
fingerspitzen: ['#f4dda8', '#eda87c', '#c8907e', '#9cacc3', '#485e80', '#3b465b'],
de_stijl: ['#f9f9f9', '#D9AC32', '#ED5045', '#1F3E9C', '#000142'],
terra_cotta_cactus: ['#5d576b', '#9bc1b8', '#f4f1bb', '#dcc48e', '#ed6a5a'],
metroid_fusion: ['#DBEED6', '#47BDC2', '#0A7DB8', '#1A3649', '#B24432'],
candywafer: ['#222222', '#fae1f6', '#b966d3', '#8ED2EE', '#362599', '#fff9de', '#FFC874'],
blush: ['#111111', '#94552C', '#F8ADAA', '#F8E3AC', '#ffffff'],
ikb: ['#070033', '#00006b', '#00187c', '#002ea7', '#0b6fff', '#5c9eff', '#e9f4ff'],
torch: ['#230000', '#770022', '#bf0000', '#dd3400', '#ff7415', '#ff9d27', '#fffa50'],
magma: ['#000004', '#3b0f70', '#8c2981', '#de4968', '#fe9f6d', '#fcfdbf'],
inferno: ['#000004', '#420a68', '#932667', '#dd513a', '#fca50a', '#fcffa4'],
plasma: ['#0d0887', '#6a00a8', '#b12a90', '#e16462', '#fca636', '#f0f921'],
viridis: ['#440154', '#414487', '#2a788e', '#22a884', '#7ad151', '#fde725'],
morley_rainbow: ['#817', '#a35', '#c66', '#e94', '#ed0', '#9d5', '#4d8', '#2cb', '#0bc', '#09c', '#36b', '#639']
};
exports.default = palettes;
// older palettes:
var lemon_beach = exports.lemon_beach = ['#d7d7d7', '#979797', '#cabd9d', '#e4ca49', '#89bed3', '#11758e'];
/***/ }),
/***/ 10:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.field = field;
var _noiseutils = __webpack_require__(2);
var _noiseutils2 = _interopRequireDefault(_noiseutils);
var _palettes = __webpack_require__(1);
var _palettes2 = _interopRequireDefault(_palettes);
var _hexScatter = __webpack_require__(4);
var _hexScatter2 = _interopRequireDefault(_hexScatter);
var _utils = __webpack_require__(0);
var _shapes = __webpack_require__(3);
var _fieldUtils = __webpack_require__(5);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var DEFAULTS = {
container: 'body',
palette: _palettes2.default.de_stijl,
addNoise: 0.04,
noiseInput: null,
dust: false,
skew: 1, // normalized skew
clear: true,
colorMode: 'auto', // from COLORMODES or 'auto'
fieldMode: 'auto', // [auto, harmonic, flow]
lightMode: 'normal', // [auto, bloom, normal]
gridMode: 'auto', // [auto, normal, scatter, random]
density: 'auto', // [auto, coarse, fine]
fieldNoise: 'auto' // mapped to values below
};
var PI = Math.PI;
var FIELDMODES = ['harmonic', 'flow'];
var LIGHTMODES = ['bloom', 'normal'];
var GRIDMODES = ['normal', 'scatter', 'random'];
var DENSITIES = ['coarse', 'fine'];
var COLORMODES = ['single', 'angle', 'random'];
// Main function
function field(options) {
var opts = Object.assign({}, DEFAULTS, options);
var container = opts.container;
var cw = container.offsetWidth;
var ch = container.offsetHeight;
var SCALE = Math.min(cw, ch);
var LONG = Math.max(cw, ch);
var SHORT = Math.min(cw, ch);
var AREA = cw * ch;
// Find or create canvas child
var el = container.querySelector('canvas');
var newEl = false;
if (!el) {
container.innerHTML = '';
el = document.createElement('canvas');
newEl = true;
}
if (newEl || opts.clear) {
el.width = cw;
el.height = ch;
}
var ctx = el.getContext('2d');
// modes and styles
var LIGHTMODE = opts.lightMode === 'auto' ? (0, _utils.randItem)(LIGHTMODES) : opts.lightMode;
var GRIDMODE = opts.gridMode === 'auto' ? (0, _utils.randItem)(GRIDMODES) : opts.gridMode;
var DENSITY = opts.density === 'auto' ? (0, _utils.randItem)(DENSITIES) : opts.density;
var FIELDMODE = opts.fieldMode === 'auto' ? (0, _utils.randItem)(FIELDMODES) : opts.fieldMode;
var COLORMODE = opts.colorMode === 'auto' ? (0, _utils.randItem)(COLORMODES) : opts.colorMode;
var FIELDNOISE = (0, _utils.mapKeywordToVal)({
// hacky way to weight options by redundantly specifying
'none': 0,
'none2': 0,
'low': 0.125,
'low2': 0.125,
'med': 0.25,
'high': 0.5
})(opts.fieldNoise, 'fieldNoise');
// color funcs
var getSolidFill = (0, _utils.getSolidColorFunction)(opts.palette);
// how many cells are in the grid?
var countMin = void 0,
countMax = void 0;
if (DENSITY === 'coarse') {
countMin = 10;
countMax = 30;
} else {
countMin = 60;
countMax = 100;
}
var cellSize = Math.round(SHORT / (0, _utils.randomInRange)(countMin, countMax));
console.log('Field: ' + DENSITY + '(' + cellSize + 'px) ' + GRIDMODE + ' ' + FIELDMODE + ' ' + COLORMODE);
// setup vars for each cell
var x = 0;
var y = 0;
var xnorm = 0;
var ynorm = 0;
var renderer = void 0;
// shared colors
var bg = getSolidFill();
// get palette of non-bg colors
var contrastPalette = [].concat(opts.palette);
contrastPalette.splice(opts.palette.indexOf(bg), 1);
var getContrastColor = (0, _utils.getSolidColorFunction)(contrastPalette);
// shared foregrounds
var fg = getContrastColor();
var fg2 = getContrastColor();
// in bloom mode, we draw high-contrast grayscale, and layer
// palette colors on top
if (LIGHTMODE === 'bloom') {
bg = '#222222';
fg = fg2 = '#cccccc';
}
// draw background
ctx.fillStyle = bg;
ctx.fillRect(0, 0, cw, ch);
// set default tail color
ctx.strokeStyle = fg;
// set default dot color
var dotFill = fg2;
var rateMax = 3;
if (DENSITY === 'fine' && Math.random() < 0.5) {
rateMax = 6;
}
// tail vars
var _x = void 0,
_y = void 0,
len = void 0;
// dotScale will be multiplied by 2. Keep below .25 to avoid bleed.
// Up to 0.5 will lead to full coverage.
var dotScale = cellSize * (0, _utils.randomInRange)(0.1, 0.25);
// line width
var weight = (0, _utils.randomInRange)(0.5, 3) * SCALE / 800;
ctx.lineWidth = weight;
ctx.lineCap = 'round';
// const used in normalizing transforms
var maxLen = 2 * Math.sqrt(2);
// It looks nice to extend lines beyond their cells. how much?
// Scaled against cellSize
var lineScale = (0, _utils.randomInRange)(0.7, 2);
// Displace the center point of each cell by this factor
// Only do this sometimes, and not when scattering
var warp = 0;
if (GRIDMODE !== 'scatter' && Math.random() < 0.5) {
warp = (0, _utils.randomInRange)(0.75, Math.sqrt(2));
}
// Pick an opacity transform to use
var opacityFunc = (0, _utils.randItem)((0, _fieldUtils.opacityTransforms)(maxLen));
// a set of independent transforms to use while rendering
var trans = {
xbase: (0, _fieldUtils.createTransform)(rateMax), // (x,y)=>0,//
ybase: (0, _fieldUtils.createTransform)(rateMax), // (x,y)=>0,//
xtail: (0, _fieldUtils.createTransform)(rateMax), // (x,y)=>0,//
ytail: (0, _fieldUtils.createTransform)(rateMax), // (x,y)=>0,//
radius: (0, _fieldUtils.createTransform)(rateMax)
};
function randomScatter(size, w, h) {
var pts = [];
var xcount = Math.ceil(w / size);
var ycount = Math.ceil(h / size);
var count = xcount * ycount;
while (count--) {
pts.push([(0, _utils.randomInRange)(0, w), (0, _utils.randomInRange)(0, h)]);
}
return pts;
}
function placeNormal(size, w, h) {
var pts = [];
var xcount = Math.ceil(w / size) + 2;
var ycount = Math.ceil(h / size) + 2;
var count = xcount * ycount;
var x = void 0,
y = void 0;
for (var i = 0; i < count; i++) {
x = size * (i % xcount - 1) + size / 2;
y = size * (Math.floor(i / xcount) - 1) + size / 2;
pts.push([x, y]);
}
return pts;
}
var pts = [];
// If we are warping the grid, we should plot points outside of the canvas
// bounds to avoid gaps at the edges. Shift them over below.
var overscan = 1;
if (warp) {
overscan = 1.2;
}
switch (GRIDMODE) {
case 'scatter':
pts = (0, _hexScatter2.default)(cellSize, cw * overscan, ch * overscan);
break;
case 'random':
pts = randomScatter(cellSize, cw * overscan, ch * overscan);
break;
default:
pts = placeNormal(cellSize, cw * overscan, ch * overscan);
}
// compensate for overscan by shifting pts back
if (warp) {
pts.map(function (p, i) {
return [p[0] - cw * .1, p[1] - ch * .1];
});
}
var sourceTransform = (0, _fieldUtils.createSourceSinkTransform)(Math.round((0, _utils.randomInRange)(5, 15)));
// Flags for coloring by angle
// Don't do special coloring in bloom mode, because it relies on grayscale
// initial rendering
var colorTailByAngle = false;
var colorDotByAngle = false;
var randomColorThreshold = void 0;
if (LIGHTMODE !== 'bloom') {
if (COLORMODE === 'angle') {
if (Math.random() < 0.6) {
colorTailByAngle = true;
}
if (Math.random() < 0.6) {
colorDotByAngle = true;
}
}
if (COLORMODE === 'random') {
randomColorThreshold = 0.66;
}
}
// console.log(`Colors: tails ${colorTailByAngle}, dots: ${colorDotByAngle}`);
// source/sink stuff
if (FIELDMODE === 'flow') {
var totalStrength = 0;
sourceTransform.sources.forEach(function (source) {
totalStrength += source.strength;
});
lineScale = 1 / totalStrength;
}
// step thru points
pts.forEach(function (p, i) {
x = p[0];
y = p[1];
xnorm = x / cw;
ynorm = y / ch;
// shift base points to their warped coordinates
x = x + cellSize * trans.xbase(xnorm, ynorm) * warp;
y = y + cellSize * trans.ybase(xnorm, ynorm) * warp;
var xNoise = 0;
var yNoise = 0;
if (FIELDNOISE > 0) {
xNoise = (0, _utils.randomInRange)(-1, 1) * FIELDNOISE;
yNoise = (0, _utils.randomInRange)(-1, 1) * FIELDNOISE;
}
// get end of tail coords
if (FIELDMODE === 'flow') {
// flow fields (source-sink)
var flow = sourceTransform.t(xnorm, ynorm);
_x = flow[0];
_y = flow[1];
} else {
// harmonic fields
_x = trans.xtail(xnorm, ynorm);
_y = trans.ytail(xnorm, ynorm);
}
_x += xNoise;
_y += yNoise;
var theta = Math.atan2(_y, _x);
var fillIndex = Math.round(contrastPalette.length * theta / PI / 2);
var angleColor = contrastPalette[fillIndex];
if (colorDotByAngle) {
dotFill = angleColor;
}
if (COLORMODE === 'random' && Math.random() < randomColorThreshold) {
dotFill = getContrastColor();
}
// draw dot
ctx.globalAlpha = 1;
(0, _shapes.drawCircle)(ctx, x, y, (trans.radius(xnorm, ynorm) + 1) * dotScale, { fill: dotFill });
ctx.globalAlpha = opacityFunc(_x, _y);
if (colorTailByAngle) {
ctx.strokeStyle = angleColor;
}
if (COLORMODE === 'random' && Math.random() < randomColorThreshold) {
ctx.strokeStyle = getContrastColor();
}
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + cellSize * _x * lineScale, y + cellSize * _y * lineScale);
ctx.stroke();
});
ctx.globalAlpha = 1;
// in bloom mode, we draw a big colorful gradient over the grayscale
// background, using palette colors and nice blend modes
if (LIGHTMODE === 'bloom') {
ctx.globalCompositeOperation = 'color-dodge';
// bloom with linear gradient
ctx.fillStyle = (0, _utils.getGradientFunction)(opts.palette)(ctx, cw, ch); //getContrastColor();
ctx.fillRect(0, 0, cw, ch);
if (Math.random() < 0.5) {
// bloom with spot lights
var dodgeDot = function dodgeDot() {
var max = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1.5;
var gx = void 0,
gy = void 0,
gr1 = void 0,
gr2 = void 0;
gx = (0, _utils.randomInRange)(0, cw);
gy = (0, _utils.randomInRange)(0, ch);
gr1 = (0, _utils.randomInRange)(0, 0.25);
gr2 = (0, _utils.randomInRange)(gr1, max);
var radial = ctx.createRadialGradient(gx, gy, gr1 * SCALE, gx, gy, gr2 * SCALE);
radial.addColorStop(0, (0, _utils.randItem)(opts.palette));
radial.addColorStop(1, '#000000');
ctx.fillStyle = radial;
ctx.fillRect(0, 0, cw, ch);
};
// try layering dots with varying coverage
ctx.globalAlpha = (0, _utils.randomInRange)(0.4, 0.7);
dodgeDot(1.5);
ctx.globalAlpha = (0, _utils.randomInRange)(0.4, 0.7);
dodgeDot(1.0);
ctx.globalAlpha = (0, _utils.randomInRange)(0.7, 0.9);
dodgeDot(0.5);
ctx.globalAlpha = 1;
}
ctx.globalCompositeOperation = 'normal';
}
// add noise
if (opts.addNoise) {
if (opts.noiseInput) {
// apply noise from supplied canvas
_noiseutils2.default.applyNoiseCanvas(el, opts.noiseInput);
} else {
// create noise pattern and apply
_noiseutils2.default.addNoiseFromPattern(el, opts.addNoise, cw / 3);
}
}
// if new canvas child was created, append it
if (newEl) {
container.appendChild(el);
}
}
/***/ }),
/***/ 2:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Add noise to existing artwork, adding small equal values to each r,g,b
* component of each pixel, by stepping through imageData.
* Noise values darken or lighten pixels within the bounds of @opacity.
* @param {node} canvas input canvas to act upon
* @param {number} opacity number from 0-1. Values < 0.1 recommended.
*/
function addNoiseToCanvas(canvas) {
var opacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.2;
var ctx = canvas.getContext('2d');
var noise = void 0;
var d = ctx.getImageData(0, 0, canvas.width, canvas.height);
var px = d.data;
var n = px.length;
var random = Math.random;
var i = 0;
// manipulate imageData array
while (i < n) {
noise = opacity * ((random() - 0.5) * 256) | 0;
px[i++] += noise;
px[i++] += noise;
px[i++] += noise;
i++; // step i for alpha value
}
ctx.putImageData(d, 0, 0);
}
/**
* Add noise to @canvas efficiently, by creating a separate offscreen noisy
* canvas, then applying that as a tiled pattern.
* @param {node} canvas the canvas to add noise to
* @param {number} opacity the intensity of the noise
* @param {number} tileSize the size of the pattern tile (a square)
* @param {boolean} useOverlay if true, will composite using overlay blend mode
*/
function addNoiseFromPattern(canvas, opacity, tileSize, useOverlay) {
var noiseCanvas = createNoiseCanvas(opacity, tileSize);
applyNoiseCanvas(canvas, noiseCanvas, useOverlay);
return {
noiseCanvas: noiseCanvas,
canvas: canvas
};
}
/**
* Creates an offscreen noisy canvas, where pixels are black or white with
* alpha values random less than @opacity. This can be applied to other canvases
* as a pattern for efficient noise application.
* @param {number} opacity Noise intensity. As usual, small values < 0.1 best
* @param {number} tileSize The size of the pattern to be created
* @return {node} returns a reference to the canvas
*/
function createNoiseCanvas(opacity, tileSize) {
tileSize = tileSize || 100;
var canvas = document.createElement('canvas');
canvas.width = tileSize;
canvas.height = tileSize;
// add noise to the offscreen canvas
var ctx = canvas.getContext('2d');
var noise = void 0;
var d = ctx.getImageData(0, 0, canvas.width, canvas.height);
var px = d.data;
var n = px.length;
var random = Math.random;
var i = 0;
// manipulate imageData array
while (i < n) {
px[i++] = px[i++] = px[i++] = random() > 0.5 ? 255 : 0;
px[i++] = opacity * random() * 256 | 0;
}
ctx.putImageData(d, 0, 0);
return canvas;
}
/**
* Actually do the application of @noiseCanvas as a pattern to @targetCanvas
* @param {node} targetCanvas the destination artwork
* @param {node} noiseCanvas the input canvas with alpha channel noise
* @param {boolean} useOverlay composite with overlay vs normal
* @return {node} return ref to the @targetCanvas
*/
function applyNoiseCanvas(targetCanvas, noiseCanvas, useOverlay) {
var ctx = targetCanvas.getContext('2d');
// create a noise pattern from the offscreen canvas
var noisePattern = ctx.createPattern(noiseCanvas, 'repeat');
ctx.fillStyle = noisePattern;
if (useOverlay) {
ctx.globalCompositeOperation = 'overlay';
}
ctx.fillRect(0, 0, targetCanvas.width, targetCanvas.height);
if (useOverlay) {
ctx.globalCompositeOperation = 'normal';
}
return targetCanvas;
}
exports.default = {
addNoiseToCanvas: addNoiseToCanvas,
addNoiseFromPattern: addNoiseFromPattern,
createNoiseCanvas: createNoiseCanvas,
applyNoiseCanvas: applyNoiseCanvas
};
/***/ }),
/***/ 25:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.trails = trails;
var _noiseutils = __webpack_require__(2);
var _noiseutils2 = _interopRequireDefault(_noiseutils);
var _palettes = __webpack_require__(1);
var _palettes2 = _interopRequireDefault(_palettes);
var _hexScatter = __webpack_require__(4);
var _hexScatter2 = _interopRequireDefault(_hexScatter);
var _utils = __webpack_require__(0);
var _shapes = __webpack_require__(3);
var _fieldUtils = __webpack_require__(5);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var PI = Math.PI;
var FIELDMODES = ['harmonic', 'flow'];
var GRIDMODES = ['normal', 'scatter', 'random'];