Clock and Animation

edited October 2013 in Questions about Code

I'm trying to get an animation working so that at 11:11, the background image is becomes animated, and then goes back to normal afterward, i just want to get the first animation going since I have a total of three, but not even that is working. Please any help/advice would be appreciated, I need this by tomorrow :/ Here's my code:

PImage a;
PImage swirl;
int numFrames1 = 4;
int numFrames2 = 5;
int numFrames3= 3;
int frame= 0;
PImage[] boy = new PImage[numFrames1];
PImage[] star =new PImage[numFrames2];
PImage[] sit =new PImage[numFrames3];
void setup() {
  size(500, 500);
  swirl =loadImage("swirl2.png");
  a = loadImage("at rest.png");
  frameRate(24);
  boy[0] = loadImage("1.png");//jumpinh 1
  boy[1] = loadImage("2.png");//jumping 2
  boy[2] = loadImage("3.png");//jumping 3
  boy[3] = loadImage("4.png");//jumping 4
  star[0] = loadImage("5.png");//shooting star 1
  star[1] = loadImage("6.png");//shooting star 2
  star[2] = loadImage("7.png");//shooting star 3
  star[3] = loadImage("8.png");//shooting star 4
  star[4] = loadImage("9.png");//shooting star 5
  sit[0] = loadImage("10.png");//sitdown 1
  sit[1] = loadImage("11.png");//sitdown 2
  sit[2] = loadImage("12.png");//sitdown 3

  pushMatrix();
  translate(width/2, height/2);

  smooth();

  ellipseMode(RADIUS);
  stroke(0);
}


void draw() {
//  noLoop();
//  image(a, 0, 0);
//
//  loop();
  image(swirl, 400, 110);

  noStroke();

//animation bs
//first animation kis jumping up and down
//get kid to do this at 11:11 somehow...
// is thE kid standing up, oh look a star -_-
   float h = hour();
  float s = second();
  float m = minute();

  if (h==8 && m==46) { 
  frame = (frame+1) % numFrames1;  // Use % to cycle through frames


  image(boy[(frame) % numFrames1], 0, 0);
}
  else {
  image(a, 0, 0);
}///whyyyyyyy

s = map(second(), 0, 60, 0, radians(360)) - radians(90);
m = map(minute(), 0, 60, 0, radians(360)) - radians(90);
h = map(hour() % 12, 0, 12, 0, radians(360)) - radians(90);

stroke(175, 205, 255);
strokeWeight(1);
line(400, 110, cos(s) * 65+ 400, sin(s) * 65+ 110);

image(swirl, 200, 50, sin(s) * 65+ 400, cos(s) * 65+ 110);
println();
strokeWeight(2);
line(400, 110, cos(m) * 67.5 +400, sin(m) * 67.5+ 110);
strokeWeight(3);
line(400, 110, cos(h) * 50 +400, sin(h) * 50+ 110);
//    for ( int x= 0; x< boy.length; x++) {
//      boy[x] = loadImage( x + ".png");
//    }
}
Tagged:

Answers

  • "not even that is working"
    What is "not working"? Do you have errors? Nothing happens?

    We don't have your images, so it is hard to run it to see the problem... The overall logic seems OK, but you know, Processing already has a global variable named frameCount, no need to maintain your own.

  • edited October 2013

    I made my own images, and it works...

    int numFrames1 = 4;
    
    PImage a;
    PImage[] boy = new PImage[numFrames1];
    
    void setup() {
      size(500, 500);
      frameRate(24);
      for (int i = 0; i < numFrames1; i++)
      {
        PGraphics b = createGraphics(200, 200);
        b.beginDraw();
        b.fill(#0000FF);
        b.textSize(100);
        b.text(i, 100, 100);
        b.endDraw();
        boy[i] = b.get();
      }
      PGraphics aa = createGraphics(width, height);
      aa.beginDraw();
      aa.ellipse(width / 2, height / 2, 400, 400);
      aa.endDraw();
      a = aa.get();
    
      pushMatrix();
      translate(width/2, height/2);
    
      smooth();
    
      ellipseMode(RADIUS);
      stroke(0);
    }
    
    
    void draw() {
      //  image(swirl, 400, 110);
      background(255);
    
      noStroke();
    
      //animation bs
      //first animation kis jumping up and down
      //get kid to do this at 11:11 somehow...
      // is thE kid standing up, oh look a star -_-
      float h = hour();
      float s = second();
      float m = minute();
    
      if (h == 7 && m == 24) {
        int frame = frameCount % numFrames1;  // Use % to cycle through frames
    
    
        image(boy[frame], 0, 0);
      }
      else {
        image(a, 0, 0);
      }///whyyyyyyy
    
      s = map(second(), 0, 60, 0, radians(360)) - radians(90);
      m = map(minute(), 0, 60, 0, radians(360)) - radians(90);
      h = map(hour() % 12, 0, 12, 0, radians(360)) - radians(90);
    
      stroke(175, 205, 255);
      strokeWeight(1);
      line(400, 110, cos(s) * 65+ 400, sin(s) * 65+ 110);
    
      //image(swirl, 200, 50, sin(s) * 65+ 400, cos(s) * 65+ 110);
      strokeWeight(2);
      line(400, 110, cos(m) * 67.5 +400, sin(m) * 67.5+ 110);
      strokeWeight(3);
      line(400, 110, cos(h) * 50 +400, sin(h) * 50+ 110);
    }
    

    But, thinking about this, you draw a swirl image after the boy image. If the image is large, it probably hides the boy...

  • ugh, didn't realize that that was already a global variable, i was following the skeleton of a program that did work and saw that, they did that probably made things worse huh...It had worked before but the animation never changed, but it does now Thanks for the very last minute help! Sorry I couldn't answer earlier.

Sign In or Register to comment.