pakt03
See /software/p5js/pakt-februari/pakt03/ for a JavaScript version and /software/supercollider/februari-pakt/pakt03/ 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 pakt03App : public App {
public:
void setup();
void draw();
int index, n;
};
void pakt03App::setup() {
index= 0;
n= 50;
}
void pakt03App::draw() {
float x= getWindowCenter().x;
float y= getWindowCenter().y;
float w= getWindowWidth()*0.4;
float h= getWindowHeight()*0.4;
float spreadx= sin(index*0.005);
float spready= sin(index*0.011);
float phaseshift= sin(index*0.001)*M_PI*2;
float wx= w*(sin(index*0.004)*0.45+0.55);
float hy= h*(sin(index*0.004)*0.45+0.55);
cairo::Context ctx(cairo::createWindowSurface());
cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
radialGrad.addColorStop(0, Color(0.7, 0.6, 0.5));
radialGrad.addColorStop(1, Color(0, 0, 0));
ctx.setSource(radialGrad);
ctx.paint();
for(int i= 0; i<n; i++) {
float r= i/(float)n*30.0+1.0;
float p= 0;
ctx.setSourceRgba(1, 1, 1, 0.5);
ctx.circle(vec2(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(0, 0, 1, 0.5);
ctx.circle(vec2(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
/*p= p+phaseshift;
ctx.setSourceRgba(0, 1, 0, 0.5);
ctx.circle(vec2(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(1, 0, 0, 0.5);
ctx.circle(vec2(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(0, 0, 0, 0.5);
ctx.circle(vec2(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();*/
}
index++;
}
CINDER_APP(pakt03App, Renderer2d, [&]( App::Settings *settings ) {
settings->setWindowSize( WIDTH, HEIGHT );
settings->setResizable( false );
})