‹ pakt04pakt06 ›

pakt05

See /software/p5js/pakt-februari/pakt05/ for a JavaScript version and /software/supercollider/februari-pakt/pakt05/ 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 pakt05App : public App {
public:
    void setup();
    void draw();
    int index, n;
};

void pakt05App::setup() {
    index= 0;
    n= 100;
}

void pakt05App::draw() {
    
    float x= getWindowCenter().x;
    float y= getWindowCenter().y;
    float w= getWindowWidth()*0.3;
    float h= getWindowHeight()*0.275;
    float spread= sin(index*0.0012)*20.0;
    float speed1= sin(index*0.0013)*0.001+0.005;
    float speed2= sin(index*0.0014)*0.001+0.0005;
    float speed3= sin(index*0.0015)*0.001+0.014;
    float speed4= sin(index*0.0016)*0.001+0.012;
    
    cairo::Context ctx(cairo::createWindowSurface());
    
    cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
    radialGrad.addColorStop(0, Color(0.5, 0.4, 0.3));
    radialGrad.addColorStop(1, Color(0, 0, 0));
    ctx.setSource(radialGrad);
    ctx.paint();
    
    ctx.setSourceRgba(1, 1, 1, 0.8);
    ctx.setLineWidth(1.0);
    for(int i= 0; i<n; i++) {
        vec2 p= vec2(x+(sin((index*i*speed1))+sin(index*i*speed2)*w)-i, y+sin((index+(i*spread))*speed3)*sin((index+i)*speed4)*h+i);
        ctx.moveTo(p.x+(n-i), p.y+(i-n));
        ctx.lineTo(p);
    }
    ctx.stroke();
    index++;
}

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