Skip to content

Instantly share code, notes, and snippets.

@lewkoo
Created January 20, 2014 23:52
Show Gist options
  • Save lewkoo/8531743 to your computer and use it in GitHub Desktop.
Save lewkoo/8531743 to your computer and use it in GitHub Desktop.
Naive gradient creation with OpenFrameworks
//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