@@ -12,60 +12,54 @@ radius <- 50
1212frequency <- 2
1313frequency2 <- 2
1414
15- settings <- function()
16- {
15+ settings <- function() {
1716 processing$size(600, 200)
1817}
1918
20- draw <- function()
21- {
19+ draw <- function() {
2220 processing$background(127)
2321 processing$noStroke()
2422 processing$fill(255)
25- processing$ellipse(width/8, 75, radius* 2, radius* 2)
23+ processing$ellipse(width/8, 75, radius * 2, radius * 2)
2624 # 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)
2927 processing$fill(0)
30-
28+
3129 processing$rect(px, py, 5, 5)
3230 processing$stroke(100)
3331 processing$line(width/8, 75, px, py)
3432 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
3835 angle2 <- 0
39-
36+
4037 # 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)
4642 angle2 <- angle2 - frequency2
4743 }
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
5147 processing$noStroke()
52- processing$ellipse(width/8+ radius+ x, py, 5, 5)
48+ processing$ellipse(width/8 + radius + x, py, 5, 5)
5349 angle <- angle - frequency
5450 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) {
5954 x <- 0
6055 angle <- 0
6156 }
62-
57+
6358 # Draw dynamic line connecting circular path with wave
6459 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