|
7 | 7 | for (e = a * e + 9, X *= a, P *= a, S *= a, r *= a, H *= 500 * t / a ** 3, K *= t / a, V *= t / a, J *= a, h = a * h | 0, i *= 0.3 * (globalThis.zzfxV || 1), s = e + X + P + S + r | 0; f < s; d[f++] = o * i) ++l % (100 * E | 0) || (o = I ? 1 < I ? 2 < I ? 3 < I ? C(x * x) : n.max(n.min(n.tan(x), 1), -1) : 1 - (2 * x / t % 2 + 2) % 2 : 1 - 4 * n.abs(n.round(x / t) - x / t) : C(x), o = (h ? 1 - L + L * C(t * f / h) : 1) * (o < 0 ? -1 : 1) * n.abs(o) ** c * (f < e ? f / e : f < e + X ? 1 - (f - e) / X * (1 - B) : f < e + X + P ? B : f < s - r ? (s - f - r) / S * B : 0), o = r ? o / 2 + (r > f ? 0 : (f < s - r ? 1 : (s - f) / r) * d[f - r | 0] / 2 / i) : o, D && (o = Z = v * U + A * (U = W) + R * (W = o) - y * Y - m * (Y = Z))), u = (z += T += H) * n.cos(K * _++), x += u + u * j * C(f ** 5), g && ++g > J && (z += V, O += V, g = 0), !h || ++$ % h || (z = O, T = F, g = g || 1); |
8 | 8 | i = zzfxX.createBuffer(1, s, a), i.getChannelData(0).set(d), z = zzfxX.createBufferSource(), z.buffer = i, z.connect(zzfxX.destination), z.start(); |
9 | 9 | }; |
10 | | - var colors = [ |
| 10 | + var defaultPalette = [ |
11 | 11 | "#111", |
12 | 12 | "#6a7799", |
13 | 13 | "#aec2c2", |
|
45 | 45 | animate: true |
46 | 46 | }; |
47 | 47 | settings = Object.assign(defaults, settings); |
48 | | - let _initialized = false, _plugins = [], _canvas, _scale = 1, _ctx, _outline_fix = 0.5, _timeScale = 1, _lastFrameTime, _deltaTime = 1 / 60, _accumulated = 0, _rafid, _fontFamily = "sans-serif", _fontSize = 20, _rng_seed = Date.now(), _events = { |
| 48 | + let _initialized = false, _plugins = [], _canvas, _scale = 1, _ctx, _outline_fix = 0.5, _timeScale = 1, _lastFrameTime, _deltaTime = 1 / 60, _accumulated = 0, _rafid, _fontFamily = "sans-serif", _fontSize = 20, _rng_seed = Date.now(), _colors = defaultPalette, _events = { |
49 | 49 | init: false, |
50 | 50 | update: false, |
51 | 51 | draw: false, |
|
55 | 55 | tapping: false, |
56 | 56 | tapped: false |
57 | 57 | }, _helpers = { |
58 | | - settings: Object.assign({}, settings), |
59 | | - colors |
| 58 | + settings: Object.assign({}, settings) |
60 | 59 | }; |
61 | 60 | const instance = { |
62 | 61 | /** @type {number} */ |
|
77 | 76 | MOUSEY: -1, |
78 | 77 | /** @type {number[]} */ |
79 | 78 | DEFAULT_SFX: [0.5, 0, 1750, , , 0.3, 1, , , , 600, 0.1], |
| 79 | + /** @type {string[]} */ |
| 80 | + COLORS: _colors, |
80 | 81 | /** MATH API */ |
81 | 82 | /** |
82 | 83 | * Twice the value of the mathematical constant PI (π). |
|
870 | 871 | triggerEvent("after:" + eventName, arg1, arg2, arg3, arg4); |
871 | 872 | } |
872 | 873 | }, |
| 874 | + /** |
| 875 | + * Set or reset the color palette |
| 876 | + * |
| 877 | + * @param {string[]} [colors] |
| 878 | + */ |
| 879 | + pal(colors = defaultPalette) { |
| 880 | + DEV: assert( |
| 881 | + Array.isArray(colors) && colors.length > 0, |
| 882 | + "pal: 1st param must be a array of strings" |
| 883 | + ); |
| 884 | + _colors = colors; |
| 885 | + instance.setvar("COLORS", _colors); |
| 886 | + }, |
873 | 887 | /** |
874 | 888 | * Get a color by index |
875 | 889 | * |
|
881 | 895 | null == index || isNumber(index) && index >= 0, |
882 | 896 | "getcolor: 1st param must be a number" |
883 | 897 | ); |
884 | | - return colors[~~index % colors.length]; |
| 898 | + return _colors[~~index % _colors.length]; |
885 | 899 | }, |
886 | 900 | /** |
887 | 901 | * Create or update a instance variable |
|
1119 | 1133 | }); |
1120 | 1134 | on(root, "focus", () => { |
1121 | 1135 | if (!_rafid) { |
| 1136 | + _accumulated = 0; |
1122 | 1137 | _rafid = raf(drawFrame); |
1123 | 1138 | } |
1124 | 1139 | }); |
|
0 commit comments