@@ -12,60 +12,54 @@ radius <- 50
12
12
frequency <- 2
13
13
frequency2 <- 2
14
14
15
- settings <- function()
16
- {
15
+ settings <- function() {
17
16
processing$size(600, 200)
18
17
}
19
18
20
- draw <- function()
21
- {
19
+ draw <- function() {
22
20
processing$background(127)
23
21
processing$noStroke()
24
22
processing$fill(255)
25
- processing$ellipse(width/8, 75, radius* 2, radius* 2)
23
+ processing$ellipse(width/8, 75, radius * 2, radius * 2)
26
24
# Rotates rectangle around circle
27
- px <- width/8 + cos(processing$radians(angle))* (radius)
28
- py <- 75 + sin(processing$radians(angle))* (radius)
25
+ px <- width/8 + cos(processing$radians(angle)) * (radius)
26
+ py <- 75 + sin(processing$radians(angle)) * (radius)
29
27
processing$fill(0)
30
-
28
+
31
29
processing$rect(px, py, 5, 5)
32
30
processing$stroke(100)
33
31
processing$line(width/8, 75, px, py)
34
32
processing$stroke(200)
35
-
36
- # Keep reinitializing to 0, to avoid
37
- # Flashing during redrawing
33
+
34
+ # Keep reinitializing to 0, to avoid Flashing during redrawing
38
35
angle2 <- 0
39
-
36
+
40
37
# Draw static curve - y <- sin(x)
41
- for (i in 1:width - 1)
42
- {
43
- px2 <- width/8 + cos(processing$radians(angle2))*(radius)
44
- py2 <- 75 + sin(processing$radians(angle2))*(radius)
45
- processing$point(width/8+radius+i, py2)
38
+ for (i in 1:width - 1) {
39
+ px2 <- width/8 + cos(processing$radians(angle2)) * (radius)
40
+ py2 <- 75 + sin(processing$radians(angle2)) * (radius)
41
+ processing$point(width/8 + radius + i, py2)
46
42
angle2 <- angle2 - frequency2
47
43
}
48
-
49
- # Send small ellipse along sine curve
50
- # to illustrate relationship of circle to wave
44
+
45
+ # Send small ellipse along sine curve to illustrate relationship of circle to
46
+ # wave
51
47
processing$noStroke()
52
- processing$ellipse(width/8+ radius+ x, py, 5, 5)
48
+ processing$ellipse(width/8 + radius + x, py, 5, 5)
53
49
angle <- angle - frequency
54
50
x <- x + 1
55
-
56
- # When little ellipse reaches end of window,
57
- # set the variables back to 0
58
- if (x >= width-60) {
51
+
52
+ # When little ellipse reaches end of window, set the variables back to 0
53
+ if (x >= width - 60) {
59
54
x <- 0
60
55
angle <- 0
61
56
}
62
-
57
+
63
58
# Draw dynamic line connecting circular path with wave
64
59
processing$stroke(50)
65
- processing$line(px, py, width/8+radius+x, py)
66
-
67
- # Output calculations to screen
68
- # processing$text("y <- sin x", 35, 185)
69
- # processing$text("px <- " + px, 105, 185)
70
- # processing$text("py <- " + py, 215, 185)
71
- }
60
+ processing$line(px, py, width/8 + radius + x, py)
61
+
62
+ # Output calculations to screen processing$text('y <- sin x', 35, 185)
63
+ # processing$text('px <- ' + px, 105, 185) processing$text('py <- ' + py, 215,
64
+ # 185)
65
+ }
0 commit comments