Skip to content

Instantly share code, notes, and snippets.

@behreajj
Created June 25, 2017 15:25
Show Gist options
  • Save behreajj/89a8f04279fe318926ff6f705b772ea9 to your computer and use it in GitHub Desktop.
Save behreajj/89a8f04279fe318926ff6f705b772ea9 to your computer and use it in GitHub Desktop.
Color Gradients 1-7
size(512, 256);
loadPixels();
int len = pixels.length;
float h = float(height);
float w = float(width);
float diamonds = TWO_PI * 8;
float red;
float green;
float blue;
boolean rule;
for (int y = 0, i = 0; y < height; ++y) {
for (int x = 0; x < width; ++x, ++i) {
rule = cos(y / h * diamonds)
< cos(x / w * diamonds);
if (rule) {
red = map(x, 0, w, 54, 255);
green = map(y, 0, h, 0, 54);
blue = map(i, 0, len, 255, 127);
} else {
red = map(x, 0, w, 255, 0);
green = map(y, 0, h, 127, 255);
blue = map(i, 0, len, 127, 54);
}
pixels[i] = color(red, green, blue);
}
}
updatePixels();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment