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 › Dots
Pages: 1 2 
Dots (Read 3842 times)
Re: Dots
Reply #15 - Mar 27th, 2008, 4:30pm
 
I made a variation with a pulsation.
It doesn't look good as I thought it would, cause the way I did it, the symmetry of the pattern is lost.
Anyway, here is the code, run it to see. Code:
//from http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Exhibition;action=display;num=1203259632

// cDotLinesBounce2

int modul = 3;
int count = modul*7;
Ball balls[] = new Ball[count];
color c = color(0);
color sc = color(0);
color lc = color(0, 100);

float radius;

void setup() {
size(400, 400);
radius = 100;
background(255);
smooth();
float vr = TWO_PI/count;
for (int i=0; i<count; i++) {
float a = i*vr;
float rx0 = cos(a) * radius;
float ry0 = sin(a) * radius;
float rx1 = cos(a) * radius * (i%modul) / modul;
float ry1 = sin(a) * radius * (i%modul) / modul;
balls[i] = new Ball(rx0, ry0, rx1 ,ry1, 3, i);
}
}

void draw() {
background(255);
for (int i=0; i<balls.length; i++) {
balls[i].pulse();
balls[i].move();




balls[i].drawlines();
balls[i].drawdots();
}
}

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/2 + rx;
y = height/2 + ry;
s = s_;
id = id_;
vx = 3;
vy = 3;
t = 0;
}
void pulse() {
x-=rx;
y-=ry;
t += PI/32;
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(c);
stroke(sc);
ellipse(x, y, s, s);
}
void drawlines() {
for (int i=id+1; i<balls.length; i++) {
stroke(lc);
line(x, y, balls[i].x, balls[i].y);
}
}
}
Re: Dots
Reply #16 - Mar 27th, 2008, 6:35pm
 
Cool! Here is a different take on the pulsing: Link.

Code:

int count = 20; // number of points (balls)
Ball balls[] = new Ball[count];

color c = color(0); // color of balls
color sc = color(0); // stroke color of balls
color lc = color(0, 100); // line color

float baseRadius = 100;
float pulseRange = 80;
float a = 0; // starting angle
float vr = .1; // rotational velocity (speed of pulsing)

void setup() {
size(400, 400);
smooth();
}

void draw() {
background(255);
a += vr;
float radius = baseRadius + sin(a) * pulseRange;
drawCircle(radius);
for (int i=0; i<balls.length; i++) {
balls[i].drawlines();
balls[i].draw();
}
}

void drawCircle(float radius) {
float vr = TWO_PI/count;
for (int i=0; i<count; i++) {
float a = i*vr;
float x = width/2 + cos(a) * radius;
float y = height/2 + sin(a) * radius;
balls[i] = new Ball(x, y, 3, i);
}
}

class Ball {
float x, y, s, vx, vy;
int id;
Ball(float x_, float y_, float s_, int id_) {
x = x_;
y = y_;
s = s_;
id = id_;
vx = 4;
vy = 3;
}
void draw() {
fill(c);
stroke(sc);
ellipse(x, y, s, s);
}
void drawlines() {
for (int i=id+1; i<balls.length; i++) {
stroke(lc);
line(x, y, balls[i].x, balls[i].y);
}
}
}

Re: Dots
Reply #17 - Mar 30th, 2008, 6:07am
 
How do you add an image, like in the previous post?

Here is a variation of my pulsating variation, with some color Code:
// cDotLinesBounce2c (2008-mar-29)
int modul = 5;
int count = (20/modul)*modul;
int pulsefac = 64;
Ball balls[] = new Ball[count];
color dotFillC = color(0,40);
color dotStrokeC = color(40,80,255,180);
color lineStrokeC = color(0, 30);
float radius;

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

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].drawlines();
   balls[i].drawdots();
 }
}

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 = 3;
   vy = 3;
   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() {
   for (int i=id+1; i<balls.length; i++) {
     float lenRatio=1.0-(sqrt(sq(balls[i].x-x)+sq(balls[i].y-y))/width);
     stroke(lenRatio*255,(1-lenRatio)*255,100,30+lenRatio*120);
     line(x, y, balls[i].x, balls[i].y);
   }
 }
}
Re: Dots
Reply #18 - Mar 30th, 2008, 6:47am
 
another one: Code:
// cDotLinesBounce2d (2008-mar-29)
int modul = 6;
int count = (20/modul)*modul;
int pulsefac = 64;
Ball balls[] = new Ball[count];
color dotFillC = color(0,40);
color dotStrokeC = color(25,50,155,80);
color lineStrokeC = color(0, 30);
int RR,GG,BB,dR,dG,dB;
float radius;

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

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();
balls[i].drawdots();
}
RR=(RR+dR);
GG=(GG+dG);
BB=(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);
}
}

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 = 3;
vy = 3;
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() {
for (int i=id+1; i<balls.length; i+=3) {
float lenRatio=1.0-(sqrt(sq(balls[i].x-x)+sq(balls[i].y-y))/width);
stroke(RR,GG,BB,30+lenRatio*100);
line(x, y, balls[i].x, balls[i].y);
}
}
}
Re: Dots
Reply #19 - Nov 18th, 2009, 8:15pm
 

Hi, thanks for your useful information Smiley
Processing is so new for me!
I have a code, simple pattern, and I try to have three of these in at the same time but I don't know how.
I appreciate if you guys help me Smiley

//this the code
int count = 20;
Ball balls[] = new Ball[count];
color c = color(0);
color sc = color(0);
color lc = color(0, 100);
float baseRadius;
float pulseRange = 0;
float a = 0; // starting angle
float vr = 0; // rotational velocity (speed of pulsing)0,1
 int sensordata01=0;
   float radius;
void setup() {
 size(1350, 750);
 baseRadius=height*3/4.0;
   a += vr;
 radius = baseRadius + sin(a) * pulseRange;//Starting from angle 0 it is 100 and @ angle 90 it is at its maximum which is 180 @ angle 135 it is 20
 drawCircle(radius);
}
void draw() {
 sensordata01=mouseX;
 //balls[9].x=sensordata01;//connect to sensordata disposition
    // float a = (balls[8].id*TWO_PI/count)+radians(sensordata01);//connect rotation of a ball to sensor data
  // balls[9].x = width/2 + cos(a) * radius;
 //  balls[9].y = height/2 + sin(a) * radius*2.0/3.0;
 background(255);

 for (int i=0; i<balls.length; i++) {
   balls[i].drawlines();
   balls[i].draw();
 }
}
void drawCircle(float radius) {
 float vr = TWO_PI/count;
 for (int i=0; i<count; i++) {
   float a = i*vr;
   float x = width/2 + cos(a) * radius*2.0/3.0;
   float y = height/2 + sin(a) * radius*2.0/3.0;
   balls[i] = new Ball(x, y, 10, i);
 }
// balls[count] = new Ball(0, 0, 3, count);
 // balls[count+1] = new Ball(width, 0, 3, count+1);
   //balls[count+2] = new Ball(width, height, 3, count+2);
   // balls[count+3] = new Ball(0, height, 3, count+3);
}
class Ball {
 float x, y, s, vx, vy;
 int id;
 Ball(float x_, float y_, float s_, int id_) {
   x = x_;
   y = y_;
   s = s_;
   id = id_;
   vx = 4;
   vy = 3;
 }
 void draw() {
   fill(c);
   stroke(sc);
   if(id==1){stroke(255,0,0);}
   ellipse(x, y, s, s);//s radious of the ball circle
 }
 void drawlines() {
   for (int i=id+1; i<balls.length; i++) {//Sequence connection
     stroke(lc);
     //if() frequency connection
     line(x, y, balls[i].x, balls[i].y);
   }
 }
}
Pages: 1 2