x + width * y
The project is in the space of Diminished Reality and the idea is to be able to create at will distortions in a live image. Hereby, I will first describe what the application does and how it does it and afterwards I will shortly go through the process of getting there.
The way the distortion is applied is by for a short amount of time (time equivalent to 120 frames), around the point a click event happens, circles are being drawn at random points near the area where the click happened. Also, while the frames increase, the radius of the circles decreases to smoothen out the video image.
The process wasn’t so smooth considering that the openFrameworks constraint proved to be of significance. The problem I had at the beginning was how to make a meaningful distortion of a video, but due to my inexperience with programming even using a simple oF library for no reason was an issue that had to be resolved. In the end, I gave up the idea of “styling a distortion” as that seemed as a second stage problem; finally the one I used was the simplest I could think of – the one I explain above – with the circles gradually to be getting smaller.
However, in order to get there I run into a number of problems which I solved by looking at examples, online tutorials or the online documentation/forums etc. The most important problems of that sort were to understand how the pixel array works and how to get the color of the random center of each circle.
Code
main.cpp
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main( ){
ofSetupOpenGL(1280, 720,OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
ofApp.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
cam.setup(1280, 720);
frameCounter = 0;
yparxeiClick = false;
w = 120;
h = 120;
}
//--------------------------------------------------------------
void ofApp::update(){
cam.update();
if (cam.isFrameNew()) {
if (yparxeiClick == true) {
frameCounter++;
w--;
h--;
if (frameCounter == 120) {
yparxeiClick = false;
frameCounter = 0;
w = 120;
h = 120;
}
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255);
cam.draw(0, 0);
ofPixels & camPixels = cam.getPixels();
if (yparxeiClick == true) {
for (int i = 0; i < 700; i++) {
Rx = ofRandom(cX - 120, cX + 120);
Ry = ofRandom(cY - 120, cY + 120);
ofColor c = camPixels.getColor(Rx, Ry);
ofSetColor(c);
ofDrawEllipse(Rx, Ry, w, h);
}
}
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
yparxeiClick = true;
cX = mouseX;
cY = mouseY;
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
ofApp.h
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofVideoGrabber cam;
int cX;
int cY;
int frameCounter;
bool yparxeiClick;
int Rx;
int Ry;
int w;
int h;
};
NMNT penFrameworksLab 2 from George Bouzias on Vimeo.