-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyAnimation.java
More file actions
69 lines (62 loc) · 1.47 KB
/
MyAnimation.java
File metadata and controls
69 lines (62 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Laura Chevalier
* Intro to Computer Science with Professor Versoza
*/
import processing.core.PApplet;
import java.util.ArrayList;
import java.util.Random;
public class MyAnimation extends PApplet {
//animates a fish tank
Random random = new Random();
ArrayList<Bubble> bubbles = new ArrayList<>();
ArrayList<Fish> fish = new ArrayList<>();
ArrayList<Seaweed> seaweed = new ArrayList<>();
FishTank fishTank = new FishTank();
public static void main(String[] args) {
PApplet.main("DrawTank");
}
public void setup() {
size(500, 500);
for (int i = 0; i < fish.size(); i++) {
this.fish.get(i).render();
this.fish.get(i).move();
}
}
public void draw() {
background(10, 10, 100);
drawFish();
drawBubble();
drawSeaweed();
}
public void drawFish() {
for (int i = 0; i < fish.size(); i++) {
this.fish.get(i).render();
this.fish.get(i).move();
}
}
public void drawSeaweed() {
for (int i = 0; i < seaweed.size(); i++) {
this.seaweed.get(i).render();
this.seaweed.get(i).move();
}
}
public void drawBubble() {
for (int i = 0; i < bubbles.size(); i++) {
this.bubbles.get(i).render();
this.bubbles.get(i).move();
}
}
public void keyPressed() {
//draw a fish for f, a bubble for b, seaweed for s
if (key == 'f') {
Fish f = new Fish(this);
fish.add(f);
} else if (key == 's') {
Seaweed s = new Seaweed(this);
seaweed.add(s);
} else if (key == 'b') {
Bubble b = new Bubble(this);
bubbles.add(b);
}
}
}