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