Passed
Push — master ( dd7741...68adbd )
by Seth
04:41
created

example.shapes.ShapeTest.loop()   A

Complexity

Conditions 5

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 10
rs 9.3333
1
package example.shapes;
2
3
import org.gannacademy.cdf.graphics.Drawable;
4
import org.gannacademy.cdf.graphics.ui.AppWindow;
5
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
    }
31
}
32