-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
180 lines (102 loc) · 3.66 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
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
let param1, param2
let scaleX = 400
let scaleY = 400
function setup() {
createCanvas(1000, 1000).parent("canvas").mouseClicked(randomOne);
noFill();
background(0);
frameRate(60)
params = new URLSearchParams(window.location.search)
if(params.get("xp") && params.get("yp")) {
param1 = parseInt(params.get("yp"));
param2 = parseInt(params.get("xp"));
updateLink()
} else {
randomOne()
}
}
function randomOne() {
background(0);
param1 = floor(random(1, 13));
param2 = floor(random(1, 13));
updateLink()
}
function updateLink () {
const link = `https://weightan.github.io/EulerCurveJS?xp=${param2}&yp=${param1}`
select("#permalink").html(link).attribute("href", link)
}
function draw() {
translate(width / 2, height / 2)
beginShape()
stroke(255, 15);
strokeWeight(1);
for (let j = -3; j < 3; j += 0.01) {
let x = trapezoid_rule (bigX, 0, j, 200);
let y = trapezoid_rule (bigY, 0, j, 200);
curveVertex(scaleX*x, scaleY*y);
//curveVertex(300*x, 300*y);
}
endShape()
}
function bigY(ts){
if (param1 == 1){
return sin(ts*ts - radians(frameCount/5))*cos(ts- radians(frameCount/5));
} else if (param1 == 2){
return sin(ts*ts)*cos(ts- radians(frameCount/5));
} else if (param1 == 3){
return sin(ts*ts - radians(frameCount/5))*cos(ts);
} else if (param1 == 4){
return cos(ts*ts - radians(frameCount/5))*sin(ts- radians(frameCount/5));
} else if (param1 == 5){
return cos(ts*ts)*sin(ts- radians(frameCount/5));
} else if (param1 == 6){
return cos(ts*ts - radians(frameCount/5))*sin(ts);
} else if (param1 == 7){
return sin(ts*ts - radians(frameCount/5))*sin(ts- radians(frameCount/5));
} else if (param1 == 8){
return sin(ts*ts)*sin(ts- radians(frameCount/5));
} else if (param1 == 9){
return sin(ts*ts - radians(frameCount/5))*sin(ts);
}else if (param1 == 10){
return cos(ts*ts - radians(frameCount/5))*cos(ts- radians(frameCount/5));
} else if (param1 == 11){
return cos(ts*ts )*cos(ts- radians(frameCount/5));
} else if (param1 == 12){
return cos(ts*ts - radians(frameCount/5))*cos(ts);
}
}
function bigX(ts){
if (param2 == 1){
return sin(ts*ts - radians(frameCount/5))*cos(ts- radians(frameCount/5));
} else if (param2 == 2){
return sin(ts*ts)*cos(ts- radians(frameCount/5));
} else if (param2 == 3){
return sin(ts*ts - radians(frameCount/5))*cos(ts);
}else if (param2 == 4){
return cos(ts*ts - radians(frameCount/5))*sin(ts- radians(frameCount/5));
} else if (param2 == 5){
return cos(ts*ts)*sin(ts- radians(frameCount/5));
} else if (param2 == 6){
return cos(ts*ts - radians(frameCount/5))*sin(ts);
} else if (param2 == 7){
return sin(ts*ts - radians(frameCount/5))*sin(ts- radians(frameCount/5));
} else if (param2 == 8){
return sin(ts*ts )*sin(ts*ts - radians(frameCount/5/5));
} else if (param2 == 9){
return sin(ts*ts - radians(frameCount/5))*sin(ts);
}else if (param2 == 10){
return cos(ts*ts - radians(frameCount/5))*cos(ts- radians(frameCount/5));
} else if (param2 == 11){
return cos(ts*ts )*cos(ts- radians(frameCount/5));
} else if (param2 == 12){
return cos(ts*ts - radians(frameCount/5))*cos(ts);
}
}
function trapezoid_rule (func, a, b, nseg){
let dx = 1.0 * (b - a) / nseg
let sum = 0.5 * (func(a) + func(b))
for (let i = 1; i <= nseg; i += 1) {
sum += func(a + i * dx)
}
return sum * dx
}