diff options
| author | Andrew Guschin <saintruler@gmail.com> | 2021-11-18 23:16:33 +0400 |
|---|---|---|
| committer | Andrew Guschin <saintruler@gmail.com> | 2021-11-18 23:16:33 +0400 |
| commit | 516a43e46898363e05a0d13b5c4074f7a4e18517 (patch) | |
| tree | a3392b4595655f167a6d82ef8d436d829256f21f /sketch.js | |
Added times table and grid sketches
Diffstat (limited to 'sketch.js')
| -rw-r--r-- | sketch.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/sketch.js b/sketch.js new file mode 100644 index 0000000..77a4899 --- /dev/null +++ b/sketch.js @@ -0,0 +1,64 @@ +function v2(x, y) { + this.x = x; + this.y = y; +} + +function gradient() { + this.color = [255, 0, 0]; + this.index = 1; + this.direction = 1; +} + +gradient.prototype.next = function() { + this.color[this.index] += this.direction; + if (this.color[this.index] == max(this.direction, 0) * 255) { + this.index = (this.index + 2) % 3; + this.direction *= -1; + } + return this.color; +}; + +let count = 250; +let multiple = 1; +let radius = 400; +let step = 0.01; +let center = new v2(radius, radius); + +let theta = 2 * Math.PI / count; + +let alpha = n => (theta * n) % count; + +let f_x = n => cos(alpha(n)) * radius + center.x; +let f_y = n => sin(alpha(n)) * radius + center.y; + +let f = n => new v2(f_x(n), f_y(n)); + +let canvasW = radius * 2; +let canvasH = radius * 2; + +function setup() { + createCanvas(canvasW, canvasH); +} + +let grad = new gradient(); + +function draw() { + background(0); + + fill(0); + + c = grad.next(); + stroke(c); + + circle(center.x, center.y, radius * 2); + + for (n = 0; n < count; n++) + { + p1 = f(n); + p2 = f(multiple * n); + stroke(c); + line(p1.x, p1.y, p2.x, p2.y); + } + + multiple += step; +} |