Skip to content

Instantly share code, notes, and snippets.

@motoishmz
Created October 7, 2013 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motoishmz/6870570 to your computer and use it in GitHub Desktop.
Save motoishmz/6870570 to your computer and use it in GitHub Desktop.
#include "ofMain.h"
class ofApp : public ofBaseApp
{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
ofImage img;
};
void ofApp::setup()
{
ofSetFrameRate(3);
ofSetVerticalSync(true);
ofSetWindowShape(500, 500);
img.allocate(500, 500, OF_IMAGE_GRAYSCALE);
img.update();
}
void ofApp::update()
{
unsigned char * pixels = img.getPixels();
// 1D loop
for (int i=0; i<img.width * img.height; i++)
{
// pixels[i] = 120;
pixels[i] = ofRandom(ofMap(ofGetMouseX(), 0, ofGetWidth(), 0, 255));
}
// 2D loop
// for (int x=0; x<img.width; x++)
// {
// for (int y=0; y<img.height; y++)
// {
//
// float dist = ofDist(mouseX, mouseY, x, y);
// //pixels[y * img.width + x] = dist;
// //pixels[y * img.width + x] = ofRandom(ofMap(ofGetMouseX(), 0, ofGetWidth(), 0, 255));
// //pixels[y * img.width + x] = sin(ofGetElapsedTimef()) * 100 * x;
// //pixels[y * img.width + x] = tan(ofGetElapsedTimef() * x * y) * 10;
// }
// }
img.update();
}
void ofApp::draw()
{
img.draw(0,0);
}
void ofApp::keyPressed(int key)
{
}
//========================================================================
int main(){
ofSetupOpenGL(1024,768, OF_WINDOW);
ofRunApp( new ofApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment