‹ pakt11pakt13 ›

pakt12

See /software/p5js/pakt-februari/pakt12/ for a JavaScript version and /software/supercollider/februari-pakt/pakt12/ 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 pakt12App : public App {
public:
    void setup();
    void draw();
    int index;
    float w, h;
    float n;
};
void pakt12App::setup() {
    index= 0;
    w= getWindowWidth();
    h= getWindowHeight();
}
void pakt12App::draw() {
    cairo::Context ctx(cairo::createWindowSurface());
    ctx.setFillRule(1);
    ctx.setLineWidth(1.0f);
    cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
    radialGrad.addColorStop(0, Color(0.3f, 0.3f, 0.3f));
    radialGrad.addColorStop(1, Color(0.0f, 0.0f, 0.0f));
    ctx.setSource(radialGrad);
    ctx.paint();
    n= sin(index/getFrameRate()*0.125)*150.0f+200.0f;
    ctx.setSourceRgba(1.0f, 1.0f, 1.0f, 0.7f);
    for(int i= 0; i<n; i++) {
        if(i==0) {
            ctx.moveTo(vec2(0.5f/n*w, h*0.5f));
        } else if(i%3==1) {
            vec2 v= vec2(i/n*w, (h*0.25)+(sin((index+(i+3))*(sin((index+1)*0.014f)*0.02f))*(sin((index+i)*0.015f))*(0.225*h)));
            ctx.lineTo(v);
        } else if(i%3==2) {
            vec2 v= vec2(i/n*w, (h*0.50)+(sin((index+(i+2))*(sin((index+2)*0.012f)*0.02f))*(sin((index+i)*0.020f))*(0.225*h)));
            ctx.lineTo(v);
        } else {
            vec2 v= vec2(i/n*w, (h*0.75)+(sin((index+(i+1))*(sin((index+3)*0.010f)*0.02f))*(sin((index+i)*0.025f))*(0.225*h)));
            ctx.lineTo(v);
        }
    }
    ctx.lineTo(vec2(w-(0.5f/n*w), h*0.5f));
    ctx.fill();        //ctx.stroke();
    index++;
}
CINDER_APP(pakt12App, Renderer2d, [&]( App::Settings *settings ) {
    settings->setWindowSize( WIDTH, HEIGHT );
    settings->setResizable( false );
})