‹ pakt14 pakt16 ›

pakt15

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

void pakt15App::setup() {
  index= 0;
  w= getWindowWidth();
  h= getWindowHeight();
  n= 80.0f;
  speed= 0.005f;
}

void pakt15App::draw() {
  cairo::Context ctx(cairo::createWindowSurface());

  ctx.setSourceRgb(0.0, 0.0, 0.0);
  ctx.paint();

  ctx.setLineWidth(1.0);
  ctx.translate(vec2(w*0.5f, h*0.5f));
  for(int i= 0; i<=n; i++) {
    ctx.setSourceRgba(1, sin((index+i)*0.1)*0.5+0.5, 1.0, 0.5);
    ctx.rotate(i/n*M_PI*2+(index*sin(index*speed)*0.0001f));
    ctx.moveTo(sin((index*0.1f)+(i*0.3f))*(h*0.3f), 0.0f);
    ctx.lineTo(vec2(w*(sin((index+i)*0.0144f)*0.03f+0.26f), h*(cos((index+i)*0.0126f)*0.03f+0.26f)));
    ctx.lineTo(vec2(w*(sin((index+i)*0.0244f)*0.02f+0.07f), h*(cos((index+i)*0.0226f)*0.02f+0.07f)));
    ctx.stroke();
  }
  index++;
}

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