Created
June 25, 2017 15:25
-
-
Save behreajj/89a8f04279fe318926ff6f705b772ea9 to your computer and use it in GitHub Desktop.
Color Gradients 1-7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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