Skip to content

Commit f24a9bb

Browse files
committed
ui changes
1 parent 3c8e468 commit f24a9bb

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

sketch.js

+41-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
let time = 0;
2-
let slider;
2+
let slider,radiusSlider,speedSlider;
3+
let STAGE_WIDTH = 800;
4+
const STAGE_HEIGHT = 400;
5+
const colors = [
6+
"#2EC4B6",
7+
"#EFDC05",
8+
"#EFDC05",
9+
"#E53A40",
10+
"#2EC4B6"
11+
]
12+
let positions = []
13+
14+
315
function setup() {
4-
createCanvas(1200, 400);
5-
slider = createSlider(1,10,1)
16+
STAGE_WIDTH = windowWidth;
17+
createCanvas(STAGE_WIDTH, STAGE_HEIGHT);
18+
//createCanvas(1200, 400);
19+
slider = createSlider(1,10,5);
20+
radiusSlider = createSlider(10,100,100);
21+
speedSlider = createSlider(1,100,50);
22+
623
}
724
wave_locations = [];
825
function getRadius(N) {
926
if (N <= 0) return 0;
10-
return 100 * (4 / (N * PI));
27+
return (radiusSlider.value() || 100) * (4 / (N * PI));
1128
}
12-
const colors = [
13-
"#2EC4B6",
14-
"#EFDC05",
15-
"#EFDC05",
16-
"#E53A40",
17-
"#2EC4B6"
18-
]
19-
let positions = []
2029

2130
function getPosition(N, time) {
2231
let radius,
@@ -30,24 +39,27 @@ function getPosition(N, time) {
3039
}
3140
let radius = getRadius(n);
3241
stroke(colors[(n-1)%5]);
42+
strokeWeight(0.5)
3343
ellipse(x, y, radius * 2);
3444
let prev_x = x,
3545
prev_y = y;
3646
x += radius * cos(n * time);
3747
y += radius * sin(n * time);
48+
stroke(0)
3849
line(prev_x, prev_y, x, y);
39-
40-
ellipse(x, y, 8);
50+
fill(0)
51+
ellipse(x, y, 4);
4152

4253
stroke(0);
4354
noFill();
4455

4556
fill(0);
46-
if(positions[i].length < 500){
57+
if(positions[i].length < radiusSlider.value() * 100){
4758
positions[i].push({x,y});
4859
}
4960
for(let k = 0; k < positions[i].length;k++){
5061
stroke(colors[(n-1)%5]);
62+
strokeWeight(1.5)
5163
point(positions[i][k].x,positions[i][k].y)
5264
}
5365

@@ -57,14 +69,19 @@ function getPosition(N, time) {
5769
return { x, y, radius };
5870
}
5971
function draw() {
60-
background(255);
61-
translate(400, 200);
72+
background("#f7f7f7");
73+
strokeWeight(0.5)
74+
radiusSlider.changed(() => positions = [])
75+
76+
line(0,STAGE_HEIGHT/2, STAGE_WIDTH,STAGE_HEIGHT/2)
77+
78+
translate(300, 200);
6279
radius = getRadius(1);
6380

6481
let { x, y } = getPosition(slider.value(), time);
6582
wave_locations.unshift(y);
6683
stroke("#ef5285");
67-
strokeWeight(2)
84+
strokeWeight(1)
6885
line(x, y, 210, y);
6986

7087
//console.log(wave_locations);
@@ -73,10 +90,14 @@ function draw() {
7390
for (let i = 0; i < wave_locations.length; i++) {
7491
stroke(0);
7592
noFill();
76-
vertex(i, wave_locations[i]);
93+
94+
strokeWeight(1);
95+
vertex(i, wave_locations[i]);
96+
97+
7798
}
7899
endShape();
79-
time -= 0.05;
100+
time += speedSlider.value() / 1000;
80101
if (wave_locations.length > 1000) {
81102
wave_locations.pop();
82103
}

0 commit comments

Comments
 (0)