‹ pakt25pakt27 ›

pakt26

See /software/p5js/pakt-februari/pakt26/ for a JavaScript version and /software/supercollider/februari-pakt/pakt26/ 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 pakt26App : public App {
public:
    void setup();
    void draw();
    cairo::SurfaceImage srfOff;
    cairo::Context ctxOff;
    int index;
    float w, h;
    float rx, ry;
    int nx, ny;
    float cols, rows;
};

void pakt26App::setup() {
    srfOff= cairo::SurfaceImage(WIDTH, HEIGHT, false);
    ctxOff= cairo::Context(srfOff);
    nx= 45;
    ny= 9;
    index= 0;
    w= getWindowWidth();
    h= getWindowHeight();
    rows= ny;
    ry= h/rows;
}

void pakt26App::draw() {
    
    cols= (sin(index*0.001f+(sin(index*0.0001f)*10.0f))*0.445f+0.5f)*(nx-1);
    rx= w/cols;
    
    cairo::Context ctx(cairo::createWindowSurface());
    ctxOff.setSourceRgba(0, 0, 0, 0.06);
    ctxOff.paint();
    
    for(int x= 0; x<cols; x++) {
        for(int y= 0; y<rows; y++) {
            float c= sin((index+(x*rows)+y)*cos(index*0.0012f)*(sin(index*0.00006f)*0.5f))*0.5f+0.5f;
            float g= c*(sin(index*0.002f+(float(x)/nx*2*M_PI))*cos(index*0.0018f+(float(y)/ny*2*M_PI)))*12.0f+9.0f;
            ctxOff.setSource(ColorA(1.0f, c, c, c));
            ctxOff.rectangle(x*rx+g, y*ry+g, rx-(g*2), ry-(g*2));
            ctxOff.fill();
        }
    }
    index++;
    ctx.copySurface(srfOff, srfOff.getBounds());
}

CINDER_APP(pakt26App, Renderer2d, [&]( App::Settings *settings ) {
    settings->setWindowSize( WIDTH, HEIGHT );
    settings->setResizable( false );
})