‹ pakt10pakt12 ›

pakt11

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

void pakt11App::setup() {
  index= 0;
  rowsMid= 22.0f;
  colsMid= 20.0f;
  w= getWindowWidth();
  h= getWindowHeight();
}

void pakt11App::draw() {
  cairo::Context ctx(cairo::createWindowSurface());
  ctx.scale(0.96f, 0.96f);
  ctx.translate(5.0f, 5.0f);

  rows= rowsMid+(sin(index*0.0015)*10.0f);
  cols= colsMid+(sin(index*0.0024)*10.0f);

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

  ctx.setSourceRgb(1, 1, 1);
  ctx.moveTo(0, 0);
  for(int y= 0; y<=rows; y++) {
    for(int x= 0; x<=cols; x++) {
      ctx.lineTo((x/rows*w)+sin(index+(x*y)*32.0f), (y/cols*h)+cos(index+(x*y)*24.0f));
      ctx.lineTo((x/cols*w)+sin(index+(x*y)*32.0f), (y/rows*h)+cos(index+(x*y)*24.0f));
    }
  }
  ctx.fill();
  index++;
}

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