PImage image1;
int w, h;
float oldRed, oldGreen, oldBlue, average;
float newRed, newGreen, newBlue;
color oldColour, newColour;
image1 = loadImage(“C:/Users/SFogo93/Desktop/Dock.jpg”);
w = image1.width;
h = image1.height;
size(w, h);
print(“Image resolution: width ” + w + ” * height ” + h);
for (int i = 0; i < w; i++)
{
for (int j = 0; j < h; j++)
{
oldColour = image1.get(i, j);
oldRed = red(oldColour);
oldGreen = green(oldColour);
oldBlue = blue(oldColour);
if (j <= h/2 && i <= w/2) // Quadrant 1
{
newRed = random(255);
newGreen = oldGreen;
newBlue = oldBlue;
}
else if (j <= h/2 && i >= w/2) // Quadrant 2
{
newRed = 255 – oldRed;
newGreen = 255 – oldGreen;
newBlue = 255 – oldBlue;
}
else if (j >= h/2 && i <= w/2) // Quadrant 3
{
newRed = oldRed;
newGreen = oldGreen – 50;
newBlue = oldBlue;
}
else // Quadrant 4
{
newRed = (oldRed * .393 + oldGreen * .769 + oldBlue * .189);
newGreen = (oldRed * .349 + oldGreen * .686 + oldBlue * .168);
newBlue = (oldRed * .272 + oldGreen * .534 + oldBlue * .131);
}
if (newRed > 255) newRed = 255;
if (newGreen > 255) newGreen = 255;
if (newBlue > 255) newBlue = 255;
if (newRed < 0) newRed = 0;
if (newGreen < 0) newGreen = 0;
if (newBlue < 0) newBlue = 0;
newColour = color(newRed, newGreen, newBlue);
image1.set(i, j, newColour);
}
}
image(image1, 0, 0, w, h);
