|
1 | | -/** |
2 | | - * Constrain. |
3 | | - * |
4 | | - * Move the mouse across the screen to move the circle. |
5 | | - * The program constrains the circle to its box. |
6 | | - * |
7 | | - * Updated 20 January 2003 |
8 | | - */ |
9 | | - |
10 | | -float mx; |
11 | | -float my; |
12 | | -float delay = 40.0; |
13 | | -float esize = 25.0; |
14 | | -int box = 30; |
15 | | - |
16 | | -void setup() |
17 | | -{ |
18 | | - size(200, 200); |
19 | | - noStroke(); |
20 | | - smooth(); |
21 | | - ellipseMode(CENTER_RADIUS); |
22 | | -} |
23 | | - |
24 | | -void draw() |
25 | | -{ |
26 | | - background(51); |
27 | | - |
28 | | - if(abs(mouseX - mx) > 0.1) { |
29 | | - mx = mx + (mouseX - mx)/delay; |
30 | | - } |
31 | | - if(abs(mouseY - my) > 0.1) { |
32 | | - my = my + (mouseY- my)/delay; |
33 | | - } |
34 | | - |
35 | | - float distance = esize * 2; |
36 | | - mx = constrain(mx, box+distance, width-box-distance); |
37 | | - my = constrain(my, box+distance, height-box-distance); |
38 | | - fill(76); |
39 | | - rect(box+esize, box+esize, box*3, box*3); |
40 | | - fill(255); |
41 | | - ellipse(mx, my, esize, esize); |
42 | | -} |
| 1 | +/** |
| 2 | + * Constrain. |
| 3 | + * |
| 4 | + * Move the mouse across the screen to move the circle. |
| 5 | + * The program constrains the circle to its box. |
| 6 | + * |
| 7 | + * Updated 20 January 2003 |
| 8 | + */ |
| 9 | + |
| 10 | +float mx; |
| 11 | +float my; |
| 12 | +float easing = 0.05; |
| 13 | +float esize = 25.0; |
| 14 | +int box = 30; |
| 15 | + |
| 16 | +void setup() |
| 17 | +{ |
| 18 | + size(200, 200); |
| 19 | + noStroke(); |
| 20 | + smooth(); |
| 21 | + ellipseMode(CENTER_RADIUS); |
| 22 | +} |
| 23 | + |
| 24 | +void draw() |
| 25 | +{ |
| 26 | + background(51); |
| 27 | + |
| 28 | + if(abs(mouseX - mx) > 0.1) { |
| 29 | + mx = mx + (mouseX - mx) * easing; |
| 30 | + } |
| 31 | + if(abs(mouseY - my) > 0.1) { |
| 32 | + my = my + (mouseY- my) * easing; |
| 33 | + } |
| 34 | + |
| 35 | + float distance = esize * 2; |
| 36 | + mx = constrain(mx, box+distance, width-box-distance); |
| 37 | + my = constrain(my, box+distance, height-box-distance); |
| 38 | + fill(76); |
| 39 | + rect(box+esize, box+esize, box*3, box*3); |
| 40 | + fill(255); |
| 41 | + ellipse(mx, my, esize, esize); |
| 42 | +} |
0 commit comments