Skip to content

Instantly share code, notes, and snippets.

@maxhawkins
Created January 10, 2011 23:41
Show Gist options
  • Save maxhawkins/773713 to your computer and use it in GitHub Desktop.
Save maxhawkins/773713 to your computer and use it in GitHub Desktop.
LibCinder copy of Georg Nees's classic media art piece Schotter.
#include "cinder/app/AppBasic.h"
#include "cinder/gl/gl.h"
#include "cinder/Rand.h"
using namespace ci;
using namespace ci::app;
using namespace std;
const Vec3f DrawingOffset = Vec3f(50, 50, 0);
const Vec2f DrawingDimensions = Vec2f(12, 23);
const Vec3f CubeSize = Vec3f(25, 25, 0);
const float MaxOffsetJitter = 1;
const float MaxRotationJitter = 10;
class SchotterApp : public AppBasic {
public:
void prepareSettings( Settings *settings );
void draw();
void mouseDown( MouseEvent event );
private:
int m_seed;
};
void SchotterApp::mouseDown( MouseEvent event )
{
m_seed++;
}
void SchotterApp::prepareSettings( Settings *settings )
{
settings->setWindowSize(DrawingOffset.x * 2 + (DrawingDimensions.x - 1) * CubeSize.x, DrawingOffset.y * 2 + (DrawingDimensions.y - 1) * CubeSize.y);
settings->setTitle("Faux Schotter");
settings->setResizable(false);
}
void SchotterApp::draw()
{
Rand::randSeed(m_seed);
gl::clear( Color::white() );
gl::color( Color::black() );
for (int x = 0; x < DrawingDimensions.x; x++) {
for (int y = 0; y < DrawingDimensions.y; y++) {
gl::pushMatrices();
int cubeNumber = y * CubeSize.y + x;
float jitterFactor = (float) cubeNumber / (DrawingDimensions.x + DrawingDimensions.y);
Vec3f center(x * CubeSize.x, y * CubeSize.y, 0 * CubeSize.z);
center += DrawingOffset;
Vec3f offsetJitter = Rand::randVec3f() * jitterFactor * MaxOffsetJitter;
offsetJitter.z = 0;
center += offsetJitter;
gl::translate(center);
float rotationJitter = (Rand::randFloat() - 0.5) * jitterFactor * MaxRotationJitter ;
gl::rotate(rotationJitter);
gl::drawStrokedCube( Vec3f::zero(), CubeSize );
gl::popMatrices();
}
}
}
CINDER_APP_BASIC( SchotterApp, RendererGl )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment