I’m trying to make a drawing program with a tool bar, buttons, and a canvas. So far I got a lot done with help from everyone here on this forum, however, when I try click on the 2 line of my 3 line button, it draws the line with little circles, and draws outside of the canvas. Can someone help me figure out how to make it so that when I click on the 3 lines the stroke weight of the drawing line changes from 1, 4 and 7, and only draws within the canvas?
// class-less version
// Please note that I used heavy inspiration and help from this users own drawing program to create my own: https://www.openprocessing.org/sketch/26614/ by Basil Vendryes
// The folowing program is a very simple drawing program. You can press you mouse key and you will be able to draw a line that follows the mouse.
// You can also change the color of the line, and clear the canvas instantly.
// You can also press any key on your keyboard and be able to draw an contiuous stream of circles.
float x;
float y;
color red = color(255, 0, 0);
color green= color(0, 255, 0);
color blue= color(0, 0, 255);
color yellow= color(247, 240, 0);
color orange= color(247, 112, 0);
color violet= color(110, 0, 220);
color blueGreen= color(0, 247, 146);
color yellowGreen= color(157, 250, 0);
color pink= color(255, 28, 97);
color yellowOrange= color(255, 159, 3);
color white= color(255);
color black= color(0);
color rand = color(random(255));
float drawX;
float drawY;
float mainStroke= 1;
void setup() {
size(2000, 2000);
smooth();
background(200);
//the border for the canvas
fill(255);
strokeWeight(4);
rect(500, 400, 1000, 1300);
rect(0, 0, 200, 500);
rect(0, 0, 1800, 200);
}
void draw() {
// stroke(0);
// strokeWeight(1);
colors();
canvas();
//I will make the options for different sizes to draw and the clearing option for the canavas as a rectangle
line(1550, 30, 1650, 30);
strokeWeight(4);
line(1550, 50, 1650, 50);
strokeWeight(8);
line(1550, 80, 1650, 80);
strokeWeight(3);
fill(255);
rect(900, 10, 50, 50);
circleOpt(mouseX, mouseY);
}
void colors() {
//The following code is used to make the boxes for my colors and the drawings stroke if clicked
strokeWeight(1);
fill(red);
rect(10, 10, 50, 50 );
strokeWeight(1);
fill(orange);
rect(60, 10, 50, 50 );
strokeWeight(1);
fill(yellowOrange);
rect(10, 60, 50, 50 );
strokeWeight(1);
fill(yellow);
rect(60, 60, 50, 50 );
strokeWeight(1);
fill(yellowGreen);
rect(10, 110, 50, 50 );
strokeWeight(1);
fill(green);
rect(60, 110, 50, 50 );
strokeWeight(1);
fill(blueGreen);
rect(10, 160, 50, 50 );
strokeWeight(1);
fill(blue);
rect(60, 160, 50, 50 );
strokeWeight(1);
fill(violet);
rect(10, 210, 50, 50 );
strokeWeight(1);
fill(pink);
rect(60, 210, 50, 50 );
strokeWeight(1);
fill(white);
rect(10, 260, 50, 50 );
strokeWeight(1);
fill(black);
rect(60, 260, 50, 50 );
strokeWeight(1);
fill(rand);
rect(10, 310, 50, 50 );
}
//This is the function for my circle drawing tool, when any key is pressed, a circle will be drawn
void circleOpt(float x, float y) {
if (keyPressed) {
ellipse(x, y, 50, 50);
}
}
//This coding allows the drawing lines color to be altered when one of the sqaures of color is pressed
void colorPick() {
if (mousePressed) {
if (mouseX > 10 && mouseX < 60) {
if (mouseY >10 && mouseY < 60) {
stroke(red);
}
if (mouseY>60 && mouseY < 110) {
stroke(yellowOrange);
}
if (mouseY>110 && mouseY<160) {
stroke(yellowGreen);
}
if (mouseY>160 && mouseY<210) {
stroke(blueGreen);
}
if (mouseY>210 && mouseY<265) {
stroke(violet);
}
if (mouseY>265 && mouseY<315) {
stroke(white);
}
if (mouseY>315 && mouseY<365) {
stroke(rand);
}
}
if (mouseX > 60 && mouseX < 110) {
if ( mouseY > 10 && mouseY <60) {
stroke(orange);
}
if (mouseY > 60 && mouseY < 110) {
stroke(yellow);
}
if (mouseY > 110 && mouseY < 160) {
stroke(green);
}
if (mouseY >160 && mouseY < 210) {
stroke(blue);
}
if (mouseY > 210 && mouseY <260) {
stroke(pink);
}
if (mouseY >260 && mouseY <310) {
stroke(black);
}
}
if (mousePressed) {
if (mouseX > 1550 && mouseX <1650) {
if (mouseY >10 && mouseY <40) {
mainStroke= 1;
}
}
if (mouseX > 1550 && mouseX <1650) {
if (mouseY >40 && mouseY <70) {
mainStroke= 4;
}
}
if (mouseX > 1550 && mouseX <1650) {
if (mouseY > 70 && mouseY <100) {
mainStroke= 7;
}
}
strokeWeight(mainStroke);
}
if (mousePressed) {
if (mouseX > 900 && mouseX <950) {
if (mouseY > 10 && mouseY <60) {
fill(255);
strokeWeight(4);
rect(500, 400, 1000, 1300);
}
}
}
//if (mousePressed) {
// line(mouseX, mouseY, drawX, drawY);
//}
}
}
void mousePressed() {
drawX=mouseX;
drawY=mouseY;
}
//The following function makes the colorPick(); fucntion draw within the rectangle made in setup
void canvas() {
if (mouseX>500 && mouseX<1500) {
if (mouseY>400 && mouseY<1700) {
if (mousePressed) {
line(mouseX, mouseY, drawX, drawY);
drawX=mouseX;
drawY=mouseY;
}
return; // leave
}
}
colorPick();
}//func
//