Last active
May 19, 2017 11:49
-
-
Save grifdail/b561ff42d461057978f4f33da6836b0e to your computer and use it in GitHub Desktop.
Use a color to create a gradient
This file contains 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
class TextureGradient { | |
public color[] pixels; | |
TextureGradient(String name) { | |
PImage background = loadImage(name); | |
background.loadPixels(); | |
pixels = background.pixels; | |
} | |
color get(float t) { | |
int currentMode = g.colorMode; | |
colorMode(RGB); | |
t*=pixels.length; | |
color tMin = pixels[max(min(int(t),pixels.length-1),0)]; | |
color tMax = pixels[min(int(t+1),pixels.length-1)]; | |
color result = lerpColor(tMin, tMax, t%1); | |
colorMode(currentMode); | |
return result; | |
} | |
color getLinear(float t) { | |
t*=backgroundColors.length; | |
return pixels[max(min(int(t),pixels.length-1),0)]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment