pakt22
See /software/p5js/pakt-februari/pakt22/ for a JavaScript version and /software/supercollider/februari-pakt/pakt22/ 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 pakt22App : public App {
public:
void setup();
void draw();
cairo::SurfaceImage srfOff;
cairo::Context ctxOff;
int index;
float w, h;
float theta;
int rows, cols;
};
void pakt22App::setup() {
srfOff= cairo::SurfaceImage(WIDTH, HEIGHT, false);
ctxOff= cairo::Context(srfOff);
ctxOff.setSourceRgb(0, 0, 0);
ctxOff.paint();
index= 0;
w= getWindowWidth();
h= getWindowHeight();
cols= 10;
rows= 14;
}
void pakt22App::draw() {
cairo::Context ctx(cairo::createWindowSurface());
ctxOff.setSourceRgba(0.1, 0, 0, 0.1);
ctxOff.paint();
ctxOff.setFillRule(1);
ctxOff.setSourceRgb(1.0, 0.0, 0.0);
theta= (sin(index*0.0004f)*0.1f)+(sin(index*0.004f)*(sin(index*0.00004f)*6.0f));
float rc= (sin(index*0.051f)*0.01f+1.0f)/cols;
float rr= (cos(index*0.062f)*0.01f+1.0f)/rows;
for(int x= 0; x<cols; x++) {
float rw= sin(float(x)/cols*M_PI*sin(index*0.0032f)+theta)*cols*5.0f;
for(int y= 0; y<rows; y++) {
float rh= cos(float(y)/rows*M_PI*cos(index*0.0034f)+theta)*rows*5.0f;
if(y%2==0) {
ctxOff.circle(rc*x*w+(rw*0.5f), rr*y*h+(rw*0.5f), rw);
} else {
ctxOff.circle(rc*x*w+(rh*0.5f), rr*y*h+(rh*0.5f), rh);
}
}
}
ctxOff.fill();
index++;
ctx.copySurface(srfOff, srfOff.getBounds());
}
CINDER_APP(pakt22App, Renderer2d, [&]( App::Settings *settings ) {
settings->setWindowSize( WIDTH, HEIGHT );
settings->setResizable( false );
})