pakt20

#include "cinder/app/AppBasic.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 pakt20App : public AppBasic {
public:
        void prepareSettings(Settings *settings);
        void setup();
        void draw();
        cairo::SurfaceImage srfOff;
        cairo::Context ctxOff;
        int index, n;
        float w, h;
        float spread;
};

void pakt20App::prepareSettings(Settings *settings) {
        settings->setWindowSize(WIDTH, HEIGHT);
        settings->setResizable(false);
}

void pakt20App::setup() {
        srfOff= cairo::SurfaceImage(WIDTH, HEIGHT, false);
        ctxOff= cairo::Context(srfOff);
        ctxOff.setSourceRgb(0, 0, 0);
        ctxOff.paint();
        ctxOff.setLineWidth(1);
        ctxOff.setAntiAlias(0);
        index= 0;
        w= getWindowWidth();
        h= getWindowHeight();
        n= 150;
}

void pakt20App::draw() {
        cairo::Context ctx(cairo::createWindowSurface());
        spread= sin(index*0.002f);
        for(int i= 0; i<n; i++) {
                float tx= sin(0.012f*(index+(i*spread)));
                float ty= sin(0.014f*(index+(i*spread)));
                float tz= sin(0.016f*(index+(i*spread)))*0.5f+0.5f;
                ctxOff.setSourceRgba(tz, tz*0.9f, tz, 0.05f);
                ctxOff.moveTo(Vec2f(sin(tx+sin(index*0.001f))*(sin(tx)*0.001f+1.0f)*w*0.46f+(w*0.5f), sin(ty+cos(index*0.001f*i))*(cos(ty)*0.001f+1.0f)*h*0.46f+(h*0.5f)));
                ctxOff.lineTo(Vec2f(cos(ty+sin(index*0.001f))*(sin(tx)*0.001f+1.0f)*w*0.36f+(w*0.5f), sin(tx+cos(index*0.001f*i))*(cos(ty)*0.001f+1.0f)*h*0.36f+(h*0.5f)));
                ctxOff.stroke();
        }
        index++;
        ctx.copySurface(srfOff, srfOff.getBounds());
}

CINDER_APP_BASIC(pakt20App, Renderer2d)