Creating something like MS Paint
in
Programming Questions
•
1 year ago
I am in the process of creating something like MS Paint where the use can click on a color and draw small ellipses using that color. It only works for the last color (blue)..
- boolean drawing = false;
// setup - runs one time
void setup()
{
// set a stage size of 500 x 500 pixels
size (500,500);
// smooth all drawing
smooth();
// don't draw an outline around your shapes
noStroke();
}
// draw - runs once a frame
void draw()
{
// draw a color button
fill (255,0,0);
rect(0,0,100,50);
fill (0,255,0);
rect(100,0,100,50);
fill (0,0,255);
rect(200,0,100,50);
// are we in draw mode?
if (drawing == true)
{
ellipse(mouseX, mouseY, 30, 30);
}
}
// mousePressed - runs every time the mouse is pressed
void mousePressed()
{
// did we click the button?
if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 50)
{
fill (255,0,0);
}
if (mouseX > 100 && mouseX < 200 && mouseY > 0 && mouseY < 50)
{
fill (0,255,0);
}
if (mouseX > 200 && mouseX < 300 && mouseY > 0 && mouseY < 50)
{
fill (0,0,255);
}
// otherwise we are in draw mode
else
{
drawing = true;
}
}
void mouseReleased()
{
drawing = false;
}
1