Help with drawing app
in
Programming Questions
•
2 years ago
I'm making a simple drawing application, currently I can click and draw lines and i have drawn my color palettes (just ellipses). I want to know how I can get the cursor to click on them so it will change the color of the line accordingly. If anyone can help I'd greatly appreciate it. Code is below.
//Variables
int y = 20;
void setup()
{
//Set the size of the sketch
size(500, 500);
//Set the background color
background(255);
smooth();
}
void draw()
{
//Draw background of toolbar
fill(150);
strokeWeight(1);
rect (-1, -1, 125, 250);
fill(150);
strokeWeight(1);
rect (-1, 249, 125, 251);
//Draw color selections
stroke(0);
strokeWeight(2);
fill(183,24,24);
ellipse (20, 20, 25, 25);
fill(255,13,13);
ellipse (60, 20, 25, 25);
fill(240,41,157);
ellipse (100, 20, 25, 25);
fill(236,41,240);
ellipse (20, 60, 25, 25);
fill(169,41,240);
ellipse (60, 60, 25, 25);
fill(116,41,240);
ellipse (100, 60, 25, 25);
fill(24,22,240);
ellipse (20, 100, 25, 25);
fill(22,194,240);
ellipse (60, 100, 25, 25);
fill(22,240,187);
ellipse (100, 100, 25, 25);
fill(51,229,52);
ellipse (20, 140, 25, 25);
fill(225,245,79);
ellipse (60, 140, 25, 25);
fill(255,244,31);
ellipse (100, 140, 25, 25);
fill(255,157,52);
ellipse (20, 180, 25, 25);
fill(234,210,147);
ellipse (60, 180, 25, 25);
fill(131,114,70);
ellipse (100, 180, 25, 25);
fill (255);
ellipse (20, 220, 25, 25);
fill (175);
ellipse (60, 220, 25, 25);
fill (0);
ellipse (100, 220, 25, 25);
//Draw line thickness selections
ellipse (60, 295, 5, 5);
ellipse (60, 325, 10, 10);
ellipse (60, 360, 15, 15);
ellipse (60, 400, 25, 25);
ellipse (60, 450, 35, 35);
stroke(0);
strokeWeight(5);
if(mousePressed)
{
line(mouseX, mouseY, pmouseX, pmouseY);
}
}
1