Drawing tool

I made a simple drawing tool that can be used to make drawings with colorful circles and squares.

PainterTool

INSTRUCTIONS:

R key – activate the rectangle(square) tool

C key – activate the circle tool

Mouse click – start drawing

Mouse press – keep drawing

Mouse release – stop drawing

D key – delete the drawing

 

Here’s the code, try it yourself!

float cornerX, cornerY;
int sizeX = 50;
int sizeY = 50;
float myPosX, myPosY;
boolean confirmClick = false;
boolean backgroundTrace = true;
int randomRed, randomBlue, randomGreen;


void setup(){
  size(1000,800);
  frameRate(100);
  background(0);
}


void draw(){
  circleTool();
  rectangleTool();
  deleteButton();
}

// randomize colors 
 void randomizeColor(){
   randomRed = Math.round(random(255));
   randomGreen = Math.round(random(255));
   randomBlue = Math.round(random(255));
 }

void mouseReleased(){
 randomizeColor();
}


void rectangleMaker(float cornerX, float cornerY, float sizeX, float sizeY){
     fill(randomRed,randomGreen,randomBlue);
     stroke(255);
     strokeWeight(5);
     rect(cornerX, cornerY, sizeX, sizeY);
}

// key press = rectangle
void rectangleTool(){
  if(key == 'r' || key == 'R'){
    if(mousePressed == true){
      //backgroundTrace = false;
      rectangleMaker(mouseX,mouseY, sizeX, sizeY);    
    }
  }
}

//key press = circle
void circleTool(){
  if(key == 'c' || key == 'C'){
    if(mousePressed == true){
      //backgroundTrace = false;
      circleMaker(mouseX,mouseY, sizeX, sizeY);    
    }
  }
}

void circleMaker(float cornerX, float cornerY, float sizeX, float sizeY){
     fill(randomRed,randomGreen,randomBlue);
     stroke(255);
     strokeWeight(5);
   
     ellipse(cornerX, cornerY, sizeX, sizeY);
}

//delete button
void deleteButton(){
  if(key == 'd' || key == 'D'){
    background(0);
  }
}

 

Leave a Reply