We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Color Spiro
Page Index Toggle Pages: 1
Color Spiro (Read 1072 times)
Color Spiro
Apr 1st, 2008, 5:32am
 
Modified from Dots by Filipe Sabella
Code:
// from http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Exhibition;action=display;num=1203259632
// cDotLinesBounce2_lincol (2008-mar-31)
// pierrecharland@hotmail.com

int modul = 5;
int count = (20/modul)*modul;
int pulsefac = 1000;//from 64 to 30000
Ball balls[] = new Ball[count];
color dotFillC = color(0,40);
color dotStrokeC = color(25,50,155,80);
color lineStrokeC = color(0, 20);
float RR,GG,BB,dR,dG,dB;
float radius;

void setup() {
size(800, 800);
radius = width/2.2;
background(255);
smooth();
float vr = TWO_PI/count;
float a, rx0, ry0, rx1, ry1;
for (int i=0; i<count; i++) {
a = i*vr;
//rx0 = cos(a) * radius;
//ry0 = sin(a) * radius;
//rx0 = cos(a) * radius * (1 + (modul-(i%modul))/(float)modul);
//ry0 = sin(a) * radius * (1 + (modul-(i%modul))/(float)modul);
rx0 = cos(a) * radius * (1 + (i%modul)/(float)modul);
ry0 = sin(a) * radius * (1 + (i%modul)/(float)modul);
rx1 = cos(a) * radius * (i%modul)/(float)modul;
ry1 = sin(a) * radius * (i%modul)/(float)modul;
balls[i] = new Ball(rx0, ry0, rx1 ,ry1, 1, i);
}
dR=1.0;
dG=1.9;
dB=2.8;
}//setup()

void draw() {
//background(255);
for (int i=0; i<balls.length; i++) {
balls[i].pulse();
balls[i].move();
}
for (int i=0; i<balls.length; i++) {
// balls[i].drawdots();
}
for (int i=0; i<balls.length; i+=3) {
balls[i].drawlines();
}
RR+=dR;
GG+=dG;
BB+=dB;
if (RR<0 || RR>255) {
dR*=-1;
RR=(RR+dR);
}
if (GG<0 || GG>255) {
dG*=-1;
GG=(GG+dG);
}
if (BB<0 || BB>255) {
dB*=-1;
BB=(BB+dB);
}
}//draw()

class Ball {
float rx0, ry0, rx1, ry1, rx, ry, s, vx, vy, x, y, t;
int id;
Ball(float rx0_, float ry0_, float rx1_, float ry1_, float s_, int id_) {
rx0 = rx0_;
ry0 = ry0_;
rx1 = rx1_;
ry1 = ry1_;
rx = rx0;
ry = ry0;
x = (width-radius)/2 + rx;
y = (height-radius)/2 + ry;
s = s_;
id = id_;
vx = 4;
vy = 4;
t = 0;
}
void pulse() {
x-=rx;
y-=ry;
t += TWO_PI/pulsefac;
rx = rx0 + (sin(t)) * (rx1-rx0);
ry = ry0 + (sin(t)) * (ry1-ry0);
x+=rx;
y+=ry;
}
void move() {
if (x < s/2) {
x = s/2 + 1;
vx *= -1;
}
else if (x > width-s/2) {
x = width-s/2-1;
vx *= -1;
}
if (y < s/2) {
y = s/2 + 1;
vy *= -1;
}
else if (y > height-s/2) {
y = height-s/2-1;
vy *= -1;
}
x += vx;
y += vy;
}
void drawdots() {
fill(dotFillC);
stroke(dotStrokeC);
ellipse(x, y, s, s);
}
void drawlines() {
float lenRatio;
for (int i=id+1; i<balls.length; i+=3) {
//choose 1 of 2 lenRatio:
//lenRatio=(sqrt(sq(balls[i].x-x)+sq(balls[i].y-y))/(1.3*width));
lenRatio=(abs(balls[i].x-x)+abs(balls[i].y-y))/(1.7*width);
//choose 1 of 2 stroke:
stroke(RR,GG,BB,lenRatio*255);
//stroke(RR,GG,BB,(1.0-lenRatio)*255);
line(x, y, balls[i].x, balls[i].y);
}
}
}//Ball class
Re: Color Spiro
Reply #1 - Apr 1st, 2008, 11:47am
 
pretty, good choice of colours too.
Re: Color Spiro
Reply #2 - Apr 27th, 2008, 11:52am
 
nice one, i was recommend this work for adding fadeout like this code

fill(0,5);
rect(0,0,width,height);
Re: Color Spiro
Reply #3 - May 6th, 2008, 4:03pm
 
this is a good one.
Page Index Toggle Pages: 1