#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.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
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
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
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
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
eventNumber=2;//move
break;
case 2://move
eventCounter=eventShortCounter;
for(int i=oldSqrTot;i
sort();
int curY=0;
for(int i=0;i
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
eventCounter=0;
userInput=false;
eventNumber=0;//reconfigure
}else{
eventCounter=eventShortCounter;
eventNumber=2;//move
}
break;
case 4://descent
eventCounter=0;
for(int i=0;i
}
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
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home