Initial concept

Untitled

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.

Testing out changing pixels

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.

Getting the pixel index based on the mouseX/Y position

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

A very messy sketch to offload my brain’s processing power

Getting the pixel area instead of single pixel

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.

The blur effect