‹ pakt17pakt19 ›

pakt18

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

void pakt18App::setup() {
  index= 0;
  w= getWindowWidth();
  h= getWindowHeight();
  n= 50;
}

void pakt18App::draw() {

  spread= sin(index*0.002f)*50.0f+(sin(index*0.003f)*40.0f);

  cairo::Context ctx(cairo::createWindowSurface());
  ctx.setSourceRgb(0.0, 0.0, 0.0);
  ctx.paint();
  ctx.setLineWidth(1.0);
  for(int i= 0; i<n; i++) {
    if(i==0) {
      ctx.moveTo(0, 0);
    } else {
      ctx.setSourceRgba(1, 1, 1, sin(float(i)/n*M_PI));
      a= sin(((i*spread)+index)*sin(index*0.0025+(sin(index*0.0050f)))*0.005f)*0.45f+0.5f;
      b= sin(((i*spread)+index)*sin(index*0.0024+(sin(index*0.0051f)))*0.005f)*0.45f+0.5f;
      c= sin(((i*spread)+index)*sin(index*0.0023+(sin(index*0.0052f)))*0.005f)*0.45f+0.5f;
      d= sin(((i*spread)+index)*sin(index*0.0022+(sin(index*0.0053f)))*0.005f)*0.45f+0.5f;
      ctx.line(vec2(a*w, b*h), vec2(c*w, d*h));
      ctx.line(vec2(b*w, a*h), vec2(d*w, c*h));
      ctx.stroke();
    }
  }
  index++;
}

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