pakt24
See /software/p5js/pakt-februari/pakt24/ for a JavaScript version and /software/supercollider/februari-pakt/pakt24/ 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 pakt24App : public App {
public:
void setup();
void draw();
cairo::SurfaceImage srfOff;
cairo::Context ctxOff;
int index;
float w, h;
int n;
};
void pakt24App::setup() {
srfOff= cairo::SurfaceImage(WIDTH, HEIGHT, false);
ctxOff= cairo::Context(srfOff);
ctxOff.setLineWidth(0.1);
index= 0;
w= getWindowWidth();
h= getWindowHeight();
n= 80;
}
void pakt24App::draw() {
float rx= sin(index*0.0012f);
float ry= sin(index*0.0022f+1.0f);
float tx= sin(index*0.0032f+2.0f)+rx;
float ty= sin(index*0.0042f+3.0f)+ry;
cairo::Context ctx(cairo::createWindowSurface());
ctxOff.setSourceRgba(1, 1, 1, 0.02);
ctxOff.paint();
ctxOff.setSourceRgba(0, 0, 0, 1);
for(int i= 0; i<n; i++) {
float t= float(i)/n*2*M_PI;
if(i==0) {
ctxOff.moveTo((cos((-1.0f/n*2*M_PI)+rx+tx)*0.49f+0.5f)*w, (sin((-1.0f/n*2*M_PI)+ry+ty)*0.49f+0.5f)*h);
}
ctxOff.quadTo((sin(t+rx+tx)*0.49f+0.5f)*w, (cos(t+ry+ty)*0.49f+0.5f)*h, (cos(t+rx+tx)*0.49f+0.5f)*w, (sin(t+ry+ty)*0.49f+0.5f)*h);
}
ctxOff.stroke();
index++;
ctx.copySurface(srfOff, srfOff.getBounds());
}
CINDER_APP(pakt24App, Renderer2d, [&]( App::Settings *settings ) {
settings->setWindowSize( WIDTH, HEIGHT );
settings->setResizable( false );
})