‹ pakt00pakt02 ›

pakt01

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

void pakt01App::setup() {
  index= 0;
  n= 75;
}

void pakt01App::draw() {

  float x= getWindowCenter().x;
  float y= getWindowCenter().y;
  float w= getWindowWidth()*0.25;
  float h= getWindowHeight()*0.25;
  float yellow= sin(index*0.0005)*0.3+0.65;

  cairo::Context ctx(cairo::createWindowSurface());

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

  //double dashes[]= {sin(index*0.0023)*50.0+51, cos(index*0.0023)*50.0+51};
  //ctx.setDash(dashes, 2, 0);

  for(int i= 0; i<n; i++) {
    float xx= x+(cos(i*0.2)*w);
    float yy= y+(sin(i*0.15)*h);
    float start= cos(index*((i+1)*0.00006))*2*M_PI;
    float end= sin(index*((i*1)*0.00008))*2*M_PI;
    float size= sin(index*0.01+i)*50+58;
    ctx.setSourceRgba(xx/getWindowWidth(), yy/getWindowHeight(), yellow, end/2*M_PI);
    //ctx.setLineWidth(0.5);
    //ctx.arc(xx, yy, size, 0, 2*M_PI);
    //ctx.stroke();
    ctx.setLineWidth(i/8.0+4);
    ctx.arc(xx, yy, size, start, start+end);
    ctx.stroke();
  }
  index++;
}

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