float[] a1 = new float[2]; float[] a2 = new float[2]; float[] c1 = new float[2]; float[] c2 = new float[2]; PFont font; String[] msgs = new String[4]; int turn =0; void setup() { size(800,600); background(255); font = createFont("Ariel",18); textFont(font); msgs[0] ="Set anchor 1"; msgs[3] ="Set anchor 2"; msgs[1] = "Set control 1"; msgs[2] = "Set control 2"; fill(0,255,0); text(msgs[0],10,50); drawbuttons(); } void draw() { } void mousePressed() { if ((mouseX>650)&&(mouseX<716)&&(mouseY>50)&&(mouseY<80)) { turn=0; //erasing old message fill(255); noStroke(); rect(5,20,120,80); fill(0,255,0); text(msgs[turn],10,50); } else if ((mouseX>740)&&(mouseX<790)&&(mouseY>50)&&(mouseY<80)){ //erase everything background(255); drawbuttons(); turn=0; //erasing old message fill(255); noStroke(); rect(5,20,120,80); fill(0,255,0); text(msgs[turn],10,50); } else { stroke(0,255,0); triangle(mouseX,mouseY, mouseX, mouseY+3,mouseX+3,mouseY); switch(turn) { case 0: a1[0] = mouseX; a1[1] = mouseY; break; case 3: a2[0] = mouseX; a2[1] = mouseY; break; case 1: c1[0] = mouseX; c1[1] = mouseY; break; case 2: c2[0] = mouseX; c2[1] = mouseY; break; } turn++; if (turn<4) { //erasing old message fill(255); noStroke(); rect(5,20,120,80); fill(0,255,0); text(msgs[turn],10,50); } else { turn=1; //erasing old message fill(255); noStroke(); rect(5,20,120,80); stroke(0,0,255); noFill(); bezier(a1[0],a1[1],c1[0],c1[1],c2[0],c2[1],a2[0],a2[1]); a1[0] = a2[0]; a1[1] = a2[1]; fill(0,255,0); text(msgs[1],10,50); } } } void drawbuttons() { fill(0); text("Click mouse to set anchor and control points for continuous Bezier curve.",50,20); noFill(); rect(650,50,66,30); rect(740,50,50,30); fill(0); text("Re-start",652,68); text("Clear",742,68); }