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

example.animation.Animation   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
C loop() 0 23 9
A setup() 0 5 2
A main(String[]) 0 2 1
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