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 › Re: swarm art
Pages: 1 2 
Re: swarm art (Read 3554 times)
Re: swarm art
Reply #15 - Jul 19th, 2006, 4:24pm
 
I haven't followed the whole thread.  But looking quickly at the code I found a few "maybe-mistakes".  Try using PGraphics instead of PImage.  I'm supposing that your image called 'white.jpg' is just a white image.

Code:

//Initialising global variables
PGraphics picture;
int location_x;
int location_y;
int generation=3;
Swarm [] locust;

//Setup of main variables
void setup () {
framerate(1);
size(500,500,P3D);
background(199);
camera(500, 300, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0);

//Loading the image
picture = createGraphics(width,height,P3D);
picture.defaults();
picture.background(255);

//Initial co-ordinates for start of jumps
location_x=100;
location_y=100;

//initialising generation
locust = new Swarm[generation];

for (int i=0; i<generation; i++ ) {
locust[i] = new Swarm(picture);
}
}

//Recursive draw method
void draw () {

//clears the sketch every frame
background(199);

//starts the process
for (int i=0; i<generation; i++ ){
locust[i].live();
println("ok "+i);
}

}

//Swarm class
class Swarm {

PGraphics pic;

//Constructor
Swarm (PGraphics back) {
pic=back;
}

//main method
void live () {

//Loading the image's pixels
loadPixels();

//Initialising variables
int random1=int(random(0,300));
int random2=int(random(0,300));

int random_red=int(random(-255,255));
int random_green=int(random(-255,255));
int random_blue=int(random(-255,255));

//Getting the random pixel
int pixel=pic.pixels[random1+random2*pic.width];

int r=(pixel&0x00FF0000)>>16;
int g=(pixel&0x0000FF00)>>8;
int b=pixel&0x000000FF;

//Setting destination
int destination_x=random1+99;
int destination_y=random2+99;

//Setting stroke properties
int randomstroke=int(random(0,255));
stroke(randomstroke);

//Drawing the line
line(location_x,location_y,0, destination_x,destination_y,0);

location_x=destination_x;
location_y=destination_y;

//Changing the pixel's RGB
r+=random_red;
if(r<0)
r=0;
else if (r>255)
r=255;

g+=random_green;
if(g<0)
g=0;
else if (g>255)
g=255;

b+=random_blue;
if(b<0)
b=0;
else if (b>255)
b=255;

//Storing the change and updating the pixels
pixel=(pixel&0xFF000000)+(r<<16)+(g<<8)+b;
pic.pixels[random1+random2*pic.width]=pixel;
pic.updatePixels();

//Assigning the image to a vertex
beginShape();
noStroke();
texture(pic);

vertex(100, 100, 0, 0);
vertex(400, 100, 300, 0);
vertex(400, 400, 300, 300);
vertex(100, 400, 0, 300);

endShape();
}

}


hope it helps
Re: swarm art
Reply #16 - Jul 22nd, 2006, 3:47pm
 
Subtract point B from point A. Then divide that in two and add it to A.

You don't have to get all Euclidean about it, just work on each dimension separately.

And before you write back, put what I've said into code and test it separately from your program. If you have a problem, display the code in your post using:

{code}
//insert code
{/code}

But use square brackets [] instead of curly ones.

The easiest questions to answer on this board are phrased in a couple of sentences with no less than 5 but no more than 50 lines of code. Get into that practice and you'll get answers a lot quicker.
Pages: 1 2