-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.bundle.js
1517 lines (1269 loc) · 51.3 KB
/
clock.bundle.js
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 = 47);
/******/ })
/************************************************************************/
/******/ ({
/***/ 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;
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;
}
/***/ }),
/***/ 1:
/***/ (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
};
/***/ }),
/***/ 19:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.truchet = truchet;
var _noiseutils = __webpack_require__(1);
var _noiseutils2 = _interopRequireDefault(_noiseutils);
var _palettes = __webpack_require__(2);
var _palettes2 = _interopRequireDefault(_palettes);
var _utils = __webpack_require__(0);
var _shapes = __webpack_require__(3);
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 DEFAULTS = {
container: 'body',
palette: _palettes2.default.south_beach,
addNoise: 0.04,
noiseInput: null,
dust: false,
skew: 1, // normalized skew
clear: true,
style: 'auto', // one of modes
layer: 'auto', // true | false | auto
count: 0, // 0 for auto, or an integer
weight: 0, // 0 for auto, or 1-10 for normalized weights
contrast: true
};
var PI = Math.PI;
// Main function
function truchet(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);
// 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');
// util to draw a square and clip following rendering inside
function clipSquare(ctx, w, h, color) {
ctx.save();
ctx.beginPath();
ctx.rect(0, 0, w, h);
ctx.fillStyle = color;
ctx.closePath();
ctx.fill();
ctx.clip();
}
// color funcs
var randomFill = function randomFill() {
return "#" + Math.random().toString(16).slice(2, 8);
};
var getSolidFill = (0, _utils.getSolidColorFunction)(opts.palette);
// define grid
var count = Math.round(opts.count) || Math.round((0, _utils.randomInRange)(4, 9));
var w = Math.ceil(cw / count);
var h = w;
var vcount = Math.ceil(ch / h);
// setup vars for each cell
var x = 0;
var y = 0;
var xnorm = 0;
var ynorm = 0;
var renderer = void 0;
var secondLayer = void 0;
if (opts.layer === true || opts.layer === 'true') {
secondLayer = true;
}
if (opts.layer === false || opts.layer === 'false') {
secondLayer = false;
}
if (opts.layer === null || opts.layer === undefined || opts.layer == 'auto') {
secondLayer = Math.random() < 0.5;
}
// play with these random seeds
var a = void 0,
b = void 0,
c = void 0;
a = Math.random();
b = Math.random();
c = Math.random();
// shared colors
var fg = void 0; // hold on…
var bg = getSolidFill(); // pick bg
// get palette of non-bg colors
var contrastPalette = [].concat(opts.palette);
contrastPalette.splice(opts.palette.indexOf(bg), 1);
var getContrastColor = (0, _utils.getSolidColorFunction)(contrastPalette);
fg = getContrastColor(); // …now set fg in contrast to bg
// mode settings
// line weight
var weight = void 0;
if (opts.weight) {
weight = w / 30 * opts.weight;
} else {
weight = w / 30 * (0, _utils.randomInRange)(1, 10);
}
// component utils
// draw a triangle at anchor corner
function _triangle(anchor, fill) {
var corners = [[0, 0], [w, 0], [w, h], [0, h]];
var drawCorners = [];
fill = fill || getSolidFill();
if (anchor === undefined) anchor = Math.round((0, _utils.randomInRange)(0, 3));
drawCorners = [].concat(corners);
drawCorners.splice(anchor, 1);
// draw a triangle with the remaining 3 points
ctx.beginPath();
ctx.moveTo.apply(ctx, _toConsumableArray(drawCorners[0]));
ctx.lineTo.apply(ctx, _toConsumableArray(drawCorners[1]));
ctx.lineTo.apply(ctx, _toConsumableArray(drawCorners[2]));
ctx.closePath();
ctx.fillStyle = fill;
ctx.fill();
}
// draw a circle at anchor corner
function _circle(anchor, fill) {
var corners = [[0, 0], [w, 0], [w, h], [0, h]];
var drawCorners = [];
fill = fill || getSolidFill();
if (anchor === undefined) anchor = Math.round((0, _utils.randomInRange)(0, 3));
(0, _shapes.drawCircle)(ctx, corners[anchor][0], corners[anchor][1], w, {
fill: fill
});
}
// fill cell
// first arg is for parity with _triangle and _circle
function _square(_, fill) {
fill = fill || getSolidFill();
ctx.rect(0, 0, w, h);
ctx.fillStyle = fill;
ctx.closePath();
ctx.fill();
}
// mode
function circles(background) {
background = background || bg;
var px = void 0,
py = void 0;
for (var i = 0; i < vcount; i++) {
for (var j = 0; j < count; j++) {
// convenience vars
x = w * j;
y = h * i;
xnorm = x / cw;
ynorm = y / ch;
// shift and clip
ctx.translate(x, y);
clipSquare(ctx, w, h, background);
_circle();
// unshift, unclip
ctx.restore();
(0, _utils.resetTransform)(ctx);
}
}
}
// mode
function triangles(background) {
background = background || bg;
for (var i = 0; i < vcount; i++) {
for (var j = 0; j < count; j++) {
// convenience vars
x = w * j;
y = h * i;
xnorm = x / cw;
ynorm = y / ch;
// shift and clip
ctx.translate(x, y);
clipSquare(ctx, w, h, background);
_triangle();
// unshift, unclip
ctx.restore();
(0, _utils.resetTransform)(ctx);
}
}
}
// mode
function mixed(background) {
background = background || bg;
var px = void 0,
py = void 0,
seed = void 0;
var styles = [function () {
renderer = _shapes.drawCircle;
px = 0;
py = 0;
}];
for (var i = 0; i < vcount; i++) {
for (var j = 0; j < count; j++) {
// convenience vars
x = w * j;
y = h * i;
xnorm = x / cw;
ynorm = y / ch;
// shift and clip
ctx.translate(x, y);
clipSquare(ctx, w, h, background);
switch (Math.round((0, _utils.randomInRange)(1, 12))) {
case 1:
case 2:
case 3:
case 4:
_circle();
break;
case 5:
case 6:
case 7:
case 8:
_square();
break;
case 9:
case 10:
case 11:
case 12:
_triangle();
break;
}
// unshift, unclip
ctx.restore();
(0, _utils.resetTransform)(ctx);
}
}
}
// gather our modes
var modes = {
circles: circles,
triangles: triangles,
mixed: mixed
};
// do the loop with one of our modes
if (opts.style && modes[opts.style]) {
renderer = modes[opts.style];
} else {
renderer = modes[(0, _utils.randItem)(Object.keys(modes))];
}
renderer(bg, weight);
if (secondLayer) {
fg = getContrastColor();
ctx.globalAlpha = 0.8;
renderer('transparent', opts.contrast ? weight / 2 : weight);
ctx.globalAlpha = 1;
}
// 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, w / 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
});
// 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'],
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']
};
exports.default = palettes;
// older palettes:
var lemon_beach = exports.lemon_beach = ['#d7d7d7', '#979797', '#cabd9d', '#e4ca49', '#89bed3', '#11758e'];
/***/ }),
/***/ 3:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.drawLine = drawLine;
/*
* Scaffolding for a drawing function.
* Implements basic setup for placement, rotation, stroke, fill,
* and leaving the path open.
* All the drawing takes place in @renderFunc, which must have the standard
* signature used in the returned function.
* The renderFunc should not begin or close paths, or translate the canvas.
*/
function _makeRenderer(renderFunc) {
return function (ctx, x, y, size, opts) {
if (!opts.continue) {
ctx.save();
ctx.beginPath();
}
ctx.translate(x, y);
if (opts.angle) {
ctx.rotate(opts.angle);
}
// This is where all the drawing happens!
//
renderFunc(ctx, x, y, size, opts);
//
// Done defining path
if (!opts.continue) {
ctx.closePath();
ctx.restore();
}
// Paint pixels
ctx.fillStyle = opts.fill;
ctx.strokeStyle = opts.stroke;
opts.fill && ctx.fill();
opts.stroke && ctx.stroke();
return ctx;
};
}
// Draw a closed circle
var drawCircle = exports.drawCircle = _makeRenderer(function (ctx, x, y, r, opts) {
ctx.moveTo(r, 0);
ctx.arc(0, 0, r, 0, 2 * Math.PI, false);
});
// Draw a ring with 50% thickness
var drawRing = exports.drawRing = _makeRenderer(function (ctx, x, y, r, opts) {
var inner = r * 0.5;
ctx.moveTo(r, 0);
ctx.arc(0, 0, r, 0, 2 * Math.PI, false);
// cutout
ctx.moveTo(inner, 0);
ctx.arc(0, 0, inner, 0, 2 * Math.PI, true);
});
// Draw a closed square
var drawSquare = exports.drawSquare = _makeRenderer(function (ctx, x, y, d, opts) {
ctx.rect(-d, -d, d * 2, d * 2);
});
// Draw a closed rectangle with golden ratio aspect ratio
var drawRect = exports.drawRect = _makeRenderer(function (ctx, x, y, d, opts) {
var gl = 0.6180339;
ctx.rect(-d, -d * gl, d * 2, d * 2 * gl);
});
// Draw a square box, 60% thickness
var drawBox = exports.drawBox = _makeRenderer(function (ctx, x, y, d, opts) {
var r = d * 0.4;
ctx.moveTo(-d, -d);
ctx.lineTo(+d, -d);
ctx.lineTo(+d, +d);
ctx.lineTo(-d, +d);
ctx.lineTo(-d, -d);
// cutout
ctx.moveTo(-r, -r);
ctx.lineTo(-r, +r);
ctx.lineTo(+r, +r);
ctx.lineTo(+r, -r);
ctx.lineTo(-r, -r);
});
// Generate drawing functions for polygons
function _drawPolygon(SIDES, SCALE) {
SCALE = SCALE || 1;
return _makeRenderer(function (ctx, x, y, d, opts) {
var r = d * SCALE;
var a = Math.PI * 2 / SIDES;
function _x(theta) {
return r * Math.cos(theta - Math.PI / 2);
}
function _y(theta) {
return r * Math.sin(theta - Math.PI / 2);
}
ctx.moveTo(_x(a * 0), _y(a * 0));
for (var i = 1; i <= SIDES; i++) {
ctx.lineTo(_x(a * i), _y(a * i));
}
});
}
// Strict drawing from centerpoint and radial corner placement
var drawExactTriangle = exports.drawExactTriangle = _drawPolygon(3, 1.2);
// Adjusting triangles downward a little fits them more naturally
// near other shapes.
var drawTriangle = exports.drawTriangle = function drawTriangle(ctx, x, y, d, opts) {
drawExactTriangle(ctx, x, y + d * 0.2, d, opts);
};
var drawPentagon = exports.drawPentagon = _drawPolygon(5, 1.1);
var drawHexagon = exports.drawHexagon = _drawPolygon(6, 1.05);
// Draw a line from @a to @b, where they are of form [x, y]
function drawLine(ctx, a, b) {
var _a = _slicedToArray(a, 2),
x1 = _a[0],
y1 = _a[1];
var _b = _slicedToArray(b, 2),
x2 = _b[0],
y2 = _b[1];
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
}
/***/ }),
/***/ 47:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
__webpack_require__(8);