AAD

(Algoritmicly Aided Desing)

Wednesday, June 18, 2014

#FLcreativecoding Week 3, 06 FloatScreen

Implemented FloatScreen object which holds all pixel colors in float values.
Also has functions to draw rectangles and lines with alpha channels.
(alpha is in range 0 to 1)
Its very slow, can be used only to render images for animation.
Also does not run on openprocessing. Sorry. :( I don't know why.
code

Tuesday, June 17, 2014

#FLcreativecoding Week 3, 04 double pendulum

interactive
move mouse around to get different shapes
click mouse to add color for a short time
code

Monday, June 16, 2014

#FLcreativecoding Week 3, 02 rainbow invaders

Appearently blogger thinks I am posting some malisious code and deletes some parts of it. Sorry for that. Now the code will be in openprocessing .

#FLcreativecoding Week 3, 01 hyperspace transition

/*
 * Creative Coding
 * Week 3, 01 - using map() to map mouse co-ordinates to background colour
 * by Indae Hwang
 * Copyright (c) 2014 Monash University
 *
 * This program allows you to change the background color.
 * Press and hold 'left mouse button' to change color.

 modified by Marius Ivaskevicius
 used HSB color model
 mouseX mapped to H
 mouseY mapped to S
 B is always 255
 special feature "hyperspace transition"
 */
float h;
float s;
float b;
void setup() {
  colorMode(HSB);
  size(500, 500);
  // initialise the colour variables
  h = 0;
  s = 0;
  b = 0;
  background(0);
  noStroke();
  rectMode(CENTER);
}
float speed=1.1;
int skipFrameCounter=0;
int skipFrames=10;
boolean record=false; //enable this to record every 10th frame to files
void draw() {
  fill(h,s,b);
  rect(mouseX,mouseY,20,20);
  PImage c = get();
  tint(255,100);
  image(c, mouseX-mouseX*speed,mouseY-mouseY*speed, width*speed,height*speed);
  h = map(mouseX, 0, width, 0, 255);
  s = map(mouseY, 0, height, 0, 255);
  b = 255;
  if (mousePressed) {
    println("red: "+h+", green: "+s+", blue: "+b);
  }
  if(skipFrameCounter++>skipFrames && record){
    skipFrameCounter=0;
    saveFrame("hs####.jpg");
  }
}

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;
  }
}

#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;
  }
}

#FLcreativecoding Week 2, 04 - The Clocks

/*
 * Creative Coding
 * Week 2, 04 - The Clocks
completely rec0ded by Marius Ivaskevicius
special feature morphing clock faces and arrows
 */
int detail=48;
int eventCouter=0;
int eventDelay=100;
class Pin{
  float pinX=0;
  float pinY=0;
  int desX=0;
  int desY=0;
  int speed=10;
  Pin(float x,float y){
    this.pinX=x;
    this.pinY=y;
    this.desX=int(this.pinX);
    this.desY=int(this.pinY);
  }
  void go(int x,int y){
    this.desX=x;
    this.desY=y;
  }
  float getX(){
    this.pinX-=(this.pinX-this.desX)/this.speed;
    return this.pinX;
  }
  float getY(){return this.pinY-=(this.pinY-this.desY)/this.speed;}
}
class Face{
  int x;
  int y;
  int size=50;
  int form=0;
  Pin[] pins;
  float rotation=0;
  Face(int x,int y,int shape){
    this.x=x;
    this.y=y;
    this.pins= new Pin[detail];
    for(int i=0;i      this.pins[i]=new Pin(int(this.x+sin(i*TWO_PI/detail)*this.size),
                          int(this.y+cos(i*TWO_PI/detail)*this.size));
    }
  }
  void nclower(int n){
    for(int i=0;i      this.pins[i].go(this.x+int(sin(i*TWO_PI/detail+this.rotation)*(this.size + cos(i*TWO_PI/detail*n+this.rotation)*this.size/2)*0.6),
                      this.y+int(cos(i*TWO_PI/detail+this.rotation)*(this.size + cos(i*TWO_PI/detail*n+this.rotation)*this.size/2)*0.6));
    }
  }
  void turn(float ang){
    this.rotation=ang;
    transformUpdate();
  }
  void transform(int to){
    this.form=to;
    transformUpdate();
  }
  void transformUpdate(){
    switch(this.form){
      case 0://circle
        for(int i=0;i          this.pins[i].go(int(this.x+sin(i*TWO_PI/detail)*this.size),
                          int(this.y+cos(i*TWO_PI/detail)*this.size));
        }
      break;
      case 1://triangle
        int ax=int(this.x+sin(TWO_PI/6.0)*this.size*1.2);
        int ay=int(this.y+cos(TWO_PI/6.0)*this.size*1.2);
        int bx=int(this.x+sin(TWO_PI/6.0*3.0)*this.size*1.2);
        int by=int(this.y+cos(TWO_PI/6.0*3.0)*this.size*1.2);
        int cx=int(this.x+sin(TWO_PI/6.0*5.0)*this.size*1.2);
        int cy=int(this.y+cos(TWO_PI/6.0*5.0)*this.size*1.2);
        for(int i=0;i          this.pins[i].go(ax,ay);
        }
        for(int i=detail/3;i          this.pins[i].go(bx,by);
        }
        for(int i=detail/3*2;i          this.pins[i].go(cx,cy);
        }
      break;
      case 2://square
        int dx=int(this.x+sin(TWO_PI/8.0)*this.size*1.2);
        int dy=int(this.y+cos(TWO_PI/8.0)*this.size*1.2);
        int ex=int(this.x+sin(TWO_PI/8.0*3.0)*this.size*1.2);
        int ey=int(this.y+cos(TWO_PI/8.0*3.0)*this.size*1.2);
        int fx=int(this.x+sin(TWO_PI/8.0*5.0)*this.size*1.2);
        int fy=int(this.y+cos(TWO_PI/8.0*5.0)*this.size*1.2);
        int gx=int(this.x+sin(TWO_PI/8.0*7.0)*this.size*1.2);
        int gy=int(this.y+cos(TWO_PI/8.0*7.0)*this.size*1.2);
        for(int i=0;i          this.pins[i].go(dx,dy);
        }
        for(int i=detail/4;i          this.pins[i].go(ex,fy);
        }
        for(int i=detail/4*2;i          this.pins[i].go(fx,fy);
        }

        for(int i=detail/4*3;i          this.pins[i].go(gx,gy);
        }
      break;
      case 3://nclower 2
        nclower(2);
      break;
      case 4://nclower 3
        nclower(3);
      break;
      case 5://nclower 4
        nclower(4);
      break;
    }
  }
  void update(){
    int j=1;
    beginShape();
    for(int i=0;i    endShape(CLOSE);
  }
}
Face[] faces;
Face[] arrows;
void setup() {
  faces=new Face[25];
  for(int i=0;i<5 br="" i="">    for(int j=0;j<5 br="" j="">      faces[i*5+j]=new Face(j*55+40,i*55+40,0);
      faces[i*5+j].transform(0);
    }
  }
  arrows=new Face[25];
  for(int i=0;i<5 br="" i="">    for(int j=0;j<5 br="" j="">      arrows[i*5+j]=new Face(j*55+40,i*55+40,0);
      arrows[i*5+j].transform(2);
    }
  }
  size(600, 600);
  background(180);
  rectMode(CENTER);
}
int shapeA=2;
int shapeB=2;
void draw() {
  eventCouter++;
  if(eventCouter>eventDelay){
    eventCouter=0;
    shapeA=int(random(0,3));
    shapeB=int(random(0,3));
    for(int i=0;i<25 br="" i="">      if(i%2==0){faces[i].transform(shapeA);}
      else{faces[i].transform(shapeB);}
    }
    shapeA=int(random(3,6));
    for(int i=0;i<25 arrows="" br="" i="" shapea="" transform="">  }
  background(206,67,0);
  strokeWeight(2);
  int num = 5;
  for (int i=0; i    for (int j=0; j      stroke(244,80,0);
      fill(255,128,64);
      faces[i*5+j].update();
      arrows[i*5+j].turn(((i+1)*5+j)* TWO_PI * millis() / 60000.0);
      fill(255,155,64);
      stroke(255,179,64);
      arrows[i*5+j].update();
    }
  }
}//end of draw

Saturday, June 14, 2014

#FLcreativecoding interpretation of Vera Molnar’s 25 Squares

/*
 * Creative Coding
 * Week 2, 03 - n squares
completely rec0det by Marius Ivaskevicius
interpretation of Vera Molnar’s 25 Squares
interactice! needs user imput to reaveal itself
click mouse on the window
x coordinate controls the number of squares
y coordinate controls the distribution between two colors
 */

int minSqrSize=10;
class Square{
  float xPos;
  float yPos;
  int desX;
  int desY;
  float size=minSqrSize;
  float desSize= size;
  float desH=10;
  float h=10;
  int speed=2;//record2 else10-----------------------------------------------------------------------------------
  boolean isFalling=false;
  int fallSpeed=0;
  boolean isReadied=false;
  boolean color2=false;
  float r=0;
  float g=0;
  float b=0;
  int desR=102;
  int desG=54;
  int desB=112;

  void teleport(int x,int y){
    this.isFalling=false;
    this.xPos=this.desX=x;
    this.yPos=this.desY=y;
  }
  void target(int x,int y){
    this.desX=x;
    this.desY=y;
  }
  void plotShadow(){
    fill(10,10,0,50); // shadow
    rect(this.xPos+this.h,
         this.yPos+this.h,
         this.size,
         this.size);
  }
  void plotBody(){
    if(color2){
      //fill(255,136,4,200); // rectangle
      fill(80,255,120,200); // rectangle
      fill(r,g,b,200); // rectangle
    }else{
      fill(255,50,0,230); // rectangle
      fill(r,g,b,230); // rectangle
    }
    rect(this.xPos,
         this.yPos,
         this.size,
         this.size);
  }
  void update(){
    this.xPos-=(this.xPos-this.desX)/this.speed;
    if(this.isFalling){
      if(this.yPos      this.fallSpeed+=10;
      this.yPos+=this.fallSpeed;
    }else{
      this.yPos-=(this.yPos-this.desY)/this.speed;
    }
    this.size-=(this.size-this.desSize)/this.speed;
    this.h-=(this.h-this.desH)/this.speed;
    this.r-=(this.r-this.desR)/this.speed;
    this.g-=(this.g-this.desG)/this.speed;
    this.b-=(this.b-this.desB)/this.speed;
  }
  void fall(){
    this.isFalling=true;
    this.isReadied=false;
    this.fallSpeed=0;
    this.desX+=random(-500,500);
  }
  void ready(){this.isReadied=true;}
  boolean isReady(){return this.isReadied;}
  boolean isFallen(){return this.isFalling;}
  void descent(){
    this.isFalling=false;
    this.isReadied=false;
    this.yPos=this.size*-1;
    //if(random(10)>8){this.color2=true;}else{this.color2=false;}
  }
  void grow(int size){
    this.desSize=size;
  }
  void rise(int goH){
    this.desH=goH;
  }
  void paint(int dist){
    if(random(100)>dist){
      this.desR=80;
      this.desG=255;
      this.desB=120;
    }else{
      this.desR=255;
      this.desG=50;
      this.desB=0;
    }
  }
  void nudge(){
    this.desX+=int(random(minSqrSize*-1,minSqrSize));
    this.desY+=random(minSqrSize*-1,minSqrSize);
    this.desH+=random(minSqrSize*-1,minSqrSize);
    if(this.desH<2 this.desh="2;}<br">   
  }
}
int eventCounter=0;
int eventCounterTot=12;//record5 else100 ------------------------------------------------------------------------
int eventShortCounter=eventCounterTot-6;
int eventNumber=0;

int sqrCountX;
int sqrCountY;
int sqrTot;
int oldSqrTot;
//int[] arr= new int[10];
//arr[1]=0;
Square[] squares;

int curSqrCountX;
int curSqrCountY;
int stepX;
int stepY;
int curSqrTot;
void newScale(int size){
  curSqrCountX=(width/(size+minSqrSize))-1;
  curSqrCountY=(height/(size+minSqrSize))-1;
  curSqrTot=curSqrCountX*curSqrCountY;
  //oldSqrTot=curSqrTot;
  stepX=width/(curSqrCountX+1);
  stepY=height/(curSqrCountY+1);
}
void setup() {
  randomSeed(hour()+minute()+second()+millis());
  size(600, 600);
  sqrCountX=width/(minSqrSize*2)-1;
  sqrCountY=height/(minSqrSize*2)-1;
  sqrTot=sqrCountX*sqrCountY;
  newScale(minSqrSize);
  squares= new Square[sqrTot];
  int curY=0;
  for(int i=0;i      squares[i]=new Square();
      if((i%sqrCountX)==0){curY++;}
      squares[i].teleport((i%sqrCountX)*stepX+stepX,curY*stepY);
  }
  rectMode(CENTER);
  noStroke();
  frameRate(10);//record ------------------------------------------------------------------------------------------
 
}
void shuffle(){
  Square temp;
  int pick;
   for(int i=0; i       temp = squares[i];
       pick  = int(random(squares.length));
       squares[i] = squares[pick];
       squares[pick]= temp;
     }
}
void sort(){
  Square[] tmpSquares;
  tmpSquares= new Square[sqrTot];
  int j=0;
  int f=sqrTot-1;
  for(int i=0;i    if(squares[i].isFallen() && !squares[i].isReady()){tmpSquares[f--]=squares[i];}
    else{tmpSquares[j++]=squares[i];}
  }
  squares=tmpSquares;
}
int newSize;
boolean userInput=false;
int userSize=minSqrSize;
int userDistrubution=50;
void draw() {
    background(102,54,112); // clear the screen
    for(int i=0;i    for(int i=0;i    for(int i=0;i    if(++eventCounter>=eventCounterTot){ //------( event !!! )-----
      if(eventNumber==0){
        if(userInput){
           
            oldSqrTot=curSqrTot;
            newSize=userSize;
            newScale(newSize);
            if(oldSqrTot>curSqrTot){
              eventNumber=1;//drop
            }else{
              eventNumber=3;//grow
            }
        }else{
          eventCounter=0;
          for(int i=0;i        }
      }
      switch(eventNumber){
        case 1://drop
          shuffle();
          sort();
          int toDrop=sqrTot-curSqrTot;
          for(int i=curSqrTot;i          eventCounter=eventShortCounter;
          eventNumber=2;//move
          break;
        case 2://move
          eventCounter=eventShortCounter;
          for(int i=oldSqrTot;i          shuffle();
          sort();
          int curY=0;
          for(int i=0;i            if(i%curSqrCountX==0){curY++;}
            squares[i].target((i%curSqrCountX)*stepX+stepX,curY*stepY);
            squares[i].paint(userDistrubution);
            squares[i].rise(10);
          }
         
          if(oldSqrTot>curSqrTot){
            eventNumber=3;//grow
          }else{
            eventNumber=4;//descent
          }
          break;
        case 3://grow
          for(int i=0;i          if(oldSqrTot>curSqrTot){
            eventCounter=0;
            userInput=false;
            eventNumber=0;//reconfigure
          }else{
            eventCounter=eventShortCounter;
            eventNumber=2;//move
          }
          break;
        case 4://descent
          eventCounter=0;
          for(int i=0;i            if(squares[i].isReady()){squares[i].descent();}
          }
          userInput=false;
          eventNumber=0;//reconfigure
          break;
      }
    }
    if (!userInput&&mousePressed) {
      userInput=true;
      //int(random(minSqrSize,100))
      userSize=int(minSqrSize+(100-minSqrSize)*(float(mouseX)/float(width)));
      //userSize=100/mouseX*width+minSqrSize;
      userDistrubution=int(100*(float(mouseY)/float(height)));
      print("mouseX: ",mouseX," mouseY: ",mouseY,"\n");
      print("userSize: ",userSize," userDistrubution: ",userDistrubution,"\n");
      
     
    }
    saveFrame("sqrn####.jpg");//record -------------------------------------------------------------------------
} //end of draw

Thursday, June 12, 2014

#FLcreativecoding 25 Squares B answer to challenge

/*
 * Creative Coding
 * Week 2, 03 - n squares
completely rec0ded by Marius Ivaskevicius
 */
int minSqrSize=10;
class Square{
  float xPos;
  float yPos;
  int DesX;
  int DesY;
  float size=minSqrSize;
  float desSize= size;
  int h=10;
  int speed=10;//record2 else10-----------------------------------------------------------------------------------
  boolean isFalling=false;
  int fallSpeed=0;
  boolean isReadied=false;
  void teleport(int x,int y){
    this.isFalling=false;
    this.xPos=this.DesX=x;
    this.yPos=this.DesY=y;
  }
  void target(int x,int y){
    this.DesX=x;
    this.DesY=y;
  }
  void plotShadow(){
    fill(128,61,0,100); // shadow
    rect(this.xPos+this.h,
         this.yPos+this.h,
         this.size,
         this.size);
  }
  void plotBody(){
    fill(255,136,4,200); // rectangle
    rect(this.xPos,
         this.yPos,
         this.size,
         this.size);
  }
  void update(){
    this.xPos-=(this.xPos-this.DesX)/speed;
    if(this.isFalling){
      if(this.yPos      this.fallSpeed+=1;
      this.yPos+=this.fallSpeed;
    }else{
      this.yPos-=(this.yPos-this.DesY)/speed;
    }
    this.size-=(this.size-this.desSize)/speed;
  }
  void fall(){
    this.isFalling=true;
    this.isReadied=false;
    this.fallSpeed=0;
    this.DesX+=random(-500,500);
  }
  void ready(){this.isReadied=true;}
  boolean isReady(){return this.isReadied;}
  boolean isFallen(){return this.isFalling;}
  void descent(){
    this.isFalling=false;
    this.isReadied=false;
    this.yPos=this.size*-1;
  }
  void grow(int size){
    this.desSize=size;
  }
}
int eventCounter=0;
int eventCounterTot=120;//record5 else100 ------------------------------------------------------------------------
int eventShortCounter=eventCounterTot-60;
int eventNumber=0;

int sqrCountX;
int sqrCountY;
int sqrTot;
int oldSqrTot;
//int[] arr= new int[10];
//arr[1]=0;
Square[] squares;

int curSqrCountX;
int curSqrCountY;
int stepX;
int stepY;
int curSqrTot;
void newScale(int size){
  curSqrCountX=(width/(size+minSqrSize))-1;
  curSqrCountY=(height/(size+minSqrSize))-1;
  curSqrTot=curSqrCountX*curSqrCountY;
  //oldSqrTot=curSqrTot;
  stepX=width/(curSqrCountX+1);
  stepY=height/(curSqrCountY+1);
}
void setup() {
  size(800, 600);
  sqrCountX=width/(minSqrSize*2)-1;
  sqrCountY=height/(minSqrSize*2)-1;
  sqrTot=sqrCountX*sqrCountY;
  newScale(minSqrSize);
  squares= new Square[sqrTot];
  int curY=0;
  for(int i=0;i      squares[i]=new Square();
      if((i%sqrCountX)==0){curY++;}
      squares[i].teleport((i%sqrCountX)*stepX+stepX,curY*stepY);
  }
  rectMode(CENTER);
  noStroke();
  //frameRate(1);//record ------------------------------------------------------------------------------------------
 
}
void shuffle(){
  Square temp;
  int pick;
   for(int i=0; i       temp = squares[i];
       pick  = int(random(squares.length));
       squares[i] = squares[pick];
       squares[pick]= temp;
     }
}
void sort(){
  Square[] tmpSquares;
  tmpSquares= new Square[sqrTot];
  int j=0;
  int f=sqrTot-1;
  for(int i=0;i    if(squares[i].isFallen() && !squares[i].isReady()){tmpSquares[f--]=squares[i];}
    else{tmpSquares[j++]=squares[i];}
  }
  squares=tmpSquares;
}
int newSize;
void draw() {
    background(90,114,169); // clear the screen to grey
    for(int i=0;i    for(int i=0;i    for(int i=0;i    if(++eventCounter>=eventCounterTot){ //------( event !!! )-----
      if(eventNumber==0){
          oldSqrTot=curSqrTot;
          newSize=int(random(minSqrSize,100));
          newScale(newSize);
          if(oldSqrTot>curSqrTot){
            eventNumber=1;//drop
          }else{
            eventNumber=3;//grow
          }
      }
      switch(eventNumber){
        case 1://drop
          shuffle();
          sort();
          int toDrop=sqrTot-curSqrTot;
          for(int i=curSqrTot;i          eventCounter=eventShortCounter;
          eventNumber=2;//move
          break;
        case 2://move
          eventCounter=eventShortCounter;
          for(int i=oldSqrTot;i          shuffle();
          sort();
          int curY=0;
          for(int i=0;i            if(i%curSqrCountX==0){curY++;}
            squares[i].target((i%curSqrCountX)*stepX+stepX,curY*stepY);
          }
          if(oldSqrTot>curSqrTot){
            eventNumber=3;//grow
          }else{
            eventNumber=4;//descent
          }
          break;
        case 3://grow
          for(int i=0;i          if(oldSqrTot>curSqrTot){
            eventCounter=0;
            eventNumber=0;//reconfigure
          }else{
            eventCounter=eventShortCounter;
            eventNumber=2;//move
          }
          break;
        case 4://descent
          eventCounter=0;
          for(int i=0;i            if(squares[i].isReady()){squares[i].descent();}
          }
          eventNumber=0;//reconfigure
          break;
      }
    }
    //saveFrame("sqrn####.jpg");//record -------------------------------------------------------------------------
} //end of draw

#FLcreativecoding 25 Squares A

/*
 * Creative Coding
 * Week 2, 03 - n squares
completely rec0det by Marius Ivaskevicius
 */
class Square{
  int xPos;
  int yPos;
  int DesX;
  int DesY;
  int size=50;
  int h=10;
  int speed=10;//record2 else10-----------------------------------------------------------------------------------
  void teleport(int x,int y){
    this.xPos=this.DesX=x;
    this.yPos=this.DesY=y;
  }
  void target(int x,int y){
    this.DesX=x;
    this.DesY=y;
  }
  void update(){
    this.xPos-=(this.xPos-this.DesX)/speed;
    this.yPos-=(this.yPos-this.DesY)/speed;
    fill(128,61,0,100); // shadow
    rect(this.xPos+this.h,
         this.yPos+this.h,
         this.size,
         this.size);
    fill(255,136,4,200); // rectangle
    rect(this.xPos,
         this.yPos,
         this.size,
         this.size);
  }
}
int eventCounter=0;
int eventCounterTot=100;//record5 else100 ------------------------------------------------------------------------
int eventNumber=0;
int sqrTot=100;
//int[] arr= new int[10];
//arr[1]=0;
Square[] squares;

void setup() {
  size(800, 600);
  rectMode(CENTER);
  noStroke();
  int stepX=width/11;
  int stepY=height/11;
  squares= new Square[100];
  for(int i=0;i      squares[i]=new Square();
      squares[i].teleport(i%10*stepX+stepX,i/10*stepY+stepY);
  }
  //frameRate(1);//record ------------------------------------------------------------------------------------------
}
void draw() {
    background(90,114,169); // clear the screen to grey
    int stepX=width/11;
    int stepY=height/11;
    for(int i=0;i      squares[i].update();
    }
    if(++eventCounter>=eventCounterTot){
      eventCounter=0;
      for(int i=0;i        squares[i].target(i%(sqrTot/10)*stepX+stepX+int(random(-40,40)),
                          i/        10 *stepY+stepY+int(random(-40,40)));
      }
    }
    //saveFrame("sqrn####.jpg");//record -------------------------------------------------------------------------
} //end of draw

#FLcreativecoding Draw your name: part 3 animated gif


Sunday, June 08, 2014

#FLcreativecoding Draw your name: part 3








/*
 * Creative Coding
 * Week 1, 03 - Draw your name! (part 3)
 * by Indae Hwang and Jon McCormack
 * Copyright (c) 2014 Monash University

 * This program allows you to draw using the mouse.
 * Press 's' to save your drawing as an image.
 * Press 'r' to erase all your drawing and start with a blank screen
 *

modiefied by Marius Ivaskevicius
using friendly virtual agent to draw by itself
its a bit drunk so movement direction and speed is randomised
draws the name accoring to array "map"
in which "." is black and numbers 1-4 are colors

one can use variable SPEED to control how many steps agent moves
one can use variable FADEOUT to control how much past traces are fading out.

 */
int SPEED=10000;
int FADEOUT=20;
String[] map ={ "...................................",
                "...................................",
                "..........1111..11..11..1.1.1.1....",
                "..........2.2.2.2.2.2.2.2.2.2.22...",
                "..........3.3.3.333.33..3.3.3...3..",
                "..........4.4.4.4.4.4.4.4..44.44...",
                "..................................."};
// variables to store the delay and target counts
int delayCount;
int targetCount;
//agent init
boolean agent=true;
float agentX=0;
float agentY=0;
float agentSpeed=3;
float agentSpeedNoise=1;
float agentSpeedMax=10;
float agentSpeedMin=1;
float agentSpeedX=0;
float agentSpeedY=0;
float agentDir=125;
float agentDirNoise=180;
float mSize;
// setup function
void setup() {
  size(1500, 300);
  background(0);
  delayCount = 0;
  targetCount = (int) random(5, 50); // set target count to a random integer between 10 and 50
}
//--------------- function that prevenst angle from going beyond 0-360 -----------------------------------------------
float safeTurn(float preAngle,float turnAngle){
  preAngle+=turnAngle;
  if(preAngle<0 br="" preangle="">  if(preAngle>360){preAngle-=360;}
  return preAngle;
}

// draw function
void draw() {
  stroke(0,FADEOUT);
  fill(0,FADEOUT);
  rect(0,0,width,height);
  for(int skipFrames=0;skipFrames<=SPEED;skipFrames++){
 
    //agent moves
    agentSpeedX=agentSpeed*cos(radians(agentDir));
    agentSpeedY=agentSpeed*sin(radians(agentDir));
    agentX+=agentSpeedX;
    agentY+=agentSpeedY;
  //walk arround
    if(agentX>width){agentX-=width;}
    if(agentX<0 agentx="" br="" width="">    if(agentY>height){agentY-=height;}
    if(agentY<0 agenty="" br="" height="">   
    agentSpeed+=random(agentSpeedNoise)-agentSpeedNoise/2;
    if(agentSpeed>agentSpeedMax){agentSpeed=agentSpeedMax;}
    if(agentSpeed    agentDir=random(agentDirNoise)-agentDirNoise/2;
    if(agentDir<0 agentdir="" br="">    if(agentDir>360){agentDir-=360;}
    //set colors by map
    int gridX=0;
    int gridY=0;
    int gridXsize=width/map[0].length();
    int gridYsize=height/map.length;
    for(int i=0;i      if(agentY>gridYsize*i&&agentY        gridY=i;
      }
    }
    for(int i=0;i      if(agentX>gridXsize*i&&agentX        gridX=i;
      }
    }
   
    switch(map[gridY].charAt(gridX)){
      case'.':
        stroke(50,50);
        fill(20,20);
        mSize=1;
        break;
      case'1':
        stroke(250,50,0,50);
        fill(180,20,0,20);
        mSize=1.2;
        break;
      case'2':
        stroke(250,120,120,50);
        fill(220,180,0,20);
        mSize=1.4;
        break;
      case'3':
        stroke(0,120,200,50);
        fill(0,80,150,20);
        mSize=1.6;
        break;
      case'4':
        stroke(0,50,120,50);
        fill(0,20,80,20);
        mSize=1.8;
        break;
    }
    int style;
    delayCount++; // increment delay count (shorthand for delayCount = delayCount + 1)
    if (delayCount == targetCount) {
      style = (int) random(4);
      targetCount = (int) random(5, 20) ;
      delayCount = 0;
    }
    else {
      style = 0;
    }
      // switch statement
      switch(style) {
      case 0:
        // draw a point
        point(agentX, agentY);
        break;
      case 1:
        // draw a circle with random radius
        float esize = random(1, 20)*mSize;
        ellipse(agentX, agentY, esize, esize);
        break;
      case 2:
        // draw a random sized rectangle
        float qsize = random(1, 10)*mSize;
        quad(agentX-qsize, agentY, agentX, agentY-qsize, agentX+qsize, agentY, agentX, agentY+qsize   );
        break;
      case 3:
        // draw a triangle with random size
        float tsize = random(1, 5)*mSize;
        triangle(agentX-tsize, agentY+tsize, agentX, agentY-tsize, agentX+tsize, agentY+tsize);
        break;
      } // end of switch statement
  }
  // save your drawing when you press keyboard 's'
  if (keyPressed == true && key=='s') {
    saveFrame("yourName.jpg");
  }
  // erase your drawing when you press keyboard 'r'
  if (keyPressed == true && key == 'r') {
    background(255);
  }
}

Wednesday, June 04, 2014

#FLcreativecoding Draw your name: part 2

/*
 * Creative Coding
 * Week 1, 02 - Draw your name! (part 2)
 * by Indae Hwang and Jon McCormack
 * Copyright (c) 2014 Monash University

 * This program allows you to draw using the mouse.
 * Press 's' to save your drawing as an image.
 * Press 'r' to erase your drawing and start with a blank screen
 *

modiefied by Marius Ivaskevicius

press [t] to display name in color
press [y] to display name in black (because black is not a color ;-) )
use variable NAME for obvious purpose
 */
String NAME="MARIUS";

PFont f;                          // STEP 2 Declare PFont variable
// variables for the angle (in radians) and increment
float angle;
float inc;

void setup() {
  size(1200, 400);
  background(0);
  f = createFont("UNICODE0.TTF",100); // STEP 3 Create Font

  rectMode(CENTER);  // rectangles drawn from the centre

  // initialise angle and inc to 0
  angle = 0;
  inc = 0;
}


void draw() {
  /*
    textFont(f,100);                 // STEP 4 Specify font to be used
    fill(20,170,200,100);                        // STEP 5 Specify font color
    text("MARIUS",600+random(10),300+random(10));  // STEP 6 Display Text
    */

  /* draw a rectangle at your mouse point while you are pressing
   the left mouse button */

  // map the mouse x position to the range (0.01, 0.08)
  inc = map(mouseX, 0, width, 0.01, 0.08);

  // incremment the current angle
  angle = angle + inc;

  if (mousePressed) {

    stroke(170);
    fill(120, 60);

    rect(mouseX, mouseY, 2, 2);

    line(mouseX, mouseY, pmouseX, pmouseY); // pmouse is the mouse position at the previous frame

    // oscillate the radius over time
    float radius = 1000 * abs( sin(frameCount) );

    float first_tempX  = mouseX + radius * cos( angle);
    float first_tempY  = mouseY + radius * sin( angle);
    float second_tempX = mouseX + radius * cos(-angle*5);
    float second_tempY = mouseY + radius * sin(-angle*5);

    // draw some lines and circles using transparency
    //stroke(110, 100);
    stroke(random(50),random(50),255, 20);
    line(mouseX, mouseY, first_tempX, first_tempY);
    line(mouseX, mouseY, second_tempX, second_tempY);

    float temp_w = random(3);
    ellipse(first_tempX, first_tempY, temp_w, temp_w);
    ellipse(second_tempX, second_tempY, temp_w, temp_w);
  }


  // save your drawing when you press keyboard 's'
  if (keyPressed == true && key == 's') {
    saveFrame("yourName.jpg");
  }

  // erase your drawing when you press keyboard 'r'
  if (keyPressed == true && key == 'r') {
    background(0);
  }
 
  if (keyPressed == true && key == 't') {
    textFont(f,100);                 // STEP 4 Specify font to be used
    fill(255,random(170),random(200),100);                        // STEP 5 Specify font color
    text(NAME,600+random(10),300+random(10));  // STEP 6 Display Text

  }
    if (keyPressed == true && key == 'y') {
    textFont(f,100);                 // STEP 4 Specify font to be used
    fill(0,0,0,50);                        // STEP 5 Specify font color
    text(NAME,600+random(10),300+random(10));  // STEP 6 Display Text
  }
 
}

Monday, June 02, 2014

#FLcreativecoding Draw your name: part 1

//_##___##____#____####__
//_#_#_#_#___#_#___#___#_
//_#__#__#__#___#__#__#__
//_#___ _###_____###___#_

int timer=0;
int timeOut=500;
int ceiling=500; 
int posX=100;
int posY=400;
int step=20;
int speed=2;
void setup() {
  size(timeOut, ceiling);
  background(255);
  rectMode(RADIUS);
}
void drunkLine(int x,int y){
  for(int i=0;i<=step;i++){
    posX+=(random(speed)-(speed/2))+speed*x;
    posY+=(random(speed)-(speed/2))+speed*y;
    rect(posX, posY, random(6), random(6));
  }
}
void draw() {
  posX=40+int(random(10));
  posY=370+int(random(10));

  fill(0, 50);
  rect(timeOut/2, ceiling/2, timeOut, ceiling);
  int r=int(random(150));
  int g=int(random(150))+100;
  int b=int(random(150));
  stroke(r,g,b);
  int darker=50;
  fill(r-darker,g-darker,b-darker, 150);
  drunkLine(1,0); //pass in
 
  drunkLine(0,-1); //M North
  drunkLine(0,-1);
  drunkLine(0,-1);
  drunkLine(0,-1);
 
  drunkLine(1,1); //M SE
  drunkLine(1,1);
  drunkLine(1,1);
 
  drunkLine(1,-1); //M NE
  drunkLine(1,-1);
 
  drunkLine(0,2); //M S
  drunkLine(0,2);
  drunkLine(0,2);
  drunkLine(0,1);

  drunkLine(1,0); //pass to A
 
  drunkLine(1,-2); //A NE
  drunkLine(1,-2);
 
  drunkLine(1,2); //A SE
  drunkLine(1,2);
  drunkLine(1,2);
 
  drunkLine(1,0); //pass to R
 
  drunkLine(0,-1); //R North
  drunkLine(0,-1);
  drunkLine(0,-1);
  drunkLine(0,-1);
 
  drunkLine(1,0); //R E
  drunkLine(1,0);
 
  drunkLine(1,1);
  drunkLine(0,1);
  drunkLine(-1,1);
 
  drunkLine(1,1);
  drunkLine(1,1);
  drunkLine(1,1);
 
  drunkLine(1,0); //pass out
  noLoop();
}
void keyPressed(){
if (key=='s') {
    saveFrame("yourName.jpg");
  }
}
void mousePressed() {
  loop();
}