xxxxxxxxxx
float startingX = 10;
float startingY = 10;
int lineLength = 580;
float xRatio=1;
float yRatio=1;
int counter;
int direction = 0; //0 -> LR, 1-> UD, 2-> RL, 3->DU
boolean play = true;
void setup() {
size(600, 600);
frameRate(10);
}
void draw() {
fill(255, 255, 255);
background(255,255,255);
// println(temp);
if(play) {
beginShape();
vertex(startingX,startingY);
for ( counter = 0; counter < 1000; counter++)
{
float temp = map(mouseX, 0, width, 1, 1.009);
float temp2 = map(mouseY, 0, height, 1, 1.009);
xRatio = temp;
yRatio = temp2;
fill(random(150),random(200),random(100,110));
direction = (counter)%4 ;
if (direction == 0) {
//line(startingX, startingY, startingX + lineLength, startingY);
if(mouseX>width/2)
startingX = startingX + xRatio*lineLength;
else
startingX = startingX + lineLength;
startingY = startingY;
vertex(startingX,startingY);
} else if ( direction == 1) {
// line(startingX, startingY, startingX, startingY+ lineLength);
startingX = startingX ;
if(mouseY > height/2)
startingY= startingY + yRatio*lineLength;
else
startingY = startingY+ lineLength;
vertex(startingX,startingY);
} else if ( direction == 2) {
//line(startingX, startingY, startingX - lineLength, startingY);
if(mouseX<width/2)
startingX = startingX - xRatio*lineLength;
else
startingX = startingX - lineLength;
startingY = startingY;
vertex(startingX,startingY);
} else if ( direction == 3) {
//line(startingX, startingY, startingX, startingY- lineLength);
startingX = startingX ;
if(mouseY <height/2)
startingY = startingY - yRatio*lineLength;
else
startingY = startingY- lineLength;
vertex(startingX,startingY);
endShape();
beginShape();
vertex(startingX,startingY);
}
lineLength -= 3;
if ( lineLength <=0) {
play = false;
break;
}
}
endShape();
startingX = 10;
startingY = 10;
lineLength = 580;
play=true;
direction = 0;
counter = 0;
}
}