xxxxxxxxxx
var myImage; // Declare image variable name
var brush;
var btn;
var btnEnableDrawing;
var isManualModeEnabled;
var x;
var y;
function preload() {
myImage = loadImage("sherlock.jpg"); // Load the image from openprocessing into myImage variable
brush = loadImage("whitebrush.png");
}
function setup() {
// Creates the application window params: width=600, height=750
createCanvas(600, 750);
btn = createButton('Clear Canvas');
btn.position(0, 0);
btn.mousePressed(btnPressed);
btnEnableDrawing = createButton('Enable Manual Mode');
btnEnableDrawing.position(100, 0);
btnEnableDrawing.mousePressed(btnPressedManualMode);
isManualModeEnabled = false;
}
function btnPressedManualMode() {
if(isManualModeEnabled == false) {
isManualModeEnabled = true;
btnEnableDrawing.html('Enable Automatic Mode');
}
else if(isManualModeEnabled == true) {
isManualModeEnabled = false;
btnEnableDrawing.html('Enable Manual Mode');
}
}
function btnPressed() {
background(255);
}
function draw() {
//background(255);
// Place loaded myImage variable into the image() function to display it on the canvas
//image(myImage, 0, 0, width, height);
noStroke();
//blendMode(MULTIPLY);
if(isManualModeEnabled == true) {
x = mouseX;
y = mouseY;
}
if(isManualModeEnabled == false) {
x = floor(random(0, myImage.width));
y = floor(random(0, myImage.height));
}
let pix = myImage.get(x, y); // returns the pixel color of the specific x and y coordinate
fill(red(pix), green(pix), blue(pix), 255); // set the fill color from loaded image
// // option 1
var sz = random(4, 20);
//circle(x, y, sz);
// option 2
push();
var randRot = random(-10, 10);
angleMode(DEGREES);
rectMode(CENTER)
fill(red(pix), green(pix), blue(pix), 95); // set the fill color from loaded image
translate(x, y);
rotate(randRot);
rect(30, 0, sz);
pop();
}