int mode = 0; int antal=0; void setup() { size(300,300); background(255); ellipseMode(CENTER_DIAMETER); noStroke(); fill(245); rect(0,0,width,20); rectMode(CENTER_DIAMETER); buttons(mode); } int old_x = -100; int old_y = -100; int control_x = -100; int control_y = -100; int control_x2 = -100; int control_y2 = -100; void loop() { if (mousePressed == true&&mouseY>20) { int new_x=mouseX; int new_y=mouseY; noStroke(); fill(int(random(200,250)),int(random(200,250)),int(random(200,250))); ellipse(new_x,new_y,20,20); fill(255); rect(new_x-2, new_y-2,5,5); if(old_x != -100) { stroke(200); if(mode==0){ find_controlpunkt(old_x,old_y,new_x,new_y); bezier(old_x,old_y,control_x,control_y,control_x,control_y,new_x,new_y); } if(mode==1){ find_controlpunkt(old_x,old_y,new_x,new_y); line(old_x, old_y,control_x,control_y); line(control_x,control_y,new_x,new_y); } delay(100); } old_x=new_x; old_y =new_y; } if (mousePressed == true&&mouseY<20&&mouseX<(width-50)) { mode = abs(mode-1); buttons(mode); delay(100); } if (mousePressed == true&&mouseY<20&&mouseX>(width-50)) { background(255); noStroke(); fill(245); rect(width/2,10,width,20); buttons(mode); old_x = old_y = -100; } } void find_controlpunkt(int x1, int y1, int x2, int y2) { int halvx=(x2-x1)/2; int halvy=(y2-y1)/2; control_x= x1+halvx; control_y = y1+halvy; control_x= control_x + halvy; control_y = control_y - halvx; } void buttons (int mode) { stroke(0); fill(255); rect (width-10,10,10,10); if (mode==1) { fill(255); rect (10,10,10,10); fill (180); rect (25,10,10,10); } else { fill (180); rect (10,10,10,10); fill(255); rect (25,10,10,10); } }