Created
September 29, 2016 05:43
-
-
Save CallumHoward/df7d0af8d61df57e151108663528e737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==== Fish ==== | |
public class Fish { | |
private int x; | |
private int y; | |
private color fishColor; | |
public Fish(int x, int y, color fishColor) { | |
this.x = x; | |
this.y = y; | |
this.fishColor = fishColor; | |
} | |
public Fish(int x, int y) { | |
this.x = x; | |
this.y = y; | |
this.fishColor = #000000; | |
} | |
public void drawFish() { | |
noStroke(); | |
fill(fishColor); // fish colour | |
// x1, y1, x2, y2, x3, y3 | |
triangle(x + 10, y + 10, x + 20, y + 5, x + 20, y + 15); | |
// center x, center y, width, height | |
ellipse(x + 10, y + 10, 12, 10); | |
moveFish(); | |
} | |
private void moveFish() { | |
this.x += random(-5, 5); | |
this.y += random(-5, 5); | |
} | |
} | |
// ==== start program ==== | |
int n_fish = 10; | |
Fish[] fishies = new Fish[n_fish]; | |
void setup() { | |
size(800, 600); | |
smooth(); | |
for (int i = 0; i < n_fish; i++) { | |
fishies[i] = new Fish(int(random(500)), int(random(500)), #5191AA); | |
} | |
} | |
void draw() { | |
background(#FFFFFF); | |
for (int i = 0; i < n_fish; i++) { | |
fishies[i].drawFish(); | |
} | |
delay(30); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment