‹ pakt18pakt20 ›

pakt19

See /software/p5js/pakt-februari/pakt19/ for a JavaScript version and /software/supercollider/februari-pakt/pakt19/ 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 pakt19App : public App {
public:
  void setup();
  void draw();
  int index, n;
  float w, h;
  float speed, disorder, rad;
  vector<vec3> bubbles;
};

void pakt19App::setup() {
  index= 0;
  w= getWindowWidth();
  h= getWindowHeight();
  n= 200;
  rad= 25.0f;
  for(int i= 0; i<n; i++) {
    bubbles.push_back(vec3(0.0f, 0.0f, 1.0f));
  }
}

void pakt19App::draw() {

  speed= sin(index*0.02f)*0.01f+0.065f;
  disorder= sin(index*0.0022f)*25.0f+25.0f;

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

  cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), w);
  radialGrad.addColorStop(0, Color(1.0, 0.3, 0.3));
  radialGrad.addColorStop(1, Color(0, 0, 0));
  ctx.setSource(radialGrad);
  ctx.paint();

  ctx.translate(w*0.5f, h*0.5f);
  for(int i= 0; i<n; i++) {
    vec3 b= bubbles[i];
    float theta= ((float(i)/n)+sin(index*0.0001f))*M_PI*2;
    ctx.setSourceRgba(1, 1, 1, 1.0f-b.z);
    ctx.circle(vec2(sin(theta+((sin(index*0.0008f)*0.25f+1.0f)*i))*w*0.4f*b.x, cos(theta+((sin(index*0.0012f)*0.25f+1.0f)*i))*h*0.4f*b.y), rad*b.z);
    ctx.fill();
    float dxyz= (sin((index+(i*speed*disorder))*0.01f)*0.1f+0.15f)*speed;
    bubbles[i]= vec3(fmod(b.x+dxyz, 1.0f), fmod(b.y+dxyz, 1.0f), fmod(b.z+dxyz, 1.0f));

  }
  index++;
}

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