a-15 動き(4) タイマー

Sep 9, 2020

a-15 タイマー

millis()関数で時間に合わせて切替るアニメーション

int time1 = 1000;
int time2 = 5000;
float x = 0;
PImage img;

void setup(){
  size(500,250);
  img = loadImage( "cake.png" );
}

void draw(){
  background(251,187,186);
  int currentTime = millis();
  if(currentTime > time2){
    x -= 1;
  }else if(currentTime > time1){
    x += 2;
  }
  image(img,x,100);
}

Processingは、プログラムがスタートしてから、経過時間をミリ秒(千分の一秒)でカウントしている。1秒経過で1000、1分なら60000となる。この値を返すのが、millis()関数です。
上記は、1秒経過ごとにif内のコードが実行されるコードです。

#animation

#いったところmemo

#読書きろく