| Total Complexity | 12 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package example.animation; |
||
| 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 | } |
||
| 48 |