jeudi 26 novembre 2015

Can I Use Processing 3 For Loop with If Statement for Animation Frames?

Script runs in Processing 3.0.1 editor. I want to achieve:

  • continuous loop
  • maintain for loop's value of 10 (where each new set of triangles in for loop replaces each oldest set making the animation appear as a flaming meteor)

Can I accomplish this with a simple if statement, or do I need to create an array, or...? Open to suggestions.

void setup() {
  size(504, 282);
  background(0);
}

void draw() {
  color from = color(255, 0, 0, 50);
  color to   = color(255, 255, 0, 300);
  color a = lerpColor(from, to, .33);
  color b = lerpColor(from, to, .66);
  for (int i=0; i<20; i++) {
      // if statement
      // 1st Stage
      float a1=random(0, 84);
      float b1=random(0, 47);
      float c1=random(84, 168);
      float d1=random(47, 94);
      float e1=random(168, 252);
      float f1=random(94, 141);
      // 2nd Stage
      float a2=random(84, 168);
      float b2=random(47, 94);
      float c2=random(168, 252);
      float d2=random(94, 141);
      float e2=random(252, 336);
      float f2=random(141, 188);
      // 3rd Stage
      float a3=random(168, 252);
      float b3=random(94, 141);
      float c3=random(252, 336);
      float d3=random(141, 188);
      float e3=random(336, 420);
      float f3=random(188, 235);
      // 4th Stage
      float a4=random(252, 336);
      float b4=random(141, 188);
      float c4=random(336, 420);
      float d4=random(188, 235);
      float e4=random(420, 504);
      float f4=random(235, 282);
      noStroke();
      fill(from);
      triangle(a1, b1, c1, d1, e1, f1);
      fill(a);
      triangle(a2, b2, c2, d2, e2, f2);
      fill(b);
      triangle(a3, b3, c3, d3, e3, f3);
      fill(to);
      triangle(a4, b4, c4, d4, e4, f4);

  }
  //saveFrame("####.png");
}

Aucun commentaire:

Enregistrer un commentaire