Bird Landing
From Physical Programming
This is the very starting work of flocking bird project. We start from drawing from scratch which is having just birds flying. We used the math equation/ coding from an example in the software itself (examples>topics>motions>moving on curves) to put a landing motion. Nothing is random here at this stage. It is just an animation, having indication of where it starts and where it would end.
int numFrames = 3;
int frame = 0;
PImage[] images1 = new PImage[numFrames];
PImage[] images2 = new PImage[numFrames];
PImage bg;
float[] beginX = {400,10,500,20,663}; // Initial x-coordinate
float[] beginY = {-10,-10,-10,400,250}; // Initial y-coordinate
float[] endX = {150,250,300,50,370}; // Final x-coordinate
float[] endY = {200,200,400,300,320}; // Final y-coordinate
float[] distX ={0,0,0,0,0}; // X-axis distance to move
float[] distY ={0,0,0,0,0}; // Y-axis distance to move
float exponent = 4; // Determines the curve
float[] x = {0,0,0,0,0}; // Current x-coordinate
float[] y = {0,0,0,0,0}; // Current y-coordinate
float step = 0.01; // Size of each step along the path
float[] pct = {0,0,0,0,0};
int i;
/*There are two set of images of bird motion. Images1 are images of bird facing to the right, and images2 are facing to the left.*/
void setup(){
frameRate(17);
size(663,500);
//background(255,255,255);
for(i=0;i<beginX.length;i++)
{
distX[i] = endX[i] - beginX[i];
distY[i] = endY[i] - beginY[i];
}
bg = loadImage("Black_Tree.gif");
images1[0] = loadImage("0001.gif");
images1[1] = loadImage("0002.gif");
images1[2] = loadImage("0003.gif");
images2[0] = loadImage("0011.gif");
images2[1] = loadImage("0021.gif");
images2[2] = loadImage("0031.gif");
}
/*The line that we put the comment on is defining a mid vertical line of the tree, to put proper images of bird facing to the tree. Otherwise, it would fly backward.*/
void draw(){
background(255,255,255); image(bg,0,200); //line(235,0,235,500);
for(i=0;i<beginX.length;i++)
{
pct[i] += step;
if (pct[i] < 1.0)
{
x[i] = beginX[i] + (pct[i] * distX[i]);
y[i] = beginY[i] + (pow(pct[i], exponent) * distY[i]);
}
else
{
endX[i]=x[i];
endY[i]=y[i];
}
if(beginX[i]<235)
{
if(x[i]==endX[i] && y[i]==endY[i])
{
image(images1[2], endX[i], endY[i]);
}
else
{
image(images1[frame], x[i], y[i]);
}
}
else
{
if(x[i]==endX[i] && y[i]==endY[i])
{
image(images2[2], endX[i], endY[i]);
}
else
{
image(images2[frame], x[i], y[i]);
}
}
}
frame = (frame+1)%numFrames;
}

