AAD

(Algoritmicly Aided Desing)

Sunday, June 15, 2014

#FLcreativecoding Week 2, 06 bubbles

/*
 * Creative Coding
 * Week 2, 06 - Moving Patterns 2
 * by Indae Hwang and Jon McCormack
 * Copyright (c) 2014 Monash University
 *
 * Similar to the previous sketch, this sketch draws a grid of oscillating circles. Each circle has a "lifetime"
 * over which it grows and changes intensity and opacity. At the end of each lifetime the circle begins again.
 * Pressing the left and right arrow keys changes the lifetime of all the circles globally.
 *
 modified by Marius Ivaskevicius
 mouse x controls offset by circle number
 mouse y controls different colored circles
 */
int speed=12;
int difference=15;
boolean solo=false;
void setup() {
  size(800,600);
  rectMode(CENTER);
  background(0);
}
void draw() {
  background(0);
  int num = 20;
  int margin = 0;
  float gutter = 0; //distance between each cell
  float cellsize = ( width - (2 * margin) - gutter * (num - 1) ) / (num - 1);
  int circleNumber = 0; // counter
  if(solo){
    movingCircle(width/2-100,height/2, cellsize, 0,false);
    movingCircle(width/2+100,height/2, cellsize, 0,true);
  }else{
    for (int i=0; i      for (int j=0; j        circleNumber = (i * num) + j; // different way to calculate the circle number from w2_04
        float tx = margin + cellsize * i + gutter * i;
        float ty = margin + cellsize * j + gutter * j;
        movingCircle(tx, ty, cellsize, circleNumber,true);
      }
    }
    for (int i=0; i      for (int j=0; j        circleNumber = (i * num) + j +difference; // different way to calculate the circle number from w2_04
        float tx = margin + cellsize * i + gutter * i;
        float ty = margin + cellsize * j + gutter * j;
        movingCircle(tx, ty, cellsize, circleNumber,false);
      }
    }
  }
  speed=int(lerp(2,50,float(mouseX)/float(width)));
  difference=int(lerp(1,1000,float(mouseY)/float(height)));
  //saveFrame("bubl####.jpg");
} //end of draw
void movingCircle(float x, float y, float size, int offset,boolean red) {
  float circlePeriod = (float)speed;
  float circleAge = (float)((frameCount + offset) % (int)circlePeriod) / circlePeriod;
  float circleSize = size * 2.0 * sin(circleAge * HALF_PI);
  strokeWeight(2);
  if(red){
    stroke(255,50,50, lerp(255, 0, circleAge));
    fill(lerp(50, 0, circleAge),lerp(50, 0, circleAge),lerp(128, 0, circleAge), lerp(120, 0, circleAge));
  }else{
    stroke(50,50,255, lerp(255, 0, circleAge));
    fill(lerp(128, 0, circleAge),lerp(50, 0, circleAge),lerp(50, 0, circleAge), lerp(120, 0, circleAge));
  }
  ellipse(x-size/2, y-size/2, circleSize, circleSize);
}
void keyPressed() {
  // right arrow -- increase frame_rate_value
  if (keyCode == RIGHT && speed < 60) {speed++;}
  // left arrow -- decrease frame_rate_value
  if ( keyCode == LEFT && speed > 1) {speed--;}
  if ( keyCode == UP) { difference++; }
  if ( keyCode == DOWN) { difference--; }
  println("speed:",speed,"difference",difference);
  if ( key == 's') {
    solo= !solo;
  }
}

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home