Last active
August 29, 2015 14:09
-
-
Save maydemir/58cf016aacfa802f46f4 to your computer and use it in GitHub Desktop.
Water and Sky 2- Escher
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
PImage birdImg; | |
PImage fishImg; | |
PImage seaImg; | |
PImage skyImg; | |
PImage bird1; | |
PImage bird2; | |
PImage bird3; | |
PImage fish1; | |
float x=0; | |
int movementSpeed = 2; | |
PGraphics overlay; | |
BirdFlock flock; | |
void setup() { | |
size(640,640); | |
overlay = createGraphics(width,height); | |
birdImg = loadImage("skyAndWater.jpg"); | |
fishImg = loadImage("fish only.jpg"); | |
seaImg = loadImage("sea.jpg"); | |
bird1 = loadImage("bird1.png"); | |
bird2 = loadImage("bird2.png"); | |
bird3 = loadImage("bird3.png"); | |
fish1 = loadImage("fish1.png"); | |
skyImg = loadImage("sky.png"); | |
flock = new BirdFlock(overlay); | |
flock.setInit(0); //Initial delay in milliseconds before showing the first bird, default is 1000 milliseconds | |
flock.interval = 600; //Delay between birds appearing, default is 1500 milliseconds | |
flock.createRow(bird1,3); //create a row of 3 birds using image bird1 | |
flock.createRow(bird2,4); //create a row of 2 birds using image bird2 | |
flock.createRow(bird3,3); | |
overlay.beginDraw(); | |
overlay.noStroke(); | |
// Display at half opacity | |
overlay.image(birdImg,0,0); | |
//overlay.image(fishImg, 0, height/2); | |
overlay.endDraw(); | |
} | |
void draw() { | |
noStroke(); | |
tint(255,255); | |
//fill(255); | |
//rect(0,0,width,height); | |
//fill(50,200,220); | |
//rect(0,0,width,height/2);//draw blue rectangle for the sky, replace with and 'image(skyImg,0,0);' if you want to use an image instead | |
image(seaImg, 0, height/2); | |
image(skyImg, 0, 0); | |
flock.update(); //update the position of the birds | |
x+= movementSpeed; //move the escher image to the right | |
tint(255, 127); | |
image(overlay,x/2,0); | |
image(fish1, x,300); | |
if (x >= width) { //if the image is off the right side of the screen, reset it | |
x=-width; | |
flock.reset(); | |
} | |
} | |
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
class Bird { | |
int xPos; | |
int yPos; | |
int delay; | |
boolean displayed; | |
PImage sprite; | |
Bird(PImage sprite, int x, int y, int appearDelay){ | |
xPos = x; | |
yPos = y; | |
delay = appearDelay; | |
displayed = false; | |
this.sprite = sprite; | |
} | |
void update(int time){ | |
if(time>delay){ | |
//displayed = true; | |
overlay.beginDraw(); | |
overlay.image(sprite,xPos,yPos); | |
overlay.endDraw(); | |
} | |
} | |
void reset(){ | |
//displayed = false; | |
} | |
} |
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
class BirdFlock { | |
int initDelay = 1000; | |
int interval = 1500; | |
int curDelay; | |
int startX = 100; | |
int startY = (height/2)-125; | |
int xShift = 158; | |
int yShift = 70; | |
int rowOffset = (xShift/2)-5; | |
int xPos; | |
int yPos; | |
int row = 0; | |
ArrayList<Bird> birds; | |
PGraphics overlay; | |
BirdFlock(PGraphics layer){ | |
this(layer, 2000, 1500); | |
} | |
BirdFlock(PGraphics layer, int delay, int intv){ | |
initDelay = delay; | |
interval = intv; | |
overlay = layer; | |
birds = new ArrayList<Bird>(); | |
curDelay = initDelay; | |
xPos = startX; | |
yPos = startY; | |
} | |
void addBird(PImage sprite){ | |
Bird newBird = new Bird(sprite,xPos,yPos,curDelay); | |
curDelay += interval; | |
xPos += xShift; | |
birds.add(newBird); | |
} | |
void newRow(){ | |
row++; | |
xPos = startX+(rowOffset*row); | |
yPos -= yShift; | |
} | |
void createRow(PImage sprite, int count){ | |
for(int i=0;i<count;i++){ | |
addBird(sprite); | |
} | |
newRow(); | |
} | |
void update(){ | |
overlay.beginDraw(); | |
//overlay.tint(255,255); | |
overlay.fill(255); | |
overlay.rect(0,0,width,height); | |
overlay.noStroke(); | |
overlay.tint(255,220); | |
overlay.image(birdImg,0,0); | |
overlay.endDraw(); | |
int time = millis(); | |
for(Bird bird : birds){ | |
bird.update(time); | |
} | |
} | |
void setInit(int init){ | |
initDelay = init; | |
curDelay = initDelay; | |
} | |
void reset(){ | |
curDelay = initDelay+millis(); | |
for(Bird b: birds){ | |
b.reset(); | |
b.delay = curDelay; | |
curDelay+=interval; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment