float weight=1; char lastShape; int x=2; float w=random(0,4); int c=0; char one; char two; float rand; char pShape; void setup() { size(400, 600); background(255); stroke(0); strokeWeight(1); } //w=random(50,100); void draw() { if(mousePressed){ if(mouseButton == RIGHT){ rand=random(0,3); //generate random color if(rand>=0 && rand<1){ stroke(255,0,0); }else if(rand>=1 && rand<2){ stroke(0,255,0); }else{ stroke(0,0,255); } //generate random shape if(w>=0 && w<1){ drawShape2('1'); }else if(w>=1 && w<2){ drawShape2('2'); }else if(w>=2 && w<3){ drawShape2('3'); }else{ drawShape2('4'); } //w=random(50,100);//generate random size for shapes }else if(mouseButton == LEFT){ if(key == 'r' || key == 'g' || key == 'b' || key == '0'){ one = lastShape;} else{ one = key;} if(key == '+'){ weight+=1; strokeWeight(weight); //changes the drawing object size key = lastShape; }else if(key == '-'){ weight-=1; if(weight<0){ weight = 0; } strokeWeight(weight); //changes the drawing object size key = lastShape; }else{ drawShape(one); } } } } void drawShape(char key1){ if(c == 0){ line(pmouseX, pmouseY, mouseX, mouseY); //draw line lastShape = '4'; } if (key1 == '1'){ rect(mouseX,mouseY,40+w,25+w); //draw rectange lastShape = '1'; c+=1; }else if(key1 == '2'){ ellipse(mouseX, mouseY, 40+w, 40+w); //draw elipse lastShape = '2'; c+=1; }else if(key1 == '3'){ arc(mouseX, (mouseY+70), 140, 140, PI, TWO_PI); //draw arc lastShape = '3'; c+=1; }else if(key1 == '4'){ line(pmouseX, pmouseY, mouseX, mouseY); //draw line lastShape = '4'; } } void drawShape2(char key1){ if (key1 == '1'){ rect(mouseX,mouseY,40+w,25+w); //draw rectange }else if(key1 == '2'){ ellipse(mouseX, mouseY, 40+w, 40+w); //draw elipse }else if(key1 == '3'){ arc(mouseX, (mouseY+70), 140, 140, PI, TWO_PI); //draw arc }else if(key1 == '4'){ line(pmouseX, pmouseY, mouseX, mouseY); //draw line } } void keyPressed() { if (key == '0') { background(255); //clear canvas stroke(0); //drawShape(lastShape); } else if (key == 'r') { stroke(255,0,0);//color red //drawShape(lastShape); } else if (key == 'g') { stroke(0,255,0);//color green //drawShape(lastShape); } else if (key == 'b') { stroke(0,0,255);//color blue //drawShape(lastShape); } } void mouseReleased(){ if (mouseButton==RIGHT){ w=random(0,4); stroke(0,0,0); } }