Skip to content

Instantly share code, notes, and snippets.

@companje
Created May 21, 2012 19:12
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 companje/2764047 to your computer and use it in GitHub Desktop.
Save companje/2764047 to your computer and use it in GitHub Desktop.
test from sublimetext2
testApp.cpp
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
w = ofGetWidth();
h = ofGetHeight();
cam.initGrabber(w,h,true);
pdf = new ofxCairo();
saving = false;
size = 4;
step = 7;
ofSetFrameRate(30);
ofBackground(255,255,255);
ofSetWindowTitle("move mouse for changing detail, press 's' to save");
}
//--------------------------------------------------------------
void testApp::update(){
cam.update();
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetColor(255,255,255);
//if saving mode is on begin PDF writing
if (saving) {
filename = ofToString(ofRandomuf()) + ".pdf";
pdf->begin(filename, w, h, OF_OUTPUT_PDF);
}
//distance between circles and their size depends on mouse pos
size = ofMap(mouseX,0,ofGetWidth(),1,10);
step = ofMap(mouseY,0,ofGetHeight(),10,3);
for (int y=0; y<h; y+=step) {
for (int x=0; x<w; x+=step) {
//get pixel color from camera
int i = (y*w+x)*3;
int r = cam.getPixels()[i+0];
int g = cam.getPixels()[i+1];
int b = cam.getPixels()[i+2];
//calculate brightness
float bri = (r+g+b) / 765.0;
//draw black circles
pdf->setColor(0);
pdf->circle(x,y,(1-bri)*size);
}
}
//if saving mode was on finish pdf writing and open preview
if (saving) {
pdf->end();
delete pdf;
pdf = new ofxCairo();
saving = false;
system(("open " + ofToDataPath(filename)).c_str());
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
//press s to enter saving mode
if (key=='s') saving=true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment