summaryrefslogtreecommitdiff
path: root/sketch.js
blob: 77a4899aa75203599194315502f1e70f353f479a (plain)
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
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;
}