Sorting the Code for Drawing Sketch

Sorting the Code for Drawing Sketch

The 4th assignment was to organize our previous code (drawing sketch) into modular and reusable parts. We needed to organize by using functions. You can find the video for the code here –> Drawing Sketch


The organized code is as following:

String currentFigure = “no-shape”;

void setup() {
size(1200, 600);
background(0);
}
void draw() {
drawUI(width, height);
}
void mouseDragged() {

if (currentFigure==”rectangle”&&mouseX>width/8) {
noStroke();
fill(mouseX-random(0, 255), mouseY-random(0, 255), mouseY-random(0, 255));
rect(mouseX, mouseY, 10, 10);
}
if (currentFigure==”triangle”&&mouseX>width/8) {
noStroke();
fill(mouseX-random(0, 255), mouseY-random(0, 255), mouseY+random(0, 255));
triangle(mouseX, mouseY, mouseX-5, mouseY+10, mouseX+5, mouseY+10);
}
if (currentFigure==”circle”&&mouseX>width/8) {
noStroke();
fill(mouseX-random(0, 255), mouseY-random(0, 255), mouseY-random(0, 255));
ellipse(mouseX, mouseY, 10, 10);
}
if (currentFigure==”line”&&mouseX>width/8) {
stroke(mouseX-random(0, 255), mouseY-random(0, 255), mouseY+random(0, 255));
line(pmouseX, pmouseY, mouseX, mouseY);
}
}

void mouseReleased() {

currentFigure = chooseFigure(mouseX, mouseY);
}