1
1
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
+
3
15
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
+
6
23
}
7
24
wave_locations = [ ] ;
8
25
function getRadius ( N ) {
9
26
if ( N <= 0 ) return 0 ;
10
- return 100 * ( 4 / ( N * PI ) ) ;
27
+ return ( radiusSlider . value ( ) || 100 ) * ( 4 / ( N * PI ) ) ;
11
28
}
12
- const colors = [
13
- "#2EC4B6" ,
14
- "#EFDC05" ,
15
- "#EFDC05" ,
16
- "#E53A40" ,
17
- "#2EC4B6"
18
- ]
19
- let positions = [ ]
20
29
21
30
function getPosition ( N , time ) {
22
31
let radius ,
@@ -30,24 +39,27 @@ function getPosition(N, time) {
30
39
}
31
40
let radius = getRadius ( n ) ;
32
41
stroke ( colors [ ( n - 1 ) % 5 ] ) ;
42
+ strokeWeight ( 0.5 )
33
43
ellipse ( x , y , radius * 2 ) ;
34
44
let prev_x = x ,
35
45
prev_y = y ;
36
46
x += radius * cos ( n * time ) ;
37
47
y += radius * sin ( n * time ) ;
48
+ stroke ( 0 )
38
49
line ( prev_x , prev_y , x , y ) ;
39
-
40
- ellipse ( x , y , 8 ) ;
50
+ fill ( 0 )
51
+ ellipse ( x , y , 4 ) ;
41
52
42
53
stroke ( 0 ) ;
43
54
noFill ( ) ;
44
55
45
56
fill ( 0 ) ;
46
- if ( positions [ i ] . length < 500 ) {
57
+ if ( positions [ i ] . length < radiusSlider . value ( ) * 100 ) {
47
58
positions [ i ] . push ( { x, y} ) ;
48
59
}
49
60
for ( let k = 0 ; k < positions [ i ] . length ; k ++ ) {
50
61
stroke ( colors [ ( n - 1 ) % 5 ] ) ;
62
+ strokeWeight ( 1.5 )
51
63
point ( positions [ i ] [ k ] . x , positions [ i ] [ k ] . y )
52
64
}
53
65
@@ -57,14 +69,19 @@ function getPosition(N, time) {
57
69
return { x, y, radius } ;
58
70
}
59
71
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 ) ;
62
79
radius = getRadius ( 1 ) ;
63
80
64
81
let { x, y } = getPosition ( slider . value ( ) , time ) ;
65
82
wave_locations . unshift ( y ) ;
66
83
stroke ( "#ef5285" ) ;
67
- strokeWeight ( 2 )
84
+ strokeWeight ( 1 )
68
85
line ( x , y , 210 , y ) ;
69
86
70
87
//console.log(wave_locations);
@@ -73,10 +90,14 @@ function draw() {
73
90
for ( let i = 0 ; i < wave_locations . length ; i ++ ) {
74
91
stroke ( 0 ) ;
75
92
noFill ( ) ;
76
- vertex ( i , wave_locations [ i ] ) ;
93
+
94
+ strokeWeight ( 1 ) ;
95
+ vertex ( i , wave_locations [ i ] ) ;
96
+
97
+
77
98
}
78
99
endShape ( ) ;
79
- time -= 0.05 ;
100
+ time += speedSlider . value ( ) / 1000 ;
80
101
if ( wave_locations . length > 1000 ) {
81
102
wave_locations . pop ( ) ;
82
103
}
0 commit comments