public
Last active

Slit-Scan from Form+Code in Art, Design, and Architecture; Cinder version fork

  • Download Gist
SlitScanCamCinder.cpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/**
* Forked by Forrest Oliphant, http://sembiki.com/
* Simplified from:
*
* Transform: Slit-Scan from Form+Code in Art, Design, and Architecture
* implemented in C++ by Patrick Tierney <http://ptierney.com>
*
* Requires Cinder 0.8.2 available at http://libcinder.org
*
* Project files are located at https://github.com/hlp/form-and-code
*
* For more information about Form+Code visit http://formandcode.com
*/
 
#include "cinder/app/AppBasic.h"
#include "cinder/Surface.h"
#include "cinder/Capture.h"
#include "cinder/gl/gl.h"
#include "cinder/gl/Texture.h"
 
using namespace ci;
 
class Transform_SlitScan : public ci::app::AppBasic {
public:
void prepareSettings(Settings* settings);
void setup();
void update();
void draw();
private:
Capture capture;
Surface inSurface;
Surface outSurface;
int video_width;
int video_height;
int video_slice_x;
int window_width;
int window_height;
int draw_position_x;
bool newFrame;
};
 
void Transform_SlitScan::prepareSettings(Settings* settings) {
video_width = 320;
video_height = 240;
video_slice_x = video_width / 2;
window_width = 1000;
window_height = video_height;
draw_position_x = 0;
newFrame = false;
outSurface = Surface(window_width, window_height, ci::SurfaceChannelOrder::RGB);
settings->setWindowSize(window_width, window_height);
}
 
void Transform_SlitScan::setup() {
try {
capture = ci::Capture(video_width, video_height);
capture.start();
} catch (...) {
// if we threw in the start close the program
ci::app::console() << "Unable to open webcam." << std::endl;
exit(1);
}
if (capture.getWidth() != video_width || capture.getHeight() != video_height) {
ci::app::console() << "Unable to open webcam at desired size." << std::endl;
exit(1);
}
}
 
void Transform_SlitScan::update() {
newFrame = false;
if (!capture || !capture.checkNewFrame())
return;
newFrame = true;
inSurface = capture.getSurface();
outSurface.copyFrom(inSurface, Area( video_slice_x, 0, video_slice_x+1, video_height ), Vec2i( draw_position_x - video_slice_x, 0 ) );
}
 
void Transform_SlitScan::draw() {
if (!newFrame)
return;
draw_position_x++;
if (draw_position_x >= window_width)
draw_position_x = 0;
if( outSurface )
gl::draw( gl::Texture( outSurface ) );
}
 
CINDER_APP_BASIC(Transform_SlitScan, ci::app::RendererGl)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.