[go: up one dir, main page]

0% found this document useful (0 votes)
2 views2 pages

Square Puzzle

Uploaded by

Meena Garai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Square Puzzle

Uploaded by

Meena Garai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//SquarePuzzle

var c1,c2,c3;
var x=[];
var y=[];
var c=[];
var k;
var l=0;

function setup() {
createCanvas(300, 300);
k=0;
r=color(255,80,80);
g=color(100,240,100);
y=color(250,250,20);
c=[];

for(let i=0;i<width;i=i+width/3){
for(let j=0;j<height; j=j+height/3){
x[k]=j;
y[k]=i;
console.log(x,y);

if(k==0 || k==5 || k==6){


c[k]=r;
} else if (k==2 || k==4 || k==7){
c[k]=g;
} else {
c[k]=y;
}

k=k+1;
}
}
console.log(c);
}

function draw() {
background(220);
for(let m=0;m<9;m++){
fill(c[m]);
rect(x[m],y[m],width/3,height/3);
}

function mousePressed(){

if(mouseX<x[1] && mouseX>x[0] && mouseY<y[3] && mouseY>y[0]){


bs=1;
console.log(bs);
let h =c[4];
c[4] = c[0];
c[0]=h;

} else if(mouseX<x[2] && mouseX>x[1] && mouseY<y[4] && mouseY>y[1]){


bs=2;
console.log(bs);
let h =c[4];
c[4] = c[1];
c[1]=h;

} else if(mouseX<width && mouseX>x[2] && mouseY<y[5] && mouseY>y[2]){


bs=3;
console.log(bs);
let h =c[4];
c[4] = c[2];
c[2]=h;

} else if(mouseX<x[4] && mouseX>x[3] && mouseY<y[6] && mouseY>y[3]){


bs=4;
console.log(bs);
let h =c[4];
c[4] = c[3];
c[3]=h;

} else if(mouseX<x[5] && mouseX>x[4] && mouseY<y[7] && mouseY>y[4]){


bs=5;
console.log(bs);

} else if(mouseX<width && mouseX>x[5] && mouseY<y[8] && mouseY>y[5]){


bs=6;
console.log(bs);
let h =c[4];
c[4] = c[5];
c[5]=h;

} else if(mouseX<x[7] && mouseX>x[6] && mouseY<height && mouseY>y[6]){


bs=7;
console.log(bs);
let h =c[4];
c[4] = c[6];
c[6]=h;

} else if(mouseX<x[8] && mouseX>x[7] && mouseY<height && mouseY>y[7]){


bs=8;
console.log(bs);
let h =c[4];
c[4] = c[7];
c[7]=h;

} else if(mouseX<width && mouseX>x[7] && mouseY<height && mouseY>y[8]){


bs=9;
console.log(bs);
let h =c[4];
c[4] = c[8];
c[8]=h;
}

You might also like