Processing Flipbook Code

General posts about art, interactivity, programming - Processing, OpenFrameworks, Arduino, Pure Data, Max/MSP, etc

Processing Flipbook Code

Postby BenChang » Fri Nov 22, 2013 5:29 pm

Code: Select all
PImage p1;
PImage p2;

int currentFrame;

float rate;  // framerate you want in frames per second, like 12
float delay; // delay between frames - 1/framerate, like 1/12
float lastTime; // use to tell how much time has elapsed

void setup ()
{
   size(200,200);
   p1=loadImage("1.png");
   p2=loadImage("2.png");
   currentFrame = 1;
   
   rate=12.0;
   delay = (1/rate) * 1000;  // in milliseconds
   lastTime = millis(); 
   frameRate=60;
}

void draw ()
{
  // get current time, see if elapsed time is greater than the delay amount,
  // if so, flip to the next animation frame.

  float t=millis();
  if (t-lastTime > delay)
  {
    currentFrame++;
    if (currentFrame > 2)
       currentFrame=1;
       
    // store the current time to compare against for the next delay
    lastTime = t;
  }
 
   
 
  if (currentFrame==1)
  {
     image(p1,0,0);
  }
  else if (currentFrame==2)
  {
     image(p2,0,0);
  }

}

Attachments
flipbook.zip
(4.4 KiB) Downloaded 445 times
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Return to Interactive Art && Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron