‹ pakt27pakt29 ›

pakt28

See /software/p5js/pakt-februari/pakt28/ for a JavaScript version and /software/supercollider/februari-pakt/pakt28/ 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 pakt28App : public App {
public:
  void setup();
  void draw();
  int index;
  float w, h;
  int n;
};

void pakt28App::setup() {
  index= 0;
  w= getWindowWidth()*0.5f;
  h= getWindowHeight()*0.5f;
}

void pakt28App::draw() {

  n= sin(index*0.0015f)*30.0f+35.0f;

  cairo::Context ctx(cairo::createWindowSurface());
  ctx.setSourceRgb(0, 0, 0);
  ctx.paint();

  for(int i= 0; i<n; i++) {
    float t= float(i)/n*M_PI*2;
    ctx.setLineWidth(sin(index*0.0125f+t)*5.0f+5.5f);
    ctx.setSource(ColorA(CM_HSV, sin(t)*(sin(index*0.01f)*0.2f)+0.5f, sin(index*0.004f)*0.3f+0.7f, 1.0f, 1.0f));
    float a1= (sin(index*(sin(index*0.0025f+t)*0.01f+0.01f))*0.5f+0.5f)*M_PI*2;
    float a2= (sin(a1*index*0.0005f+t)*0.5f+0.5f)*M_PI;
    float r= h*0.95f*(1.0f-float(i)/n);
    ctx.arc(w, h, r, a1, a2);
    ctx.stroke();
  }
  index++;
}

CINDER_APP(pakt28App, Renderer2d, [&]( App::Settings *settings ) {
  settings->setWindowSize( WIDTH, HEIGHT );
  settings->setResizable( false );
})