For this assignment, I initially wanted to make a smudge tool. In terms of pseudocode, I would get the mouse X and Y positions on drag, and apply the pixels from the previous mouse X/Y position to the new X & Y position.
Screen Recording 2023-10-31 at 8.00.13 PM.mov
After importing an image and loading pixels, I tested out changing some pixels on mousepress.
This is the part that was the most challenging/mind-boggling:
let arrPosX = mouseX * 4;
let arrPosY = (mouseY * (img.width * 4));
let arrPos = arrPosX + arrPosY;
A very messy sketch to offload my brain’s processing power
Now that I’ve gotten a pixel’s position based on the mouse position, I needed to also get pixels that surround this pixel.
let allowance = 4 //Retrieve 4 pixels around the centre pixel
for (let x = arrPosX - allowance *4; x <= arrPosX + allowance*4; x += 4) {
for (let y = arrPosY - (allowance * img.width * 4); y <= arrPosY + (allowance * img.width *4); y += (img.width*4)) {
img.pixels[x+y] = 255;
img.pixels[x+y+1] = 255;
img.pixels[x+y+2] = 255;
}
}
When mouse is pressed, the pixels around the 4x4 radius turns white.
When mouse is pressed, the pixels around the 4x4 radius turns white.