Passed
Push — master ( 8a17de...4e3e47 )
by Seth
03:37
created

example.animation.Animation.loop()   C

Complexity

Conditions 9

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 16
c 1
b 0
f 0
dl 0
loc 23
rs 6.6666
1
package example.animation;
2
3
import org.gannacademy.cdf.graphics.ui.AppWindow;
4
5
import java.util.ArrayList;
6
import java.util.List;
7
8
public class Animation extends AppWindow {
9
    List<Bubble> bubbles;
10
11
    @Override
12
    protected void setup() {
13
        bubbles = new ArrayList<>();
14
        for (int i = 0; i < 50; i++) {
15
            bubbles.add(new Bubble(getDrawingPanel()));
16
        }
17
    }
18
19
    @Override
20
    protected void loop() {
21
        long start = System.currentTimeMillis();
22
        for (Bubble b : bubbles) {
23
            b.step();
24
        }
25
26
        List<Bubble> trash = new ArrayList<>();
27
        for (Bubble b : bubbles) {
28
            if (!trash.contains(b)) {
29
                for (Bubble c : bubbles) {
30
                    if (b != c && !trash.contains(c) && b.intersects(c)) {
31
                        b.absorb(c);
32
                        trash.add(c);
33
                    }
34
                }
35
            }
36
        }
37
        for (Bubble b : trash) {
38
            bubbles.remove(b);
39
            b.close();
40
        }
41
        sleep(50 - (System.currentTimeMillis() - start));
42
    }
43
44
    public static void main(String[] args) {
45
        new Animation();
46
    }
47
}
48