pakt03
Submitted by f0 on Tue, 2011-02-22 19:17
#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 pakt03App : public AppBasic {
public:
void prepareSettings(Settings *settings);
void setup();
void draw();
int index, n;
};
void pakt03App::prepareSettings(Settings *settings) {
settings->setWindowSize(WIDTH, HEIGHT);
settings->setResizable(false);
}
void pakt03App::setup() {
index= 0;
n= 50;
}
void pakt03App::draw() {
float x= getWindowCenter().x;
float y= getWindowCenter().y;
float w= getWindowWidth()*0.4;
float h= getWindowHeight()*0.4;
float spreadx= sin(index*0.005);
float spready= sin(index*0.011);
float phaseshift= sin(index*0.001)*M_PI*2;
float wx= w*(sin(index*0.004)*0.45+0.55);
float hy= h*(sin(index*0.004)*0.45+0.55);
cairo::Context ctx(cairo::createWindowSurface());
cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
radialGrad.addColorStop(0, Color(0.7, 0.6, 0.5));
radialGrad.addColorStop(1, Color(0, 0, 0));
ctx.setSource(radialGrad);
ctx.paint();
for(int i= 0; i<n; i++) {
float r= i/(float)n*30.0+1.0;
float p= 0;
ctx.setSourceRgba(1, 1, 1, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(0, 0, 1, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
/*p= p+phaseshift;
ctx.setSourceRgba(0, 1, 0, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(1, 0, 0, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(0, 0, 0, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();*/
}
index++;
}
CINDER_APP_BASIC(pakt03App, Renderer2d)
#include "cinder/cairo/Cairo.h"
using namespace ci;
using namespace ci::app;
using namespace std;
const int WIDTH= 640;
const int HEIGHT= 480;
class pakt03App : public AppBasic {
public:
void prepareSettings(Settings *settings);
void setup();
void draw();
int index, n;
};
void pakt03App::prepareSettings(Settings *settings) {
settings->setWindowSize(WIDTH, HEIGHT);
settings->setResizable(false);
}
void pakt03App::setup() {
index= 0;
n= 50;
}
void pakt03App::draw() {
float x= getWindowCenter().x;
float y= getWindowCenter().y;
float w= getWindowWidth()*0.4;
float h= getWindowHeight()*0.4;
float spreadx= sin(index*0.005);
float spready= sin(index*0.011);
float phaseshift= sin(index*0.001)*M_PI*2;
float wx= w*(sin(index*0.004)*0.45+0.55);
float hy= h*(sin(index*0.004)*0.45+0.55);
cairo::Context ctx(cairo::createWindowSurface());
cairo::GradientRadial radialGrad(getWindowCenter(), 0, getWindowCenter(), getWindowWidth());
radialGrad.addColorStop(0, Color(0.7, 0.6, 0.5));
radialGrad.addColorStop(1, Color(0, 0, 0));
ctx.setSource(radialGrad);
ctx.paint();
for(int i= 0; i<n; i++) {
float r= i/(float)n*30.0+1.0;
float p= 0;
ctx.setSourceRgba(1, 1, 1, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(0, 0, 1, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
/*p= p+phaseshift;
ctx.setSourceRgba(0, 1, 0, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(1, 0, 0, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();
p= p+phaseshift;
ctx.setSourceRgba(0, 0, 0, 0.5);
ctx.circle(Vec2f(x+(sin((index+(i*spreadx))*0.05+p)*wx), y+cos((index+(i*spready))*0.05+p)*hy), r);
ctx.fill();*/
}
index++;
}
CINDER_APP_BASIC(pakt03App, Renderer2d)