Can't figure out loop
in
Programming Questions
•
1 year ago
Hey Guys,
So I've been working on creating a drawing tool and I have it all laid out. However I am having trouble creating a mousePressed button to change the drawing tool. For example
I have 4 buttons that are suppose to do different things
button1- regular line tool
button 2- change colors depending where the mouse is on the screen
button 3- mousepressed ellipse tool
button 4- mousepressed square tool.
Here is my code for you =]
//******CANVAS******//
int xMin = 15; // position-left
int xMax = 450; // position of the canvas from-right
int yMin = 50; // position-top
int yMax = 420; // position-bottom
//******First Square Button******//
float x=20;
float y=10;
float w=30;
float h=30;
boolean button1=false;
//******Second Square Button******//
float sx2=120;
float sy2=10;
float sw2=30;
float sh2=30;
//******Ellipse Button******//
float ellix=240;
float elliy=25;
float elliw=30;
float ellih=30;
//******Third Button******//
float sx3=340;
float sy3=10;
float sw3=30;
float sh3=30;
//******Clear Button******//
float sx4=470;
float sy4=470;
float sw4=20;
float sh4=20;
boolean button=false;
void setup() {
//*canvas dimensions*//
size(500, 500);
background(149,87,5);
noStroke();
rect(xMin, yMin, width - 2*xMin, height - 2*yMin);
}
//******VOID DRAW PLACEMENT******//
void draw(){
//drawWorkSpace();
drawImageSquare();
drawImageSquaretwo();
drawImageEllipse();
drawImageSquareThree();
drawImageSquareClear();
}
//******CANVAS******//
//void drawWorkSpace(){
// stroke(0);
//strokeWeight(2);
//smooth();
//if ((mouseX > xMin) && (mouseX < xMax)) {
//if ((mouseY > yMin) && (mouseY < yMax)) {
//if (mousePressed) {
//line(pmouseX, pmouseY, mouseX, mouseY);
//}
//}
//}
//}
//****** FIRST SQUARE Button ******//
void drawImageSquare(){
rect(x,y,w,h);
fill(255);
rect(x,y,w,h);
//fill(255);
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && mousePressed) {
button1 = true;
} else {
button1 = false;
}
if (button1=mousePressed) {
stroke (255);
fill (67,255,244);
ellipseMode(CENTER);
ellipse (mouseX,mouseY,16,16);
}
//******Second Button******//
}
void drawImageSquaretwo(){
rect(sx2,sy2,sw2,sh2);
fill(255);
//mousePressed goes here
}
//****** Ellipse Button ******//
void drawImageEllipse(){
ellipse(ellix,elliy,elliw,ellih);
fill(255);
//mousePressed goes here
}
//****** Third Button ******//
void drawImageSquareThree(){
rect(sx3,sy3,sw3,sh3);
fill(255);
//mousePressed goes here
}
//****** Clear Button******//
void drawImageSquareClear(){
rect(sx4,sy4,sw4,sh4);
fill(255);
if (mouseX > sx4 && mouseX < sx4+sw4 && mouseY > sy4 && mouseY < sy4+sh4 && mousePressed) {
button = true;
} else {
button = false;
}
if (button) {
fill(random(255),random(255),random(255));
rect(xMin, yMin, width - 2*xMin, height - 2*yMin);
stroke(0);
} else {
stroke(0);
}
fill(255);
rect(sx4,sy4,sw4,sh4);
}
Basically I've been playing around with the //*******FIRST SQUARE BUTTON******// just to combine the mousepress and buttonPressed. I also need to put a constrain in to stay within the parameters of the canvas. I figured once I figure out how to connect the first button, than I can play with the other three. If someone can help me that will be great. I have so much code that it's confusing me. I know what I want to say but I don't know how.
Thanks in advance, if someone can stir me in the right direction for my first button.
So I've been working on creating a drawing tool and I have it all laid out. However I am having trouble creating a mousePressed button to change the drawing tool. For example
I have 4 buttons that are suppose to do different things
button1- regular line tool
button 2- change colors depending where the mouse is on the screen
button 3- mousepressed ellipse tool
button 4- mousepressed square tool.
Here is my code for you =]
//******CANVAS******//
int xMin = 15; // position-left
int xMax = 450; // position of the canvas from-right
int yMin = 50; // position-top
int yMax = 420; // position-bottom
//******First Square Button******//
float x=20;
float y=10;
float w=30;
float h=30;
boolean button1=false;
//******Second Square Button******//
float sx2=120;
float sy2=10;
float sw2=30;
float sh2=30;
//******Ellipse Button******//
float ellix=240;
float elliy=25;
float elliw=30;
float ellih=30;
//******Third Button******//
float sx3=340;
float sy3=10;
float sw3=30;
float sh3=30;
//******Clear Button******//
float sx4=470;
float sy4=470;
float sw4=20;
float sh4=20;
boolean button=false;
void setup() {
//*canvas dimensions*//
size(500, 500);
background(149,87,5);
noStroke();
rect(xMin, yMin, width - 2*xMin, height - 2*yMin);
}
//******VOID DRAW PLACEMENT******//
void draw(){
//drawWorkSpace();
drawImageSquare();
drawImageSquaretwo();
drawImageEllipse();
drawImageSquareThree();
drawImageSquareClear();
}
//******CANVAS******//
//void drawWorkSpace(){
// stroke(0);
//strokeWeight(2);
//smooth();
//if ((mouseX > xMin) && (mouseX < xMax)) {
//if ((mouseY > yMin) && (mouseY < yMax)) {
//if (mousePressed) {
//line(pmouseX, pmouseY, mouseX, mouseY);
//}
//}
//}
//}
//****** FIRST SQUARE Button ******//
void drawImageSquare(){
rect(x,y,w,h);
fill(255);
rect(x,y,w,h);
//fill(255);
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && mousePressed) {
button1 = true;
} else {
button1 = false;
}
if (button1=mousePressed) {
stroke (255);
fill (67,255,244);
ellipseMode(CENTER);
ellipse (mouseX,mouseY,16,16);
}
//******Second Button******//
}
void drawImageSquaretwo(){
rect(sx2,sy2,sw2,sh2);
fill(255);
//mousePressed goes here
}
//****** Ellipse Button ******//
void drawImageEllipse(){
ellipse(ellix,elliy,elliw,ellih);
fill(255);
//mousePressed goes here
}
//****** Third Button ******//
void drawImageSquareThree(){
rect(sx3,sy3,sw3,sh3);
fill(255);
//mousePressed goes here
}
//****** Clear Button******//
void drawImageSquareClear(){
rect(sx4,sy4,sw4,sh4);
fill(255);
if (mouseX > sx4 && mouseX < sx4+sw4 && mouseY > sy4 && mouseY < sy4+sh4 && mousePressed) {
button = true;
} else {
button = false;
}
if (button) {
fill(random(255),random(255),random(255));
rect(xMin, yMin, width - 2*xMin, height - 2*yMin);
stroke(0);
} else {
stroke(0);
}
fill(255);
rect(sx4,sy4,sw4,sh4);
}
Basically I've been playing around with the //*******FIRST SQUARE BUTTON******// just to combine the mousepress and buttonPressed. I also need to put a constrain in to stay within the parameters of the canvas. I figured once I figure out how to connect the first button, than I can play with the other three. If someone can help me that will be great. I have so much code that it's confusing me. I know what I want to say but I don't know how.
Thanks in advance, if someone can stir me in the right direction for my first button.
1