Buttons/Drawing Shapes question(s)
in
Programming Questions
•
2 years ago
Ok so I'm trying to create an application that works some what like a program like paint. Except mostly involving the shape drawing aspects. I 've worked out how to draw shapes using pressed and release using this code: (so that you hold down the mouse and it draws the shape to where you release the mouse).
float x,y;
void setup(){
size(400, 400);
}
void draw(){
}
void mousePressed(){
x = mouseX;
y = mouseY;
}
void mouseReleased(){
rectMode(CORNERS);
rect(x,y,mouseX,mouseY);
}
What I want to know is how I can toggle what shape you are using with buttons. Eg I want to have rectangle, ellipse, triangle and line options. So when you select that tool you can only draw that shape. So far my attempts using buttons have ended miserably. So how would I set a button so that when clicked it uses the code for that shape. I'm beginning to think the above code will not work/ or need changes if I want to do this.
Buttons will just be the shape they relate to etc.
It would be cool to have like a temporary shape that draws with the mouse being held down to show where you are dragging, and then I also want the shapes to be filled with text rather than a fill when you draw them, but we can deal with all that later. Baby steps.
Thanks in advance!
Jonathan
float x,y;
void setup(){
size(400, 400);
}
void draw(){
}
void mousePressed(){
x = mouseX;
y = mouseY;
}
void mouseReleased(){
rectMode(CORNERS);
rect(x,y,mouseX,mouseY);
}
What I want to know is how I can toggle what shape you are using with buttons. Eg I want to have rectangle, ellipse, triangle and line options. So when you select that tool you can only draw that shape. So far my attempts using buttons have ended miserably. So how would I set a button so that when clicked it uses the code for that shape. I'm beginning to think the above code will not work/ or need changes if I want to do this.
Buttons will just be the shape they relate to etc.
It would be cool to have like a temporary shape that draws with the mouse being held down to show where you are dragging, and then I also want the shapes to be filled with text rather than a fill when you draw them, but we can deal with all that later. Baby steps.
Thanks in advance!
Jonathan
1