‹ pakt05pakt07 ›

pakt06

See /software/p5js/pakt-februari/pakt06/ for a JavaScript version and /software/supercollider/februari-pakt/pakt06/ 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 pakt06App : public App {
public:
  void setup();
  void draw();
  int n;
  float w, h;
  float theta, speed, spread;
  vector<vec2> points;
};

void pakt06App::setup() {
  n= 50;
  theta= 0;
  speed= 0.00002;
  spread= 1;
  for(int i= 0; i<n; i++) {
    points.push_back(getWindowCenter());
  }
  w= getWindowWidth();
  h= getWindowHeight();
}

void pakt06App::draw() {
  cairo::Context ctx(cairo::createWindowSurface());
  //ctx.setAntiAlias(1);

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

  ctx.setLineWidth(1);
  for(size_t i= 0; i<points.size(); i++) {

    float x= (points[i].x/w)*2-1;
    float y= (points[i].y/h)*2-1;
    vec2 v= vec2(
      (((cos(theta)*x)-(sin(theta)*y))*0.5+0.5)*w+spread,
      (((cos(theta)*y)+(sin(theta)*x))*0.5+0.5)*h+spread
    );
    points[i]= v;
    ctx.setSourceRgb(1, 0, 0);
    ctx.circle(v, 50);
    ctx.fill();
    ctx.setSourceRgb(1, 1, 1);
    ctx.circle(v, 50);
    ctx.stroke();
    theta= theta+speed;
  }
}

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