‹ pakt24pakt26 ›

pakt25

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

void pakt25App::setup() {
  srfOff= cairo::SurfaceImage(WIDTH, HEIGHT, false);
  ctxOff= cairo::Context(srfOff);
  ctxOff.setLineWidth(0.5);
  index= 0;
  w= getWindowWidth();
  h= getWindowHeight();
}

void pakt25App::draw() {

  n= sin(index*0.0006f)*15+20;

  cairo::Context ctx(cairo::createWindowSurface());
  ctxOff.setSourceRgba(0, 0, 0, 0.02);
  ctxOff.paint();

  ctxOff.setSourceRgba(1, 1, 1, 1);
  ctxOff.moveTo(0, h*0.5);
  for(int i= 0; i<n; i++) {
    float t= float(i)/(n-1);
    ctxOff.quadTo((t-(0.5f/n))*w, h*(sin(index*(sin(index*0.006f)*0.02f)+t)*0.5f+0.5f), t*w, h*(cos(index*(sin(index*0.002f)*0.02f)+t)*0.5f+0.5f));
  }
  ctxOff.stroke();
  index++;
  ctx.copySurface(srfOff, srfOff.getBounds());
}

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