import controlP5.*; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Establishing universal variables PImage[] images = new PImage [13]; Triangle1 t1 ; Triangle2 t2 ; Triangle3 t3 ; Triangle4 t4 ; Triangle5 t5 ; Quad1 q1 ; Quad2 q2 ; int c,w; boolean a; boolean d; color e; ControlP5 controlP5; public float myAngle1= 0; public float myAngle2= 0; public float myAngle3= 0; public float myAngle4= 0; public float myAngle5= 0; public float myAngle6= 0; public float myAngle7= 0; MultiList l; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Setting up the environment void setup(){ size (1200,800); smooth(); background(255); t1= new Triangle1(583,341.5,-59,-118,-59,118,59,0); t2= new Triangle2(642,400.5,-118,59,118,59,0,-59); t3= new Triangle3(730.5,253,-88.5,-29.5,29.5,-29.5,29.5,88.5); t4= new Triangle4(583,253,-59,-29.5,59,-29.5,0,29.5); t5= new Triangle5(671.5,341.5,-29.5,0,29.5,-59,29.5,59); q1= new Quad1(642,282.5,-59,0,0,-59,59,0,0,59); q2= new Quad2(730.5,371,-29.5,-88.5,29.5,-29.5,29.5,88.5,-29.5,29.5); for (int i = 0; i < 13; i++) { String imageName = "image" + i+ ".jpg"; images[i] = loadImage(imageName); } c=0; controlP5 = new ControlP5(this); controlP5.addSlider("R1",-360,360,0,1000,200,180,20); controlP5.addSlider("R2",-360,360,0,1000,230,180,20); controlP5.addSlider("R3",-360,360,0,1000,260,180,20); controlP5.addSlider("R4",-360,360,0,1000,290,180,20); controlP5.addSlider("R5",-360,360,0,1000,320,180,20); controlP5.addSlider("R6",-360,360,0,1000,350,180,20); controlP5.addSlider("R7",-360,360,0,1000,380,180,20); controlP5.addButton("CLEAR",10,1000,430,200,30); l = controlP5.addMultiList("myList",1000,150,100,18); MultiListButton b; b = l.add("SHAPE",1); b.add("level11",11).setLabel("STROKE BLACK"); b.add("level12",12).setLabel("NO STROKE"); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////The draw routine void draw(){ imageMode(CORNER); image(images[0],0,0,1000,800); image(images[1],36,120,236,236); select(); displaySelect(); if((mouseX >36) && (mouseX <272)&&(mouseY > 120) && (mouseY < 356)){ if (mousePressed==true){ if (mouseButton==LEFT){ a=true; } } } if(a==true){ noFill(); stroke(255); strokeWeight(12); strokeJoin(ROUND); rect(29,113,250,250);//////////////////////////////////////////////////////////////////////////////////////////////select the tangram if(w==1&&d==true) { strokeWeight(2); stroke(0); fill(55,176,223); t1.display(); fill(155,195,91); t2.display(); fill(251,196,0); t3.display(); fill(243,176,205); t4.display(); fill(255,241,0); t5.display(); fill(201,129,180); q1.display(); fill(233,88,134); q2.display(); } if(w==2&&d==true) { noStroke(); fill(55,176,223); t1.display(); fill(155,195,91); t2.display(); fill(251,196,0); t3.display(); fill(243,176,205); t4.display(); fill(255,241,0); t5.display(); fill(201,129,180); q1.display(); fill(233,88,134); q2.display(); //////////////////////////////////////////////////////////////////////////////////////////////////display the tangram in the drawing area } if (mouseX>320&&mouseX<964&&mouseY>39&&mouseY<644) { color e =get(mouseX,mouseY); if(e==color(55,176,223)) { t1.move(); } if(e== color(155,195,91)) { t2.move(); } if(e== color(251,196,0)) { t3.move(); } if(e== color(243,176,205)) { t4.move(); } if(e== color(255,241,0)) { t5.move(); } if(e== color(201,129,180)) { q1.move(); } if(e== color(233,88,134)) { q2.move(); } } //////////////////////////////////////////////////////////////////////////////////move and rotate the elemental forms } fill(0); noStroke(); rect(1180,200,20,20); rect(1180,230,20,20); rect(1180,260,20,20); rect(1180,290,20,20); rect(1180,320,20,20); rect(1180,350,20,20); rect(1180,380,20,20); noFill(); stroke(0); strokeWeight(2); rect(0,0,1200,800); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void R1(int theValue1) { myAngle1 = theValue1; } void R2(int theValue2) { myAngle2 = theValue2; } void R3(int theValue3) { myAngle3 = theValue3; } void R4(int theValue4) { myAngle4 = theValue4; } void R5(int theValue5) { myAngle5 = theValue5; } void R6(int theValue6) { myAngle6 = theValue6; } void R7(int theValue7) { myAngle7 = theValue7; } void CLEAR() { a=false; d=false; myAngle1=0; myAngle2=0; myAngle3=0; myAngle4=0; myAngle5=0; myAngle6=0; myAngle7=0; } ///////////////////////////////////////////////// //method for activate each button void level11() { d=true; w=1; } void level12 () { d=true; w=2; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////select examples of shapes void select() { if((mouseY >690) &&(mouseY < 766)){ if (mousePressed==true){ if (mouseButton==LEFT){ if((mouseX >59) && (mouseX <115)){ c=1; } if((mouseX >143) && (mouseX <198)){ c=2; } if((mouseX >228) && (mouseX <282)){ c=3; } if((mouseX >312) && (mouseX <367)){ c=4; } if((mouseX >396) && (mouseX <451)){ c=5; } if((mouseX >480) && (mouseX <535)){ c=6; } if((mouseX >564) && (mouseX <619)){ c=7; } if((mouseX >648) && (mouseX <703)){ c=8; } if((mouseX >732) && (mouseX <788)){ c=9; } if((mouseX >817) && (mouseX <872)){ c=10; } if((mouseX >901) && (mouseX <956)){ c=11; } } } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////display examples of shapes which is selected by orange rect void displaySelect() { if(c==1){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(50,690,67,77); imageMode(CORNER); image(images[2],67,419); } if(c==2){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(136,690,67,77); imageMode(CORNER); image(images[3],61,411); } if(c==3){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(220,690,67,77); imageMode(CORNER); image(images[4],58,419); } if(c==4){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(305,690,67,77); imageMode(CORNER); image(images[5],85,412); } if(c==5){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(389,690,67,77); imageMode(CORNER); image(images[6],67,419); } if(c==6){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(473,690,67,77); imageMode(CORNER); image(images[7],67,419); } if(c==7){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(558,690,67,77); imageMode(CORNER); image(images[8],56,419); } if(c==8){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(642,690,67,77); imageMode(CORNER); image(images[9],59,419); } if(c==9){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(726,690,67,77); imageMode(CORNER); image(images[10],50,449); } if(c==10){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(811,690,65,77); imageMode(CORNER); image(images[11],50,449); } if(c==11){ noFill(); stroke(250,153,33); strokeWeight(1); strokeJoin(ROUND); rect(895,690,67,77); imageMode(CORNER); image(images[12],67,419); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class Triangle class Triangle { float x,y,x1,x2,x3,y1,y2,y3,angle; Triangle(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3) { x=mx; y=my; x1=xpos1; y1=ypos1; x2=xpos2; y2=ypos2; x3=xpos3; y3=ypos3; } void move( ) { if(mousePressed==true) { if (mouseButton==LEFT){ x=mouseX; y=mouseY; } } } void display() { pushMatrix(); translate(x,y); rotate(angle); triangle(x1,y1,x2,y2,x3,y3); popMatrix(); } } class Triangle1 extends Triangle { Triangle1(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3) { super(mx,my,xpos1,ypos1,xpos2,ypos2,xpos3,ypos3); } void display() { pushMatrix(); translate(x,y); rotate(myAngle1); triangle(x1,y1,x2,y2,x3,y3); popMatrix(); } } class Triangle2 extends Triangle { Triangle2(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3) { super(mx,my,xpos1,ypos1,xpos2,ypos2,xpos3,ypos3); } void display() { pushMatrix(); translate(x,y); rotate(myAngle2); triangle(x1,y1,x2,y2,x3,y3); popMatrix(); } } class Triangle3 extends Triangle { Triangle3(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3) { super(mx,my,xpos1,ypos1,xpos2,ypos2,xpos3,ypos3); } void display() { pushMatrix(); translate(x,y); rotate(myAngle3); triangle(x1,y1,x2,y2,x3,y3); popMatrix(); } } class Triangle4 extends Triangle { Triangle4(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3) { super(mx,my,xpos1,ypos1,xpos2,ypos2,xpos3,ypos3); } void display() { pushMatrix(); translate(x,y); rotate(myAngle4); triangle(x1,y1,x2,y2,x3,y3); popMatrix(); } } class Triangle5 extends Triangle { Triangle5(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3) { super(mx,my,xpos1,ypos1,xpos2,ypos2,xpos3,ypos3); } void display() { pushMatrix(); translate(x,y); rotate(myAngle5); triangle(x1,y1,x2,y2,x3,y3); popMatrix(); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////class quad class Quad { float x,y,x1,x2,x3,y1,y2,y3,x4,y4; float angle=0; Quad(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3,float xpos4,float ypos4) { x=mx; y=my; x1=xpos1; y1=ypos1; x2=xpos2; y2=ypos2; x3=xpos3; y3=ypos3; x4=xpos4; y4=ypos4; } void move( ) { if(mousePressed==true) { if (mouseButton==LEFT){ x=mouseX; y=mouseY; } } } void display() { pushMatrix(); translate(x,y); rotate(angle); quad(x1,y1,x2,y2,x3,y3,x4,y4); popMatrix(); } } class Quad1 extends Quad { Quad1(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3,float xpos4,float ypos4) { super(mx,my,xpos1,ypos1,xpos2,ypos2,xpos3,ypos3,xpos4,ypos4); } void display() { pushMatrix(); translate(x,y); rotate(myAngle6); quad(x1,y1,x2,y2,x3,y3,x4,y4); popMatrix(); } } class Quad2 extends Quad { Quad2(float mx,float my,float xpos1,float ypos1,float xpos2,float ypos2,float xpos3,float ypos3,float xpos4,float ypos4) { super(mx,my,xpos1,ypos1,xpos2,ypos2,xpos3,ypos3,xpos4,ypos4); } void display() { pushMatrix(); translate(x,y); rotate(myAngle7); quad(x1,y1,x2,y2,x3,y3,x4,y4); popMatrix(); } }