First Processing Animation

screen-shot-2017-02-08-at-9-29-48-pm

Code:

//ellipse 1
int xPosition=10;
int xDirection=2;
int yPosition=10;
int yDirection=3;
//ellipse 2
int xPosition1=80;
int xDirection1=5;
int yPosition1=80;
int yDirection1=6;
//ellipse 3
int xPosition2=50;
int xDirection2=4;
int yPosition2=40;
int yDirection2=3;
//ellipse 4
int xPosition3=70;
int xDirection3=7;
int yPosition3=70;
int yDirection3=6;
//ellipse 5
int xPosition4=120;
int xDirection4=4;
int yPosition4=120;
int yDirection4=2;

PImage img;

void setup()
{
 size(500, 500);
 img = loadImage("yellow_new.jpg");
 noStroke();
 smooth();
 frameRate(80); 
}
//ellipse 1 animation
void draw()
{
 //background
 background(img);
 //animation start
 fill(#7683FF);
 noStroke();
 ellipse(xPosition, yPosition, 20, 20);
 xPosition=xPosition+xDirection;
 if(xPosition>width-10 || xPosition<10)
 {
 xDirection=xDirection*-1;
 }
 yPosition=yPosition+yDirection;
 if(yPosition>height-10 || yPosition<10)
 {
 yDirection=yDirection*-1;
 }
//ellipse 2 animation
 fill(#FF4D47);
 noStroke();
 ellipse(xPosition1, yPosition1, 25, 25);
 xPosition1=xPosition1+xDirection1;
 if(xPosition1>width-10 || xPosition1<10)
 {
 xDirection1=xDirection1*-1;
 }
 yPosition1=yPosition1+yDirection1;
 if(yPosition1>height-10 || yPosition1<10)
 {
 yDirection1=yDirection1*-1;
 }
//ellipse 3 animation
 fill(#32B25E);
 noStroke();
 ellipse(xPosition2, yPosition2, 15, 15);
 xPosition2=xPosition2+xDirection2;
 if(xPosition2>width-10 || xPosition2<10)
 {
 xDirection2=xDirection2*-1;
 }
 yPosition2=yPosition2+yDirection2;
 if(yPosition2>height-10 || yPosition2<10)
 {
 yDirection2=yDirection2*-1;
 }
//ellipse 4 animation
 fill(#B2327C);
 noStroke();
 ellipse(xPosition3, yPosition3, 22, 22);
 xPosition3=xPosition3+xDirection3;
 if(xPosition3>width-10 || xPosition3<10)
 {
 xDirection3=xDirection3*-1;
 }
 yPosition3=yPosition3+yDirection3;
 if(yPosition3>height-10 || yPosition3<10)
 {
 yDirection3=yDirection3*-1;
 }
//ellipse 5 animation
 fill(#FCBD46);
 noStroke();
 ellipse(xPosition4, yPosition4, 27, 27);
 xPosition4=xPosition4+xDirection4;
 if(xPosition4>width-10 || xPosition4<10)
 {
 xDirection4=xDirection4*-1;
 }
 yPosition4=yPosition4+yDirection4;
 if(yPosition4>height-10 || yPosition4<10)
 {
 yDirection4=yDirection4*-1;
 }
}

To download and run the code on your own system, click here: Download

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s