Project 3
//Shariwa Sharada
//Section-A
//ssharada@andrew.cmu.edu
//Assignment-03-A
var ssw = 135;
var ssh = 160;
function setup(){
createCanvas (480, 360);
rectMode(CENTER);
}
function draw(){
//changing the background depending on the position of the cursor
background(mouseX, mouseY, 191);
push();
//limiting the colour change to certain types - dependent on the mouse placement within a 4x3 grid
//changing colours dependent on the x-axis placement
if (mouseX>0 & mouseX < ssw){
mouseX = 246
}
if (mouseX>ssw && mouseX < ssw*2){
mouseX = 236
}
if (mouseX>ssw*2 && mouseX < ssw*3){
mouseX = 226
}
if (mouseX>ssw*2 && mouseX < width){
mouseX = 216
}
//changing colours dependent on the y-axis placement
if (mouseY>0 && mouseY < ssh){
mouseX = 180
}
if (mouseY>ssh && mouseY < ssh*2){
mouseX = 170
}
if (mouseY>ssh*2 && mouseY < height){
mouseX = 160
}
pop();
push();
//creating the translating and moving squares
translate (width/2, height/2);
//stating the number of squares i want within the first level -
//using the increment command to have the squares rotated with equal distances.
for (var a = 0; a < 15; a++){
push();
//rotation and pasting
rotate(TWO_PI * a / 15);
//making the placement of the level dependent
//on the y-axis placement of the cursor
var X = mouseY;
translate(X, 0);
//the colour of this rectangles and randomising the transparancy
//of the white to make the quares appear to flicker
fill(255, random(20,90));
noStroke();
//the size of the first level of rectangles.
rect(0,0,60,60);
//stating the number of squares i want within the second level -
//using the increment command to have the squares rotated with equal distances.
for (var b = 0; b < 12; b++){
push();
//rotation and pasting
rotate(TWO_PI * b/12);
//making the placement of the level dependent
//on the x-axis placement of the cursor
var Y = mouseX;
//the size of the second level of rectangles.
rect (Y,0,30,30);
//the colour of this rectangles and randomising the
//transparancy of the white to make the quares appear to flicker
fill(255, random(10,80));
noStroke();
//stating the number of squares i want within the third level -
//using the increment command to have the squares rotated with equal distances.
for (var c = 0; c < 8; c++){
push();
//rotation and pasting
rotate(TWO_PI* c/8);
//making the placement of the level dependent
//on the y-axis placement of the cursor
var Z = mouseY;
//the size of the third level of rectangles.
rect (0,Z,10,10);
//the colour of this rectangles and randomising the
//transparancy of the white to make the quares appear to flicker
fill(255, random(10,50));
noStroke();
//preventing the code from affecting other factors of the program
pop();
}
//preventing the code from affecting other factors of the program
pop();
}
//preventing the code from affecting other factors of the program
pop();
}
pop();
}