‹ pakt03pakt05 ›

pakt04

See /software/p5js/pakt-februari/pakt04/ for a JavaScript version and /software/supercollider/februari-pakt/pakt04/ 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 pakt04App : public App {
public:
    void setup();
    void draw();
    int index, n;
};
void pakt04App::setup() {
    index= 0;
    n= 90;
}
void pakt04App::draw() {
    float x= getWindowCenter().x;
    float y= getWindowCenter().y;
    float w= getWindowWidth()*0.49;
    float h= getWindowHeight()*0.49;
    float spreadx= sin(index*0.005)*5.0;
    float spready= cos(index*0.006)*5.0;
    float wx= w*(sin(index*0.0125)*0.4+0.6);
    float hy= h*(cos(index*0.01)*0.4+0.6);
    cairo::Context ctx(cairo::createWindowSurface());
    cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
    radialGrad.addColorStop(0, Color(0.5, 0.7, 0.5));
    radialGrad.addColorStop(1, Color(0, 0, 0));
    ctx.setSource(radialGrad);
    ctx.paint();
    ctx.setSourceRgba(1, 1, 1, 0.8);
    ctx.setLineWidth(3.0);
    for(int i= 0; i<int(n+(sin(index*0.00876)*50)); i++) {
        vec2 p= vec2(x+(sin((index+(i*spreadx))*0.05)*sin((index+i)*0.01)*wx), y+sin((index+(i*spready))*0.04)*sin((index+i)*0.02)*hy);
        if(i==0) {
            ctx.moveTo(p.x, p.y);
        } else {
            ctx.lineTo(p);
        }
    }
    ctx.stroke();
    //ctx.fill();
    index++;
}
CINDER_APP(pakt04App, Renderer2d, [&]( App::Settings *settings ) {
    settings->setWindowSize( WIDTH, HEIGHT );
    settings->setResizable( false );
})