| Total Complexity | 6 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package example.shapes; |
||
| 6 | public abstract class ShapeTest extends AppWindow { |
||
| 7 | |||
| 8 | protected Drawable shape; |
||
| 9 | protected double dx, dy, width, height; |
||
| 10 | |||
| 11 | @Override |
||
| 12 | protected void setup() { |
||
| 13 | width = getDrawingPanel().getWidth() / 3.0; |
||
| 14 | height = getDrawingPanel().getHeight() / 3.0; |
||
| 15 | double heading = Math.random() * Math.PI * 2.0; |
||
| 16 | dx = Math.cos(heading); |
||
| 17 | dy = Math.sin(heading); |
||
| 18 | } |
||
| 19 | |||
| 20 | @Override |
||
| 21 | protected void loop() { |
||
| 22 | shape.translate(dx, dy); |
||
| 23 | if (shape.getX() < 0 || shape.getX() + shape.getWidth() > getDrawingPanel().getWidth()) { |
||
| 24 | dx = -dx; |
||
| 25 | } |
||
| 26 | if (shape.getY() < 0 || shape.getY() + shape.getHeight() > getDrawingPanel().getHeight()) { |
||
| 27 | dy = -dy; |
||
| 28 | } |
||
| 29 | sleep(10); |
||
| 30 | } |
||
| 32 |