pakt02
See /software/p5js/pakt-februari/pakt02/ for a JavaScript version and /software/supercollider/februari-pakt/pakt02/ 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 pakt02App : public App {
public:
void setup();
void draw();
int index, n;
};
void pakt02App::setup() {
index= 0;
n= 50;
}
void pakt02App::draw() {
float x= 10+(sin(index*0.016)*2);
float y= getWindowCenter().y+(sin(index*0.010)*50);
float x3= getWindowWidth()-10+(sin(index*0.012)*2);
float y3= getWindowCenter().y+(sin(index*0.014)*50);
float w= getWindowWidth()*0.5;
float h= getWindowHeight()*0.5;
float spread= lmap(sin(index*0.0005), -1.0, 1.0, 0.5, 1.5);
cairo::Context ctx(cairo::createWindowSurface());
cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
radialGrad.addColorStop(0, Color(0.5, 0.6, 0.7));
radialGrad.addColorStop(1, Color(0, 0, 0));
ctx.setSource(radialGrad);
ctx.paint();
double dashes[]= {sin(index*0.0023)*50.0+51, cos(index*0.0023)*50.0+51};
ctx.setDash(dashes, 2, 0);
// ctx.setLineCap(cairo::LINE_CAP_ROUND);
ctx.setSourceRgba(1, 1, 0, 0.8);
ctx.setLineWidth(1.0);
for(int i= 0; i<n; i++) {
float x1= lmap(sin(index*0.135+(i*spread)), -1.0, 1.0, 0.1, 0.5);
float y1= cos((index+i)*0.130+(i*spread));
float x2= lmap(sin(index*0.125+(i*spread)), -1.0, 1.0, 0.5, 0.9);
float y2= cos((index+i)*0.120+(i*spread));
ctx.moveTo(x, y);
ctx.curveTo(x1*w+w, y1*h+h, x2*w+w, y2*h+h, x3, y3);
}
ctx.stroke();
index++;
}
CINDER_APP(pakt02App, Renderer2d, [&]( App::Settings *settings ) {
settings->setWindowSize( WIDTH, HEIGHT );
settings->setResizable( false );
})