‹ pakt13pakt15 ›

pakt14

See /software/p5js/pakt-februari/pakt14/ for a JavaScript version and /software/supercollider/februari-pakt/pakt14/ 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 pakt14App : public App {
public:
    void setup();
    void draw();
    int index;
    float w, h;
    float spread;
    float spreadx, spready;
    int n;
};

void pakt14App::setup() {
    index= 0;
    w= getWindowWidth();
    h= getWindowHeight();
    n= 100;
}

void pakt14App::draw() {
    cairo::Context ctx(cairo::createWindowSurface());
    ctx.setFillRule(1);
    
    cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
    radialGrad.addColorStop(0, Color(0.5f, 0.5f, 0.6f));
    radialGrad.addColorStop(1, Color(0.0f, 0.0f, 0.0f));
    ctx.setSource(radialGrad);
    ctx.paint();
    
    ctx.setSourceRgba(1.0f, 1.0f, 1.0f, 0.85f);
    
    for(int i= 0; i<=n; i++) {
        spreadx= sin((i+index)*0.011f)*sin((i+index)*0.013f);
        spready= sin((i+index)*0.012f)*sin((i+index)*0.014f);
        spread= (spreadx*spready)*0.25f+cos((index+i)*0.001f);
        
        float yy= sin((i+index)*0.012f+spready);
        float hh= yy*(cos(index*0.013f));
        float xx= cos((i+index)*0.014f+spreadx);
        float ww= xx*(sin(index*0.015f));
        yy= yy*(h*spread)+(h*0.5f);
        xx= xx*(h*spread)+(h*0.5f);
        hh= hh*(h*spread)+(h*0.5f);
        ww= ww*(h*spread)+(h*0.5f);
        if(i==0) {
            ctx.moveTo(xx, yy);
        } else if(i%5==1) {
            ctx.quadTo(xx, yy, ww, hh);
        } else if(i%5==2) {
            ctx.quadTo(yy, xx, hh, ww);
        } else if(i%5==3) {
            ctx.quadTo(xx, yy, hh, ww);
        } else if(i%5==4) {
            ctx.quadTo(yy, xx, ww, hh);
        } else {
            ctx.moveTo(yy, xx);
        }
    }
    ctx.fill();
    index++;
}

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