‹ pakt07pakt09 ›

pakt08

See /software/p5js/pakt-februari/pakt08/ for a JavaScript version and /software/supercollider/februari-pakt/pakt08/ for accompanying sound code.

#include "cinder/app/App.h"
#include "cinder/cairo/Cairo.h"
using namespace ci;
using namespace ci::app;
using namespace std;
const int WIDTH= 640;
const int HEIGHT= 480;
class pakt08App : public App {
public:
    void setup();
    void draw();
    int n;
    float w, h;
    float d, speed, spread, theta;
    vector<vec2> points;
};
void pakt08App::setup() {
    n= 25;
    d= 0.0001f;
    speed= 0.00002f;
    spread= 2.0f;
    theta= 0.0f;
    for(int i= 0; i<n; i++) {
        points.push_back(getWindowCenter());
    }
    w= getWindowWidth();
    h= getWindowHeight();
}
void pakt08App::draw() {
    cairo::Context ctx(cairo::createWindowSurface());
    ctx.setFillRule(1);
    ctx.setSourceRgb(0, 0, 0);
    ctx.paint();
    ctx.moveTo(getWindowCenter());
    //ctx.setLineWidth(10.0f);
    ctx.setSourceRgb(1.0f, 0, 0);
    for(size_t i= 0; i<points.size(); i++) {
        float c= cos(theta+(i*d));
        float s= sin(theta+(i*d));
        float x= (points[i].x/w)*2-1;
        float y= (points[i].y/h)*2-1;
        vec2 v= vec2(
                       (((c*x)-(s*y))*0.5+0.5)*w+spread,
                       (((c*y)+(s*x))*0.5+0.5)*h+spread
                       );
        points[i]= v;
        //ctx.circle(v, 50);
        ctx.lineTo(v);
        theta= theta+speed;
    }
    ctx.fill();
}
CINDER_APP(pakt08App, Renderer2d, [&]( App::Settings *settings ) {
    settings->setWindowSize( WIDTH, HEIGHT );
    settings->setResizable( false );
})