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 › 'Remix' my sketch
Pages: 1 2 
'Remix' my sketch (Read 3877 times)
'Remix' my sketch
Jun 5th, 2008, 6:21pm
 
Edit: This post was incorrectly moved into the exhibition forum, but I am not exhibiting my work, I am looking for collaboration. No big deal, just want to make that clear to people reading my post! Smiley

Okay, here's the idea. I'm posting a very simple sketch. You take the code and add stuff to it, take stuff away, mangle it, and repost it here. The next person will do the same to YOUR code, and so on. It's like the telephone game, but with Processing sketches! Scroll down to the bottom to get the latest mutation of the sketch to use.

Here's mine:

http://popgroupe.com/alex/processing/circles/index.html

Code:

import java.util.ArrayList;

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 40;
// max and min size of circles
float maxSize = 30;
float minSize = 20;
// max speed for circles
float speed = 2;

void setup() {
 size(300, 300);
 background(255);
 noStroke();
 smooth();

 // fill the circles list with circle objects
 circles = new ArrayList();
 for (int i=0; i<circleCount; i++) {
   // random color with opacity of 150 (weighted toward blues & greens)
   color c = color(random(50), random(255), random(255), 150);
   // add the circle to circles list
   circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, c));
 }
}

void draw() {
 background(255);

 // loop through the circle objects in circles list
 for (int i=0; i<circles.size(); i++) {
   Circle circle = (Circle) circles.get(i);
   // move circles
   circle.move();
   // draw circles
   circle.display();
 }
}

class Circle {
 // x and y position, radius, x and y velocities
 float x, y, r, vx, vy;
 // circle color
 color c;

 Circle(float _x, float _y, float _r, color _c) {
   x = _x;
   y = _y;
   r = _r;
   c = _c;
   vx = random(-speed, speed);
   vy = random(-speed, speed);
 }

 // draw circle
 void display() {
   fill(c);
   ellipse(x, y, r*2, r*2);
 }

 // move circle
 void move() {
   // bounce against the sides
   if (x - r < 0) {
     x = r + 1;
     vx *= -1;
   }
   else if (x + r > width) {
     x = width - r - 1;
     vx *= -1;
   }
   if (y - r < 0) {
     y = r + 1;
     vy *= -1;
   }
   else if (y + r > height) {
     y = height - r - 1;
     vy *= -1;
   }

   // add velocities to position
   x += vx;
   y += vy;
 }
}


If there is enough participation, I will set up a website at some point displaying the results of this experiment. You could be famous! Participate!

Also, come chat with us about this project on the Processing IRC channel. Server: irc.freenode.net, channel: #processing.
Re: 'Remix' my sketch
Reply #1 - Jun 5th, 2008, 9:48pm
 
Here's a simple edit of Alex's original. I tweaked the colors a little and added some per pixel color manipulation based on the distance from the pixel being set to a random circle. Also, I changed all the r terms in the edge detection to r/4 so the circles can go outside the frame a little.

Quote:


// import java.util.ArrayList;

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 15;
// max and min size of circles
float maxSize = 100;
float minSize = 10;
// max speed for circles
float speed = 5;

void setup() {
 size(300, 300);
 background(255);
 noStroke();
 smooth();

 // fill the circles list with circle objects
 circles = new ArrayList();
 for (int i=0; i<circleCount; i++) {
   // random color with opacity of 150 (weighted toward blues & greens)
   color c = color(random(255), random(128,255), random(192), 64);
   // add the circle to circles list
   circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, c));
 }
 background(255);
 loadPixels();
}

void draw() {
 for(int y=0; y<height; y++) {
   for(int x=0; x<width; x++) {
     Circle circ = (Circle) circles.get((int)random(circles.size()));
     float disn = dist(x, y, circ.x, circ.y);
     if(disn < circ.r/2) {
       pixels[y*width+x] = lerpColor(pixels[y*width+x], circ.c, disn/(circ.r/2));
     }
   }
 }
 // loop through the circle objects in circles list
 for (int i=0; i<circles.size(); i++) {
   Circle circle = (Circle) circles.get(i);
   // move circles
   circle.move();
   // draw circles
   //circle.display();
 }
 updatePixels();
}

class Circle {
 // x and y position, radius, x and y velocities
 float x, y, r, vx, vy;
 // circle color
 color c;

 Circle(float _x, float _y, float _r, color _c) {
   x = _x;  
   y = _y;  
   r = _r;  
   c = _c;
   vx = random(-speed, speed);
   vy = random(-speed, speed);
 }

 // draw circle
 void display() {
   fill(c);
   ellipse(x, y, r*2, r*2);
 }

 // move circle
 void move() {
   // bounce against the sides
   if (x - r/4 < 0) {
x = r/4 + 1;
vx *= -1;
   }  
   else if (x + r/4 > width) {
x = width - r/4 - 1;
vx *= -1;
   }
   if (y - r/4 < 0) {
y = r/4 + 1;
vy *= -1;
   }  
   else if (y + r/4 > height) {
y = height - r/4 - 1;
vy *= -1;
   }

   // add velocities to position
   x += vx;
   y += vy;
 }
}


Re: 'Remix' my sketch
Reply #2 - Jun 5th, 2008, 11:45pm
 
Very cool! Here's my take on yours.

Main changes:

- more circles, and smaller sizes
- a list of colors to choose from, instead of random RGB values
- black outlines around each circle

Also, I should mention, don't be afraid to erase stuff the person before you has done. You can even write your sketch from scratch and carry over a certain concept from the previous sketch.

Code:

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 40;
// max and min size of circles
float maxSize = 15;
float minSize = 5;
// max speed for circles
float speed = 1;

color colors[] = {color(170, 232, 0), color(0, 154, 255), color(50, 255, 255), color(255), color(255), color(255)};

void setup() {
size(250, 250);
background(255);
noStroke();
smooth();

// fill the circles list with circle objects
circles = new ArrayList();
for (int i=0; i<circleCount; i++) {
// pick a color from the color list
color circleColor = colors[(int)random(colors.length)];
// add the circle to circles list
circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, circleColor));
}
background(255);
loadPixels();
}

void draw() {
// loop through each pixel
for(int y=0; y<height; y++) {
for(int x=0; x<width; x++) {
// choose a random circle
Circle circ = (Circle) circles.get((int)random(circles.size()));
// find distance from current pixel to circle
float disn = dist(x, y, circ.x, circ.y);
// if the pixel is inside the circle, than set that pixel's color
if(disn < circ.r) {
pixels[y*width+x] = lerpColor(pixels[y*width+x], circ.c, disn/(circ.r));
}
}
}

updatePixels();

// loop through the circle objects in circles list
for (int i=0; i<circles.size(); i++) {
Circle circle = (Circle) circles.get(i);
// move circles
circle.move();
// draw circle's outlines
circle.display();
}
}

class Circle {
// x and y position, radius, x and y velocities
float x, y, r, vx, vy;
// circle color
color c;

Circle(float _x, float _y, float _r, color _c) {
x = _x;
y = _y;
r = _r;
c = _c;
vx = random(-speed, speed);
vy = random(-speed, speed);
}

// draw circle
void display() {
noFill();
stroke(0);
ellipse(x, y, r*2, r*2);
}

// move circle
void move() {
// bounce against the sides
if (x - r/4 < 0) {
x = r/4 + 1;
vx *= -1;
}
else if (x + r/4 > width) {
x = width - r/4 - 1;
vx *= -1;
}
if (y - r/4 < 0) {
y = r/4 + 1;
vy *= -1;
}
else if (y + r/4 > height) {
y = height - r/4 - 1;
vy *= -1;
}

// add velocities to position
x += vx;
y += vy;
}
}
Re: 'Remix' my sketch
Reply #3 - Jun 7th, 2008, 5:17am
 
my 2 lines. unfortunately "copy for web" messed up the code.. so here it is plain:

// list that holds circles  
ArrayList circles;  
// number of circles to create initially  
int circleCount = 40;  
// max and min size of circles  
float maxSize = 25;  
float minSize = 5;  
// max speed for circles  
float speed = .8;  
float counter = 0.0;

color colors[] = {
 color(255,0,0,20), color(0,6), color(0,6)};

void setup() {  
 size(250, 250);  
 //background(255);  
 noStroke();  
 smooth();  

 // fill the circles list with circle objects  
 circles = new ArrayList();  
 for (int i=0; i<circleCount; i++) {  
   // pick a color from the color list
   color circleColor = colors[(int)random(colors.length)];
   // add the circle to circles list
   circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, circleColor));  
 }  
 background(0);  
 loadPixels();  
}  

void draw() {  
 counter += .075;
 // loop through each pixel
 float disn;
 Circle circ;
 for(int y=0; y<height; y++) {  
   for(int x=0; x<width; x++) {  
     // choose a random circle
     circ = (Circle) circles.get((int)random(circles.size()));
     // find distance from current pixel to circle  
     disn = dist(x, y, circ.x, circ.y);  
     // if the pixel is inside the circle, than set that pixel's color
     if(disn < circ.r) {  
       pixels[y*width+x] = lerpColor(pixels[y*width+x], circ.c, disn/(circ.r));  
     }  
   }  
 }

 updatePixels();  


 // loop through the circle objects in circles list  
 for (int i=0; i<circles.size(); i++) {  
   Circle circle = (Circle) circles.get(i);  
   // move circles  
   circle.move();  
   // draw circle's outlines
   circle.display();  
 }  

}  

class Circle {  
 // x and y position, radius, x and y velocities  
 float x, y, r, rbase, vx, vy, offset;  
 // circle color  
 color c;  

 Circle(float _x, float _y, float _r, color _c) {  
   x = _x;    
   y = _y;    
   rbase = _r;  
   r = _r;
   c = _c;  
   vx = random(-speed, speed);  
   vy = random(-speed, speed);  
   offset = random(0,10);
 }  

 // draw circle  
 void display() {
   noFill();
   stroke(random(50,255));
   ellipse(x, y, r*2, r*2);  
 }

 // move circle  
 void move() {  
   // oscillate the radius
   r = rbase + sin(counter+offset)*15;
   
   // bounce against the sides  
   if (x - r/4 < 0) {  
     x = r/4 + 1;  
     vx *= -1;  
   }    
   else if (x + r/4 > width) {  
     x = width - r/4 - 1;  
     vx *= -1;  
   }  
   if (y - r/4 < 0) {  
     y = r/4 + 1;  
     vy *= -1;  
   }    
   else if (y + r/4 > height) {  
     y = height - r/4 - 1;  
     vy *= -1;  
   }  

   // add velocities to position  
   x += vx;  
   y += vy;  
 }  
}  

Re: 'Remix' my sketch
Reply #4 - Jun 7th, 2008, 5:31pm
 
Nice, I like that progression.
Re: 'Remix' my sketch
Reply #5 - Jun 7th, 2008, 6:41pm
 
Yes, very cool so far! Keep them coming! Smiley
Re: 'Remix' my sketch
Reply #6 - Jun 8th, 2008, 1:41pm
 
here is my version...
actually i didn't change that much, some blending & colors and alpha values and an extra circle;

press d to switch between dark liquid & glow mode

Code:

import processing.opengl.*;
import javax.media.opengl.*;
import java.util.ArrayList;

PGraphicsOpenGL pgl;
GL gl;

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 100;
// max and min size of circles
float maxSize = 80;
float minSize = 2;
// max speed for circles
float speed = 5;
// glow toggle
boolean glow=false;

void setup() {
size(300,300,OPENGL);
//translate(width/2, height/2,50);
background(0);
noStroke();
smooth();

// fill the circles list with circle objects
circles = new ArrayList();
for (int i=0; i<circleCount; i++) {
// random color with opacity of 20 (weighted toward blues & greens)
color c = color(random(10), random(150), random(100), 20);
// add the circle to circles list
circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, c));
}
}

void draw() {
fill(0,25);
noStroke();
rect(0,0,width,height);

if (glow) {
glowStuff();
}

// loop through the circle objects in circles list
for (int i=0; i<circles.size(); i++) {
Circle circle = (Circle) circles.get(i);
// move circles
circle.move();
// draw circles
circle.display();
}
}

class Circle {
// x and y position, radius, x and y velocities
float x, y, r, vx, vy;
// circle color
color c;

Circle(float _x, float _y, float _r, color _c) {
x = _x;
y = _y;
r = _r;
c = _c;
vx = random(-speed, speed);
vy = random(-speed, speed);
}

// draw circle
void display() {
fill(c,100);
ellipse(x, y, r*2, r*2);
fill(0,150);
ellipse(x, y, r, r);
}

// move circle
void move() {
// bounce against the sides
if (x - r < 0) {
x = r + 1;
vx *= -1;
}
else if (x + r > width) {
x = width - r - 1;
vx *= -1;
}
if (y - r < 0) {
y = r + 1;
vy *= -1;
}
else if (y + r > height) {
y = height - r - 1;
vy *= -1;
}

// add velocities to position
x += vx;
y += vy;
}
}
// opengl blending as seen here http://www.rui-m.com/p5/Boids/ ;)
void glowStuff(){
pgl = (PGraphicsOpenGL) g;
gl = pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
pgl.endGL();
}

void keyPressed() {
if (key == 'd'){
glow = !glow;
}
}




applet here:
circles_remix
Re: 'Remix' my sketch
Reply #7 - Jun 8th, 2008, 2:12pm
 
Wow, the dark liquid is very beautiful! I didn't make this clear at first, but the idea is to remix the person before you, not just my sketch. Very sorry about that.

No matter though, your sketch still goes along with the others. We'll continue from your code.

Here's mine (didn't turn out looking that nice...):

Code:

import processing.opengl.*;
import javax.media.opengl.*;
import java.util.ArrayList;

PGraphicsOpenGL pgl;
GL gl;

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 10;
// max and min size of circles
float maxSize = 1;
float minSize = 1;
// max speed for circles
float speed = 5;
// glow toggle
boolean glow=true;

void setup() {
size(300,300,OPENGL);
//translate(width/2, height/2,50);
background(0);
noStroke();
smooth();
// fill the circles list with circle objects
circles = new ArrayList();
for (int i=0; i<circleCount; i++) {
// random color with opacity of 20 (weighted toward blues & greens)
color c = color(random(10), random(255), random(255));
// add the circle to circles list
circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, c));
}
}

void lines() {
for (int i=0; i<circleCount; i++) {
Circle c1 = (Circle) circles.get(i);
for (int j=i+1; j<circleCount; j++) {
Circle c2 = (Circle) circles.get(j);
stroke(c1.c);
strokeWeight(1);
line(c1.x, c1.y, c2.x, c2.y);
}
}
}

void draw() {
fill(0,20);
noStroke();
rect(0,0,width,height);

if (glow) {
glowStuff();
}

// draw lines connecting circles
lines();

// loop through the circle objects in circles list
for (int i=0; i<circles.size(); i++) {
Circle circle = (Circle) circles.get(i);
// move circles
circle.move();
// draw circles
circle.display();
}


}

class Circle {
// x and y position, radius, x and y velocities
float x, y, r, vx, vy;
// circle color
color c;

Circle(float _x, float _y, float _r, color _c) {
x = _x;
y = _y;
r = _r;
c = _c;
vx = random(-speed, speed);
vy = random(-speed, speed);
}

// draw circle
void display() {
fill(255);
ellipse(x, y, r*2, r*2);
}

// move circle
void move() {
// bounce against the sides
if (x - r < 0) {
x = r + 1;
vx *= -1;
}
else if (x + r > width) {
x = width - r - 1;
vx *= -1;
}
if (y - r < 0) {
y = r + 1;
vy *= -1;
}
else if (y + r > height) {
y = height - r - 1;
vy *= -1;
}

// add velocities to position
x += vx;
y += vy;
}
}
// opengl blending as seen here http://www.rui-m.com/p5/Boids/ ;)
void glowStuff(){
pgl = (PGraphicsOpenGL) g;
gl = pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
pgl.endGL();
}

void keyPressed() {
if (key == 'd'){
glow = !glow;
}
}

Re: 'Remix' my sketch
Reply #8 - Jun 8th, 2008, 4:42pm
 
a bit like the first ones.
colorfull. sorry for the bunch of pink. dunno how to get it away from it. some are very colorfull some are not.
to many circles will slow it down.
an rick your code doesn't  work for me.
the line
 Circle circ = (Circle) circles.get((int)random(circles.size()));
throws an error. and i don't understand circles.size
that stuff too.


Code:

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 8;
// max and min size of circles
float maxSize = 45;
float minSize = 25;
// max speed for circles
float speed = .8;
float counter = 0.0;



void setup() {
size(250, 250);
//background(255);
noStroke();
smooth();

// fill the circles list with circle objects
circles = new ArrayList();
for (int i=0; i<circleCount; i++) {
// pick a color from the color list
color circleColor = color((int) random(220),(int) random(255),(int) random(255));
// add the circle to circles list
circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, circleColor));
}
background(0);
loadPixels();
}

void draw() {
counter += .075;
// loop through each pixel
float disn;
Circle circ;
for(int y=0; y<height; y++) {
for(int x=0; x<width; x++) {
// just a small number of pixels
if(random(1)<0.75)
continue;
// choose a random circle
color a= pixels[y*width+x];
// make a lerp of the color through all circles
// k for not having the same order always
int k= (int) random(circleCount);
for(int i=0; i<circleCount;i++){
circ = (Circle) circles.get((k+i)%circleCount);
disn = dist(x, y, circ.x, circ.y);
a= lerpColor(a,circ.c, disn/(circ.r));
}
pixels[y*width+x]= a;
}
}

updatePixels();


// loop through the circle objects in circles list
for (int i=0; i<circles.size(); i++) {
Circle circle = (Circle) circles.get(i);
// move circles
circle.move();
// draw circle's outlines
circle.display();
}

}

class Circle {
// x and y position, radius, x and y velocities
float x, y, r, rbase, vx, vy, offset;
// circle color
color c;

Circle(float _x, float _y, float _r, color _c) {
x = _x;
y = _y;
rbase = _r;
r = _r;
c = _c;
vx = random(-speed, speed);
vy = random(-speed, speed);
offset = random(0,10);
}

// draw circle
void display() {
noFill();
stroke(180,225);
ellipse(x, y, r*2, r*2);
}

// move circle
void move() {
// oscillate the radius
r = rbase + sin(counter+offset)*15;

// bounce against the sides
if (x - r/4 < 0) {
x = r/4 + 1;
vx *= -1;
}
else if (x + r/4 > width) {
x = width - r/4 - 1;
vx *= -1;
}
if (y - r/4 < 0) {
y = r/4 + 1;
vy *= -1;
}
else if (y + r/4 > height) {
y = height - r/4 - 1;
vy *= -1;
}

// add velocities to position
x += vx;
y += vy;
}
}
Re: 'Remix' my sketch
Reply #9 - Jun 8th, 2008, 5:21pm
 
Thats a shame. I used the copy for discourse thing in the PDE and it screws up the code when you copy it from the forum.

The line that Ramin is referring to shows up like this when I copy and paste from the forum:
Quote:
Circle circ = (Circle) circles.get((int)random(circles.[colo r=#996600]size[/color]()));


When it should be:
Quote:
Circle circ = (Circle) circles.get((int)random(circles.size()));


Without the forum code segment for coloring the text.

I like your take on it Ramin although it is pretty processor intensive.

[edit]
I fixed the original post. The forum color code doesn't work after a dot perhaps.
Re: 'Remix' my sketch
Reply #10 - Jun 8th, 2008, 7:28pm
 
ah thank you. mh our are quite similar.
but sorry i didn't remix the last one.
here is the new
Code:

import processing.opengl.*;
import javax.media.opengl.*;
import java.util.ArrayList;

PGraphicsOpenGL pgl;
GL gl;

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 16;
// max and min size of circles
float maxSize = 1;
float minSize = 1;
// max speed for circles
float speed = 5;
// glow toggle
boolean glow=true;

void setup() {
size(300,300,OPENGL);
//translate(width/2, height/2,50);
background(0);
noStroke();
smooth();
// fill the circles list with circle objects
circles = new ArrayList();
for (int i=0; i<circleCount; i++) {
// random color with opacity of 20 (weighted toward blues & greens)
color c = color(random(10), random(255), random(255));
// add the circle to circles list
circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, c));
}
}


void bezier(int i) {
// bezierpoints of a circle, change when it bounces
Circle[] bp= new Circle[4];
bp[0]= (Circle) circles.get(i);
bp[1]= (Circle) circles.get((bp[0].to[0])%circleCount);
bp[2]= (Circle) circles.get((bp[0].to[1])%circleCount);
bp[3]= (Circle) circles.get((bp[0].to[2])%circleCount);
stroke(bp[0].c);
strokeWeight(4);
bezier(bp[0].x,bp[0].y,bp[1].x,bp[1].y,bp[2].x,bp[2].y,bp[3].x,bp[3].y);
}

void draw() {
fill(0,20);
noStroke();
rect(0,0,width,height);

if (glow) {
glowStuff();
}

// draw lines connecting circles
for (int i=0; i<circleCount; i++) {
bezier(i);
}

// loop through the circle objects in circles list
for (int i=0; i<circles.size(); i++) {
Circle circle = (Circle) circles.get(i);
// move circles
circle.move();
// draw circles
circle.display();
}


}

class Circle {
// x and y position, radius, x and y velocities
float x, y, r, vx, vy;
// circle color
color c;
int[] to = { 2,4,6};

Circle(float _x, float _y, float _r, color _c) {
x = _x;
y = _y;
r = _r;
c = _c;
vx = random(-speed, speed);
vy = random(-speed, speed);
}

// draw circle
void display() {
fill(255);
ellipse(x, y, r*2, r*2);
}

// move circle
void move() {
// bounce against the sides
if (x - r < 0) {
x = r + 1;
vx *= -1;
to[(int)random(3)]+=1;
}
else if (x + r > width) {
x = width - r - 1;
vx *= -1;
to[(int)random(3)]+=circleCount-1;
}
if (y - r < 0) {
y = r + 1;
vy *= -1;
to[(int)random(3)]+=2;
}
else if (y + r > height) {
y = height - r - 1;
vy *= -1;
to[(int)random(3)]+=circleCount-1;

}

// add velocities to position
x += vx;
y += vy;
}
}
// opengl blending as seen here http://www.rui-m.com/p5/Boids/ ;)
void glowStuff(){
pgl = (PGraphicsOpenGL) g;
gl = pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
pgl.endGL();
}

void keyPressed() {
if (key == 'd'){
glow = !glow;
}
}
Re: 'Remix' my sketch
Reply #11 - Jun 8th, 2008, 8:53pm
 
this is realy addictive Wink
Code:


import processing.opengl.*;
import javax.media.opengl.*;
import java.util.ArrayList;

PGraphicsOpenGL pgl;
GL gl;

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 20;
// max and min size of circles
float maxSize = 4;
float minSize = 4;
// max speed for circles
float speed = 3;
float center = 100;
float vxc = random(-speed/center, speed/center);
float vyc = random(-speed/center, speed/center);

// glow toggle
boolean glow=true;

void setup() {
size(300,300,OPENGL);
background(0);
noStroke();
smooth();
// fill the circles list with circle objects
circles = new ArrayList();
for (int i=0; i<circleCount; i++) {
// random color with opacity of 20 (weighted toward blues & greens)
color c = color(random(150), random(180), random(150),250);
// add the circle to circles list
circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, c));
}
}


void bezier(int i) {
// bezierpoints of a circle, change when it bounces
Circle[] bp= new Circle[6];
bp[0]= (Circle) circles.get(i);
bp[1]= (Circle) circles.get((bp[0].to[0])%circleCount);
bp[2]= (Circle) circles.get((bp[0].to[1])%circleCount);
bp[3]= (Circle) circles.get((bp[0].to[2])%circleCount);
stroke(bp[0].c,20);
strokeWeight(4);
bezier(bp[0].x,bp[0].y,bp[1].x,bp[1].y,bp[2].x,bp[2].y,bp[3].x,bp[3].y);
}

void draw() {
fill(0,10);
noStroke();
rect(0,0,width,height);

if (glow) {
glowStuff();
}

// draw lines connecting circles
for (int i=1; i<circleCount; i++) {
bezier(i);
}

// loop through the circle objects in circles list
for (int i=0; i<circles.size(); i++) {
Circle circle = (Circle) circles.get(i);
// move circles
circle.move();
// draw circles
circle.display();
}


}

class Circle {
// x and y position, radius, x and y velocities
float x, y, r, vx, vy;
// circle color
color c;
int[] to = {
2,4,6 };

Circle(float _x, float _y, float _r, color _c) {
x = _x;
y = _y;
r = _r;
c = _c;
float z = random(10);
if (z < 5) {
vx = random(-speed, speed);
vy = random(-speed, speed);
}
else {
vx = vxc;
vy = vyc;
x=width/2;
y=height/2;
}
}

// draw circle
void display() {
fill(c,10);
ellipse(x, y, r*2, r*2);
}

// move circle
void move() {
// bounce against the sides
if (x - r < 0) {
x = r + 1;
vx *= -1;
to[(int)random(3)]+=1;
}
else if (x + r > width) {
x = width - r - 1;
vx *= -1;
to[(int)random(3)]+=circleCount-1;
}
if (y - r < 0) {
y = r + 1;
vy *= -1;
to[(int)random(3)]+=2;
}
else if (y + r > height) {
y = height - r - 1;
vy *= -1;
to[(int)random(3)]+=circleCount-1;

}

// add velocities to position
x += vx;
y += vy;
}
}
// opengl blending as seen here http://www.rui-m.com/p5/Boids/ ;)
void glowStuff(){
pgl = (PGraphicsOpenGL) g;
gl = pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
pgl.endGL();
}

void keyPressed() {
if (key == 'd'){
glow = !glow;
}
}


playing around with center and speed values gives some very different results

have fun

edited out a little mistake
Re: 'Remix' my sketch
Reply #12 - Jun 8th, 2008, 9:42pm
 
nice, curious if this makes it to the flurry osx screensaver, almost looks like it.
Re: 'Remix' my sketch
Reply #13 - Jun 8th, 2008, 10:23pm
 
Wow, great work everyone! This is really coming along well. Keep at it! Smiley
Re: 'Remix' my sketch
Reply #14 - Jun 9th, 2008, 12:10am
 
R is for Random Movement Smiley

Code:

import processing.opengl.*;
import javax.media.opengl.*;
import java.util.ArrayList;

PGraphicsOpenGL pgl;
GL gl;

// list that holds circles
ArrayList circles;
// number of circles to create initially
int circleCount = 20;
// max and min size of circles
float maxSize = 4;
float minSize = 4;
// max speed for circles
float speed = 3;
float center = 100;
float vxc = random(-speed/center, speed/center);
float vyc = random(-speed/center, speed/center);

// glow toggle
boolean glow=true;

//random movement toggle:
boolean randomBool = false;

void setup() {
size(300,300,OPENGL);
background(0);
noStroke();
smooth();
// fill the circles list with circle objects
circles = new ArrayList();
for (int i=0; i<circleCount; i++) {
// random color with opacity of 20 (weighted toward blues & greens)
color c = color(random(150), random(180), random(150),250);
// add the circle to circles list
circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, c));
}
}


void bezier(int i) {
// bezierpoints of a circle, change when it bounces
Circle[] bp= new Circle[6];
bp[0]= (Circle) circles.get(i);
bp[1]= (Circle) circles.get((bp[0].to[0])%circleCount);
bp[2]= (Circle) circles.get((bp[0].to[1])%circleCount);
bp[3]= (Circle) circles.get((bp[0].to[2])%circleCount);
stroke(bp[0].c,20);
strokeWeight(4);
bezier(bp[0].x,bp[0].y,bp[1].x,bp[1].y,bp[2].x,bp[2].y,bp[3].x,bp[3].y);
}

void draw() {
fill(0,10);
noStroke();
rect(0,0,width,height);

if (glow) {
glowStuff();
}

// draw lines connecting circles
for (int i=1; i<circleCount; i++) {
bezier(i);
}

// loop through the circle objects in circles list
for (int i=0; i<circles.size(); i++) {
Circle circle = (Circle) circles.get(i);
// move circles
if(randomBool){
circle.moveRandomly();
}
else {
circle.move();
}
// draw circles
circle.display();
}


}

class Circle {
// x and y position, radius, x and y velocities
float x, y, r, vx, vy;
float ax, ay; //just acceleration variables
float damp; //this will act as friction
int step; //maximum step in random movement
// circle color
color c;
int[] to = {
2,4,6 };

Circle(float _x, float _y, float _r, color _c) {
x = _x;
y = _y;
r = _r;
c = _c;
float z = random(10);
if (z < 5) {
vx = random(-speed, speed);
vy = random(-speed, speed);
}
else {
vx = vxc;
vy = vyc;
x=width/2;
y=height/2;
}

damp = 0.9;
step = 1;
}

// draw circle
void display() {
fill(c,10);
ellipse(x, y, r*2, r*2);
}

// move circle
void move() {
// bounce against the sides
if (x - r < 0) {
x = r + 1;
vx *= -1;
to[(int)random(3)]+=1;
}
else if (x + r > width) {
x = width - r - 1;
vx *= -1;
to[(int)random(3)]+=circleCount-1;
}
if (y - r < 0) {
y = r + 1;
vy *= -1;
to[(int)random(3)]+=2;
}
else if (y + r > height) {
y = height - r - 1;
vy *= -1;
to[(int)random(3)]+=circleCount-1;

}

// add velocities to position
x += vx;
y += vy;
}

void moveRandomly(){
//this is a slight variation from a Keith Peter's tutorial for Flash,
//wich ca be found here:http://www.bit-101.com/tutorials/elasticiy.html
ax = random(-step, step);
vx += ax;
vx *= damp;
x += vx;

ay = random(-step, step);
vy += ay;
vy *= damp;
y += vy;

//i just copied this bit from the "move" function
// bounce against the sides
if (x - r < 0) {
x = r + 1;
vx *= -1;
to[(int)random(3)]+=1;
}
else if (x + r > width) {
x = width - r - 1;
vx *= -1;
to[(int)random(3)]+=circleCount-1;
}
if (y - r < 0) {
y = r + 1;
vy *= -1;
to[(int)random(3)]+=2;
}
else if (y + r > height) {
y = height - r - 1;
vy *= -1;
to[(int)random(3)]+=circleCount-1;

}

}

}
// opengl blending as seen here http://www.rui-m.com/p5/Boids/ ;)
// Rui: i think i forgot to put in that Boids source that the additive blend is taken from a Robert Hodgin tutorial
// wich can be found here: http://www.flight404.com/blog/?p=71 :)
void glowStuff(){
pgl = (PGraphicsOpenGL) g;
gl = pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
pgl.endGL();
}

void keyPressed() {
if (key == 'd'){
glow = !glow;
}
if(key == 'r' || key == 'R'){ // R is for Random
randomBool = !randomBool;
}
}

p.s. i'm really looking forward to see where this sketch will go Smiley
Pages: 1 2