Advertisement
Guest User

Untitled

a guest
Sep 8th, 2014
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ArrayList<Cube> cubes;
  2.  
  3. void setup() {
  4.   size(500, 500, P3D);
  5.   smooth(6);
  6.   frameRate(30);
  7.  
  8.   cubes = new ArrayList();
  9.   int cubeNum = 0;
  10.   for (int i = 0; i < 10; i++) {
  11.     for (int j = 0; j < 15; j++) {
  12.       cubes.add(new Cube(50*i+25, 35*j+10, 35*j, cubeNum));
  13.       cubeNum ++;
  14.     }
  15.   }
  16.  
  17.   for (int i = 0; i < cubes.size (); i++) {
  18.     Cube c = (Cube) cubes.get(i);
  19.     c.timeStampAnim = millis();
  20.     c.timeStampDelay = millis();
  21.   }
  22. }
  23.  
  24. void draw() {
  25.   background(25);
  26.  
  27.   //  camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, mouseY, 0, 0, 1, 0);
  28.   camera(width/2.0, height/2.0, 675, width/2.0, height/2, 0, 0, 1, 0);
  29.   println(mouseX*3);
  30.  
  31.   for (int i = 0; i < cubes.size (); i++) {
  32.     Cube c = (Cube) cubes.get(i);
  33.     c.draw();
  34.   }
  35. }
  36.  
  37. class Cube {
  38.   // timer interne de l'animation
  39.  float timeStampAnim, intervalAnim;
  40.  boolean beginTimerAnim;
  41.  // timer pour activer le timer de l'animat selon le delai entré en param
  42.   float timeStampDelay, intervalDelay;
  43.   boolean  animate;
  44.   float posX, posY, angleY, posZ;
  45.   int cubeNum;
  46.   Cube(float posX, float posY, float posZ, float delay) {
  47.     // timer interne de l'animation
  48.    timeStampAnim = millis();
  49.    intervalAnim = 5000; // chaque 5 secondes, l'animation joue (si elle doit le faire)
  50.     beginTimerAnim = false;
  51.  
  52.     // timer pour activer le timer de l'animat selon le delai entré en param
  53.    timeStampDelay = cubeNum * 100;
  54.    intervalDelay = delay * 50;
  55.  
  56.    animate = false;
  57.  
  58.    this.posX = posX;
  59.    this.posY = posY;
  60.    this.posZ = posY;
  61.  
  62.  
  63.    angleY = 45;
  64.  
  65.    // println(intervalDelay);
  66.  }
  67.  
  68.  void draw() {
  69.    pushMatrix();
  70.    //    posZ = mouseX;
  71.    translate(posX, posY, posZ);
  72.    //rotateX(radians(-45));
  73.    rotateY(radians(angleY));
  74.    stroke(25);
  75.    strokeWeight(1.5);
  76.    box(35);
  77.    popMatrix();
  78.  
  79.    if (animate) {
  80.      if (angleY < 135) {
  81.        angleY+=5;
  82.      } else { // >=
  83.        animate = false;
  84.        angleY = 45;
  85.      }
  86.    }
  87.    if (beginTimerAnim) {
  88.      if (millis() - timeStampAnim >= intervalAnim) {
  89.        animate = true;
  90.        timeStampAnim = timeStampAnim + intervalAnim;
  91.      }
  92.    }
  93.    if (!beginTimerAnim) {
  94.      if (millis() - timeStampDelay >= intervalDelay) {
  95.        beginTimerAnim = true;
  96.        timeStampAnim = millis();
  97.      }
  98.    }
  99.  }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement