‹ pakt28

pakt29

See /software/p5js/pakt-februari/pakt29/ for a JavaScript version and /software/supercollider/februari-pakt/pakt29/ 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 pakt29App : public App {
public:
    void setup();
    void draw();
    int index;
    float w, h;
    int cols, rows;
};

void pakt29App::setup() {
    cols= 20;
    rows= 20;
    index= 0;
    w= getWindowWidth();
    h= getWindowHeight();
}

void pakt29App::draw() {
    
    cairo::Context ctx(cairo::createWindowSurface());
    ctx.setSourceRgb(0, 0, 0);
    ctx.paint();
    
    ctx.setLineCap(1);
    ctx.setLineWidth(20.0);
    float oy= 0.025f*h;
    for(int x= 0; x<cols; x++) {
        float t= float(x)/cols;
        float xx= t*w+(0.5f/cols*w);
        ctx.setSource(ColorA(CM_HSV, fmod(float(sin(t*M_PI)*0.25f+(index*0.0004f+(x*0.02f))), 1.0f), sin(t*M_PI)*0.25f+0.25f, sin(t*M_PI)*0.5f+0.5, 1.0f));
        vector<double> dashes;
        for(int y= 0; y<rows; y++) {
            dashes.push_back(sin((index+y)*(sin((index*0.1f+(x*0.35f))*0.01f)*0.015f))*10.0f+(sin((index+x)*0.003f)*40.0f+70.0f));
        }
        ctx.setDash(dashes, index);
        ctx.moveTo(xx, h-oy);
        ctx.lineTo(xx, oy);
        ctx.stroke();
    }
    index++;
}

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