/*Triangle practice PCS 6th grade - Z. J. Wood 10/2015 */ /* click each of the specified missing vertices */ /* Winslow mod - click wherever you want to draw final vertex include 4 triangles*/ void setup() { size(800, 800); v1x = 400; v1y = 300; v2x = 600; v2y = 100; v3x = 550; v3y = 550; C1x = 400; C1y = 300; C2x = 500; C2y = 400; C3x = 300; C3y = 500; mouseX = mouseY = 100; anim1 = true; anim2 = anim3 = anim4 =false; } void mousePressed() { if (anim1) { anim1 = false; C1x = t2x = mouseX; C1y = t2y = mouseY; anim2 = true; } else if (anim2) { anim2 = false; C2x = mouseX; C2y = mouseY; anim3 = true; } else if (anim3) { anim3 = false; C3x = mouseX; C3y = mouseY; anim4 = true; }else if (anim4) { anim4 = false; C4x = mouseX; C4y = mouseY; } } void draw() { background(12, 34, 56); drawGrid(); fill(250, 200, 200); text("Draw whatever you want, by clicking the mouse", 20, 20); if (anim1) { fill(250, 250, 24); triangle(mouseX, mouseY, 200, 200, 200, 400); } else { fill(250, 250, 240); triangle(C1x, C1y, 200, 200, 200, 400); } if (anim2) { fill(250, 250, 24); triangle(mouseX, mouseY, 200, 200, t2x, t2y); } else if (!anim1 && !anim2) { fill(250, 250, 240); triangle(C2x, C2y, 200, 200, t2x, t2y); } if (anim3) { fill(250, 250, 24); triangle(mouseX, mouseY, 200, 400, t2x, t2y); } else if (!anim1 && !anim2 && !anim3) { fill(250, 250, 240); triangle(C3x, C3y, 200, 400, t2x, t2y); } if (anim4) { fill(250, 250, 24); triangle(mouseX, mouseY, C3x, C3y, 200, 400); } else if (!anim1 && !anim2 && !anim3) { fill(250, 250, 240); triangle(C4x, C4y, C3x, C3y, 200, 400); } fill(255); text("Current {x, y}: {" + mouseX + ", " +mouseY + "}", 20, 40); } int C1x, C1y, C2x, C2y, C3x, C3y, C4x, C4y; int v1x, v1y, v2x, v2y, v3x, v3y; int t2x, t2y, t3x, t3y; boolean v1, v2, v3; boolean anim1, anim2, anim3, anim4; /*Method to draw a grid every 50th pixel */ void drawGrid() { //the horizontal lines - every 50th pixel draw a line for (int i=0; i < height/50; i++) { if (i%2 == 0) { strokeWeight(1); stroke(0, 0, 128); } else { strokeWeight(2); stroke(128, 128, 128); } line(0, (i+1)*50, width, (i+1)*50); } //the vertical lines - every 50th pixel draw a line for (int i=0; i < width/50; i++) { if (i%2 == 0) { stroke(128, 0, 128); strokeWeight(1); } else { strokeWeight(2); stroke(128, 128, 128); } line((i+1)*50, 0, (i+1)*50, height); } }