‹ pakt08pakt10 ›

pakt09

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

void pakt09App::setup() {
  index= 0;
  n= 1000;
  m= 0;
  rows= 3;
  cols= 4;
  magic= 50;
}

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

  float w= getWindowWidth();
  float h= getWindowHeight();

  cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
  radialGrad.addColorStop(0, Color(0.5, 0.5, 0.5));
  radialGrad.addColorStop(1, Color(0, 0, 0));
  ctx.setSource(radialGrad);
  ctx.paint();

  ctx.setSourceRgba(1, 1, 1, 0.85);
  if(m<n) {
    m= m+1;
  }
  for(int i= 0; i<m; i++) {
    vec2 p= vec2(fmod((rows+i), w), fmod((cols+i)*(fmod(i, magic)), h));
    ctx.rectangle(p, p+vec2(8*sin((index+i)*0.012), 8*cos((index+i)*0.011)));
  }
  ctx.fill();
  magic= magic+(sin(index*0.001)*0.01);
  rows= rows+(sin(index*0.0004));
  cols= cols+(sin(index*0.0005));
  index++;
}

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