Created
January 20, 2014 23:52
-
-
Save lewkoo/8531743 to your computer and use it in GitHub Desktop.
Naive gradient creation with OpenFrameworks
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
//set the image size | |
int imageWidth = 960; | |
int imageHeight = 540; // change these to any integers | |
//instanciate a gradient variable | |
ofImage gradient = ofImage(); | |
gradient.allocate(960,540,OF_IMAGE_COLOR); | |
ofColor leftColor = ofColor::black; //these are your gradient colors | |
ofColor rightColor = ofColor::white; | |
ofColor currColor = ofColor::black; //current color for a giver row in the image | |
//set the image pixels - looping through them sounds like a good idea, eh? | |
for(int pixelsRow = 0; pixelsRow < imageWidth; pixelsRow++) | |
{ | |
float value = ofNormalize(pixelsRow, 0, imageWidth); | |
currColor = leftColor.getLerped(rightColor, value); | |
for(int pixelsHeight = 0; pixelsHeight < imageHeight; pixelsHeight++) | |
{ | |
gradient.setColor(pixelsRow, pixelsHeight, currColor); | |
} | |
} | |
//here, we shall update the texture on the GPU | |
gradient.update(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment