AAD

(Algoritmicly Aided Desing)

Sunday, June 15, 2014

#FLcreativecoding Week 2, 05

/*
 * Creative Coding
 * Week 2, 05 - Moving Patterns 1
 * by Indae Hwang and Jon McCormack
 * Copyright (c) 2014 Monash University
 *
 * This sketch builds on the previous sketches, drawing shapes based on the
 * current framerate. The movement of individual shapes combine to create a
 * gestalt field of motion. Use the arrow keys on your keyboard to change the
 * frame rate.

 modified by Marius Ivaskevicius
 press [S] to wiev one element, again to see array
 press [UP][DOWN] to change rotation offset
 press [LEFT][RIGHT] to change rotation speed
 */

// variable used to store the current frame rate value
float speed=14;
float difference=16;
boolean solo=false;
void setup() {
  size(500, 500);
  rectMode(CENTER);
  background(0);
}
int eventNr=0;
int eventCounter=0;
int countToEvent=100;
int specialNode=0;
void draw() {
  fill(0,20);
  noStroke();
  rect(width/2,height/2,width,height);
  int num = 20;
  if(eventCounter++>countToEvent){
    eventCounter=0;
    specialNode=int(random(0,num*num));
    if(eventNr++>1){eventNr=0;}
  }
  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,height/2, cellsize, circleNumber,false);
  }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,specialNode>circleNumber);
      }
    }
  }
  //saveFrame("lsbr####.jpg");
} //end of draw
void movingCircle(float x, float y, float size, int circleNum,boolean special) {
  float finalAngle;
  finalAngle = frameCount + circleNum * difference;
  float speedMult=0.1;
  //the rotating angle for each tempX and tempY postion is affected by frameRate and angle;
  float tempX = x + (width *2) * sin(PI / speed * finalAngle*speedMult);
  float tempY = y + (width *2) * cos(PI / speed * finalAngle*speedMult);
  noFill();
  if(special){stroke(255,0,0);}
  else{stroke(255);}
  line(x, y, tempX, tempY);
}
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