‹ pakt26pakt28 ›

pakt27

See /software/p5js/pakt-februari/pakt27/ for a JavaScript version and /software/supercollider/februari-pakt/pakt27/ 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 pakt27App : public App {
public:
    void setup();
    void draw();
    cairo::SurfaceImage srfOff;
    cairo::Context ctxOff;
    int index;
    float w, h;
    int n;
};
void pakt27App::setup() {
    srfOff= cairo::SurfaceImage(WIDTH, HEIGHT, false);
    ctxOff= cairo::Context(srfOff);
    n= 80;
    index= 0;
    w= getWindowWidth()*0.5f;
    h= getWindowHeight()*0.5f;
}
void pakt27App::draw() {
    cairo::Context ctx(cairo::createWindowSurface());
    ctxOff.setSourceRgba(0, 0, 0, 0.2f);
    ctxOff.paint();
    for(int i= 0; i<n; i++) {
        float t= float(i)/n*M_PI*2;
        ctxOff.setSource(ColorA(CM_HSV, sin(t)*0.15f+0.15f, 1.0f, 1.0f, 0.4f));
        float c= (sin(index*0.036f+t)+cos(index*0.022f-t))*0.01f;
        float d= (cos(index*0.033f+t)+sin(index*0.020f-t))*0.01f;
        float r= sin(t)*25.0f+30.0f;
        ctxOff.circle(w+(sin((index*(d*0.05f))+c+t)*(w*0.8f)), h+(cos((index*(c*0.05f))+d+t)*(h*0.7f)), r);
        ctxOff.fill();
    }
    index++;
    ctx.copySurface(srfOff, srfOff.getBounds());
}
CINDER_APP(pakt27App, Renderer2d, [&]( App::Settings *settings ) {
    settings->setWindowSize( WIDTH, HEIGHT );
    settings->setResizable( false );
})