Hi @alligatorpears,
The idea is the same as your eraserOn
variable. You simply need to have a way to store the state of your program.
For that, you can add a eyeDropperOn
variable and set it to true when you clicked on the button. Then you handle the color picking in a mouseClicked
event without forgetting to set back the eyeDropperOn
variable to false since the color picking has been done.
Here’s a partial solution. It is not preventing the user to draw while in the color picking mode AND it does not really color pick, it simply write a message in the console:
const outsideColor = [127,127,127];
const bgColor = [0,0,0];
const padding = 50;
let penSize = 1;
let colorPicker;
let jankyBtn;
let tracking = false;
let clickAmnt = 0;
let eraserOn = false;
let eyeDropperOn = false;
function setup() {
createCanvas(750, 700);
let saveBtn = createButton("Save your work of art!");
saveBtn.size(padding*4,padding);
saveBtn.position(0,0);
saveBtn.mousePressed(function() {
save(); // I have it in this form just in case I want to add more code here
});
let resetBtn = createButton("Reset your art!");
resetBtn.size(padding*2,padding);
resetBtn.position(width-padding*2,0);
resetBtn.mousePressed(function() {
background(bgColor); // I have it in this form just in case I want to add more code here
});
let eyeDropper = createButton("Eyedropper");
eyeDropper.size(padding*2,padding);
eyeDropper.position(width-padding*4,0);
eyeDropper.mousePressed(eyeDrop);
let eraserCheckbox = createCheckbox("Eraser", false);
eraserCheckbox.size(padding,padding*2);
eraserCheckbox.position(0,padding);
eraserCheckbox.changed(function() {
eraserOn = this.checked();
});
colorPicker = createColorPicker("white");
colorPicker.size(padding,padding);
colorPicker.position(0,height-padding);
background(bgColor);
}
function draw() {
if (tracking) {
jankyBtn.position(mouseX - 10, mouseY - 10);
if (mouseIsPressed) {
loadPixels();
jankyBtn.hide();
print(pixels[mouseX * mouseY]);
updatePixels();
}
}
let inBounds = (mouseX < width - padding &&
mouseX > padding) &&
(mouseY < height - padding &&
mouseY > padding);
//drawing functionality
strokeWeight(penSize);
stroke(colorPicker.color());
if (mouseIsPressed && inBounds) {
if (eraserOn) {
stroke(bgColor);
}
line(mouseX, mouseY, pmouseX, pmouseY);
}
noStroke();
// border rectangles
fill(outsideColor);
rect(0, 0, padding, height);
rect(0, 0, width, padding);
rect(width - padding, 0, padding, height);
rect(0, height - padding, width, padding);
/*
for preview circle in bottom right,
maybe i'll change this later to just an outlined circle
around the cursor's position
*/
fill(colorPicker.color());
circle((width - (padding / 20) - padding / 2),
(height - (padding / 20) - padding / 2),
(penSize));
}
function clamp(num, min, max) {
return num <= min ? min : num >= max ? max : num;
}
//changing penSize
function mouseWheel(event) {
penSize -= event.delta / 5;
penSize = clamp(penSize, 2, padding);
}
function mouseClicked() {
if(eyeDropperOn) {
print("Get your color here");
eyeDropperOn = false;
}
}
function keyTyped() {
if (key === 'f') {
floodFill();
}
}
function floodFill() {
print("😢😢😢😢");
}
function eyeDrop() {
eyeDropperOn = true;
}