-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
73 lines (63 loc) · 1.55 KB
/
sketch.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
let hue = 0, i = 0;
let currentPoint, nextPoint;
var w = window.innerWidth;
var h = window.innerHeight;
// Sliders defaults
let R = 224; // R: base radius
let r = 28; // r: second radius
let p = 93; // p: length of the pen
let slider_R, slider_r, slider_p;
function setup() {
canvas = createCanvas(w, h);
background(255);
colorMode(HSB);
slider_R = createSlider(10, 400, R)
.position(10, 5)
.style("width", "400px");
slider_r = createSlider(10, 400, r)
.position(10, 25)
.style("width", "400px");
slider_p = createSlider(10, 200, p)
.position(10, 45)
.style("width", "400px");
currentPoint = [
w/2 + (R - r) * cos(i) + p * cos(i * (1 - r / R)),
h/2 + (R - r) * sin(i) - p * sin(i * (1 - r / R)),
];
nextPoint = null;
}
function draw() {
//////////////////////// The sliders
fill(255);
noStroke();
rect(0, 0, 450, 90);
R = slider_R.value();
r = slider_r.value();
p = slider_p.value();
textSize(15);
fill(0);
text(R, 420, 20);
text(r, 420, 40);
text(p, 420, 60);
//////////////////////// The spirograph
noFill();
strokeWeight(2);
i += PI / 20;
nextPoint = [
w/2 + (R - r) * cos(i) + p * cos(i * (1 - r / R)),
h/2 + (R - r) * sin(i) - p * sin(i * (1 - r / R)),
];
stroke(hue, 255, 80);
hue += 1;
if (hue >= 360) hue = 0;
line(currentPoint[0], currentPoint[1], nextPoint[0], nextPoint[1]);
currentPoint = nextPoint;
}
function mouseReleased() {
background(255);
}
window.onresize = function () {
w = window.innerWidth;
h = window.innerHeight;
canvas.size(w, h);
};