Hello everyone I am a beginner and I am trying to make four different drawing tools (one of them is a simple draw tool, i.e. dragging the mouse pointer draws pixels in the selected color; the other three tools could be, for example, a pipette, straight line, rectangle, spray paint, or ellipse tool). One tool or color can be assigned to each of the (left and right) mouse buttons; the default behavior is to draw a pixel with the current foreground color on the left mouse button click and with the current background color on right-click. A tool or color is assigned to the left of right mouse button by clicking on it. I only managed to do the colors and paint but i am stuck at the paint tools.
int cols=2;
int rows=10;
int counter;
int[] button = new int[5];
int col=0;
String saveText ="Save";
color f1 = color(0);
color f2 = color(255);
Cell[][] palette = new Cell[cols][rows];
color[] rectCol = new color[20];
void setup() {
size(500,500);
smooth();
background(255);
mousePressed();
for (int i=0; i<cols; i++) {
for (int j=0; j<rows; j++) {
palette[i][j] = new Cell(i*20,j*20,20,20,2*j + i);
}
}
rectCol[0] = color(0); //black
rectCol[1] = color(255); //white
rectCol[2] = color(46, 11, 11); //brown
rectCol[3] = color(120, 10, 10); // dark red
rectCol[4] = color(255, 0, 0); //red
rectCol[5] = color(250, 71, 74); // light red
rectCol[6] = color(245, 59, 255); //pinkish
rectCol[7] = color(232, 0, 245); // pink
rectCol[8] = color(129, 3, 137); //purple
rectCol[9] = color(55, 55, 250); //light blue
rectCol[10] = color(0, 0, 255); //blue
rectCol[11] = color(0, 0, 150); //dark blue
rectCol[12] = color(95, 247, 101); //light green
rectCol[13] = color(0, 247, 10); //lime green
rectCol[14] = color(0, 103, 4); //dark green
rectCol[15] = color(58, 103, 0); //yellow green
rectCol[16] = color(255, 255, 0); //yellow
rectCol[17] = color(255, 100, 0); //orange
rectCol[18] = color(155); // gray
rectCol[19] = color(55); //grayer
}
void mousePressed(){
// Check mouseX/mouseY against button position/size
// Then if OK, save
rect(420,10,50,30);
fill(255);
textSize(20);
textAlign(CENTER, CENTER);
text(saveText, 421, 7, 50, 30);
if (button[4]==1){
rect(100,100,30,30);
}
if((mouseY<(button[1]+button[3]))&&(mouseY>(button[1]))){
if((mouseX<(button[0]+button[2]))&&(mouseX>(button[0]))){
col=150;
}
}
//counter++;
//String fileName = "savedImage-" + nf(counter, 3) + ".png";
//// Save image here instead
//println(fileName);
}
void draw() {
for (int i=0; i<cols; i++) {
for (int j=0; j<rows; j++) {
palette[i][j].display();
checkMouseOver(palette[i][j]);
}
}
}
void mouseDragged() {
if (mouseButton == LEFT) {
noFill();
stroke(f1);
strokeWeight(20);
strokeJoin(ROUND);
line(mouseX,mouseY,pmouseX,pmouseY);
}
if (mouseButton == RIGHT) {
noFill();
stroke(f2);
strokeWeight(20);
strokeJoin(ROUND);
line(mouseX,mouseY,pmouseX,pmouseY);
}
}
void checkMouseOver(Cell c) {
if (mousePressed) {
if (mouseButton == LEFT && mouseX > c.x && mouseX < c.x+c.w && mouseY > c.y && mouseY < c.y+c.h) {
f1 = (get(mouseX,mouseY));
}else if (mouseButton == RIGHT && mouseX > c.x && mouseX < c.x+c.w && mouseY > c.y && mouseY < c.y+c.h) {
f2 = (get(mouseX,mouseY));
}
}
}
class Cell {
float x,y,w,h;
int c;
Cell (float tempX, float tempY, float tempW, float tempH, int tempC) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
c = tempC;
}
void display() {
stroke(0);
strokeWeight(3);
fill(rectCol[c]);
rect(x,y,w,h);
}
}