-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecret.js
201 lines (169 loc) · 5.45 KB
/
secret.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const songs = ["solo", "multi", "voice"];
$("#switch-container").click(() => {
let toggleContainer = $("#toggle-container");
let toggleNumber = $(this).data("toggleNumber");
toggleNumber = !toggleNumber;
$(this).data("toggleNumber", toggleNumber);
if (toggleNumber) {
// Switches the highlighted part of the switch.
toggleContainer.css("clipPath", "inset(0 0 0 50%)");
toggleContainer.css("backgroundColor", "dodgerblue");
$("#view-1").hide();
$("#view-2").css("display", "flex");
songs.forEach(song => eval(`${song}Win.sound.pause()`));
secret2.loop();
} else {
// Switches the highlighted part of the switch.
toggleContainer.css("clipPath", "inset(0 50% 0 0)");
toggleContainer.css("backgroundColor", "dodgerblue");
$("#view-2").hide();
$("#view-1").show();
secret2.noLoop();
}
});
function eventHandlers() {
songs.forEach(song => {
eval(`
${song}Win = $(".${song} iframe")[0].contentWindow;
$(".${song} .play-sound").click(() => {
if (${song}Win.sound.isPlaying()) {
${song}Win.sound.pause();
} else {
${song}Win.sound.loop();
}
});
`);
eval(`$(".${song} .show-amps").click(() => ${song}Win.sketch.showAmp = !${song}Win.sketch.showAmp);`);
});
$("#play-once").click(() => {
secret2.repeat = false;
$("#play-once").attr("class", "button-primary");
$("#play-forever").attr("class", "");
});
$("#play-forever").click(() => {
secret2.repeat = true;
secret2.loop();
$("#play-once").attr("class", "");
$("#play-forever").attr("class", "button-primary");
});
}
class Complex {
constructor(a, b) {
this.re = a;
this.im = b;
}
add(c) {
return new Complex(this.re + c.re, this.im + c.im);
}
mult(c) {
const re = this.re * c.re - this.im * c.im;
const im = this.re * c.im + this.im * c.re;
return new Complex(re, im);
}
}
let secret2 = new p5((p) => {
function dft(x) {
const X = [];
const N = x.length;
for (let k = 0; k < N; k++) {
let sum = new Complex(0, 0);
for (let n = 0; n < N; n++) {
const phi = (p.TWO_PI * k * n) / N;
const c = new Complex(p.cos(phi), -p.sin(phi));
sum = sum.add(x[n].mult(c));
}
sum.re = sum.re / N;
sum.im = sum.im / N;
let freq = k;
let amp = p.sqrt(sum.re * sum.re + sum.im * sum.im);
let phase = p.atan2(sum.im, sum.re);
X[k] = { re: sum.re, im: sum.im, freq, amp, phase };
}
return X;
}
function epicycles(x, y, rot, fourier) {
for (let k = 0; k < fourier.length; k++) {
let prevx = x;
let prevy = y;
let { amp, freq, phase } = fourier[k];
x += amp * p.sin(freq * p.local_t + phase + rot);
y += amp * p.cos(freq * p.local_t + phase + rot);
// draws the circles.
p.push();
p.noFill();
p.strokeWeight(2);
p.ellipseMode(p.RADIUS);
p.circle(prevx, prevy, amp);
p.pop();
// draws the lines.
p.push();
p.strokeWeight(3);
p.line(prevx, prevy, x, y);
p.pop();
}
return { x, y };
}
let local_speed;
p.st = [];
p.local_t = 0;
p.fourierS = [];
p.path = [];
p.repeat = true;
p.setup = function() {
p.width = 0.9 * p.windowWidth;
let cnv = p.createCanvas(p.width, 600);
cnv.parent("#secret2");
local_t = 0;
local_A = 80;
local_cx = 200;
local_cy = p.height / 2;
let drawWidth = drawingSize[0];
let drawHeight = drawingSize[1];
let drawScale = p.height / drawHeight;
for (let i = 0; i < drawing.length; i += 3) {
let x = -drawing[i].x + drawWidth / 2;
let y = drawing[i].y - drawHeight / 2;
p.st.unshift(new Complex(drawScale * x, drawScale * y));
}
let lastIndex = drawing.length - 1;
let x = -drawing[lastIndex].x + drawWidth / 2;
let y = drawing[lastIndex].y - drawHeight / 2;
p.st.unshift(new Complex(drawScale * x, drawScale * y));
p.fourierS = dft(p.st);
p.fourierS.sort((a, b) => b.amp - a.amp);
p.noLoop();
};
p.windowResized = function () {
p.resizeCanvas(0.9 * p.windowWidth, 600);
}
p.draw = function() {
p.background(218);
p.stroke(155);
let v = epicycles(p.width / 2, p.height / 2, -p.HALF_PI, p.fourierS);
p.path.unshift(v);
p.push();
p.stroke(0);
p.strokeWeight(2);
p.noFill();
p.beginShape();
for (let i = 0; i < p.path.length; i++) {
p.vertex(p.path[i].x, p.path[i].y);
}
p.endShape();
p.pop();
p.push();
p.fill(0);
p.noStroke();
p.textSize(14);
p.text("Logo Design By Danielle Salloum", p.width - 235, p.height - 5);
p.pop();
local_speed = p.TWO_PI / p.fourierS.length;
p.local_t -= local_speed;
if (p.local_t < -p.TWO_PI) {
p.local_t = 0;
p.path = [];
if (!p.repeat)
p.noLoop();
}
};
});