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 3555 times)
Re: swarm art
May 27th, 2006, 3:58pm
 
My first works in Processing were a series of basic automata based filters called RobotAcids, created out of my move from printmaking to code. They're quite basic but Processing is certainly a good environment for playing with pixels.

That said though, on ProcessingBlogs Quasimondo just recently linked Filter Forge. Given it's graphical patch format it might be easier for you to get into.

It would depend on whether you're producing static art or a dynamic installation. If the latter then Processing would certainly be the way to go. As for whether it would be considered art I'll have to quote Harold Cohen that a work of art is generally considered to have meaning and a filter does not imbue an image with any more meaning than that which it started with.
Re: swarm art
Reply #1 - May 27th, 2006, 9:14pm
 
If source code is published online it's generally a given that it's free for anyone else to use. Just be sure to credit the people you borrow your snippets from.

I've only been programming for two-years so I would recommend casting your research net a lot wider than my backyard. This list is most of the people who have given me some programming advice on the Processing forum, I'm sure it wouldn't hurt to check the delicious tags too.
Re: swarm art
Reply #2 - Jul 3rd, 2006, 8:49pm
 
When you load an image, it gets stored in a PImage object. You can then read and alter the pixels in the PImage if you want. There's 2 ways to do it, the easy way, and the quick way.

Example, easy way: get the pixel at x=20, y=20, add 100 to the red value, and put that back into the image.
Code:
//Load the image
PImage MyImg=loadImage("thingy.jpg");

//Get the colour of pixel (20,20)
color c=MyImg.get(20,20);

//Get the red portion, and add 100 to it (value goes from 0-255)
int r=int(red(c));
r=r+100;

//Set the color to the new values
c=color(r,green(c),blue(c));

//update the image
MyImg.set(20,20,c);

//Make processing take note of the changes.
MyImg.updatePixels();



Example quick way:
Code:
PImage MyImg=loadImage("thingy.jpg");
int c=MyImg.pixels[20+20*MyImg.width];
int r=(c&0x00FF0000)>>16;
r+=100;
if(r>255)
r=255;
c=(c&0xFF00FFFF)+(r<<16);
MyImg.pixels[20+20*MyImg.width]=c;
MyImg.updatePixels();


It should be noted that the quick way is only noticably quicker if you're doing quite a few changes at a time.
Re: swarm art
Reply #3 - Jul 4th, 2006, 9:24pm
 
The processing download installs a copy of the reference locally. Just go Help->Reference from inside processing.
Re: swarm art
Reply #4 - Jul 5th, 2006, 3:45pm
 
You need to change the image before you use it as a texture.

What's happening is you're loading the original image, using that as a texture to a polygon, which is getting drawn, and then altering the image, but the changes being lost next frame because you re-load the image.
Re: swarm art
Reply #5 - Jul 5th, 2006, 7:50pm
 
Okay, computers tend to store colours as a single number, which represents the Alpha Red Green and Blue (ARGB) values all added together in a way, to make it easier for them to ship the information back and forwards.

Each pixels is a single 32bit number, with 8bits for each of the parts (ARGB).

The two lines of code use what is called bit-masking, and bit shifting to get at just the red information.

Now breaking down the 2 lines:

Code:
int r=(c&0x00FF0000)>>16; 



Lets look at the middle part first: c&0x00FF0000. What this says is take the pixel value, and remove everything apart from the bits that refer to the red values. The first two digits are the alpha channel, the second the red, third green, and last blue. so 0xFF000000 would leave us with the alpha information and 0x000000FF the blue etc.

The >>16 means shift this number 16 bits to the right. We need to do this as we want the value to be in the range 0 to 255, wheras in the original it's much bigger, and woudl eb significantly harder to add 100 to.

So we've got the red value as a number between 0 and 255, added 100 to it, and now need to put the new red value back into the pixel.

So: c&0xFF00FFFF, this does the opposite of the above, instead of leaving the red information, it leaves all the information except the red.

We then take the new red value, and shift it right 16 bits (r<<16), so that it lines up with the gap we created, andis where processing expext the red values to be, and then add the 2 parts together to get the new pixel value, in the computer's single ARGB value format.

Re: swarm art
Reply #6 - Jul 6th, 2006, 3:14pm
 
Almost. You're getting the data out of the pixel right, but your check to make sure it's not too small needs a tweak:

Code:
     r-=20;  
if(r<=0)
r=0;
g-=20;
if(g<=0)
g=0;
b-=20;
if(b<=0)
b=0;


If you want to see the changes slow,y then you need to only change a few pixels each frame, as nothing is actually drawn to the screen until the draw() function has finished.

So make a global counter to say which pixel to change, then increase that by one each frame. Just like your for loop, but instead of changing them all in one frame, you change them over the course of 300 frames.

Re: swarm art
Reply #7 - Jul 6th, 2006, 4:24pm
 
You need to set the counter outside of everything, e.g.:

Code:
int count;
PImage dali;
void setup()
{
... stuff ...
count=0;
dali=loadImage("image-dali.jpg");
}

void draw()
{
pixelchange(count,dali);
count++;
}


Anything you define outside of all the functions, is accessible by them all. Anything inside a function is re-created each time the function is run, and is only accessible from inside that function.
Re: swarm art
Reply #8 - Jul 7th, 2006, 3:49pm
 
I think you'll need to use something like http://processing.org/reference/curvePoint_.html or http://processing.org/reference/bezierPoint_.html to generate the points and then go about looping through them yourself.
Re: swarm art
Reply #9 - Jul 8th, 2006, 12:29pm
 
Code:

int steps;
int step;

void setup()
{
size( 200, 200 );
framerate(5);
ellipseMode(CENTER);
steps = 10;
step = 0;
}

void draw()
{
background(125);
bezier(85, 20, 10, 10, 90, 90, 15, 80);
float t = step / float(steps); // 0.0 <= t <= 1.0
float x = bezierPoint(85, 10, 90, 15, t);
float y = bezierPoint(20, 10, 90, 80, t);
ellipse(x, y, 5, 5);
step++;
step %= steps+1;
}


you don't need to draw all the points. see example.

F
Re: swarm art
Reply #10 - Jul 8th, 2006, 6:17pm
 
Just don't do the ellipse() part.. that's drawing the white bits...
Re: swarm art
Reply #11 - Jul 9th, 2006, 11:21pm
 
Reload the image when you want to remove all the changes.
just do img=loadImage("thingy.jpg"); inside draw() when you need to refresh it.
Re: swarm art
Reply #12 - Jul 10th, 2006, 11:47pm
 
I think you may have to keep a list of all the pixels you changed in the jumping, and what they were before you jumped over, then when it's time to repair the jumped bits, change them back manually.
Re: swarm art
Reply #13 - Jul 14th, 2006, 4:20pm
 
background(..a color..) makes everything go away. So you have a fresh screen every time. Means you have to draw everything you want drawn every frame though.
Re: swarm art
Reply #14 - Jul 17th, 2006, 11:38pm
 
This is what i've got so far:

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

//Setup of main variables
void setup () {
 
 //Loading the image
 picture=loadImage("white.jpg");
 
 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);
 
 //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 {
 
 PImage pic;
 
 //Constructor
 Swarm (PImage 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();
 }
 
}


my problem is that this draws triplets of lines instead of three separate lines.
if you change the generation variable to 1, it draws a line and then another starting from where the last one left off and so on. what i want to have happen as i increase the generation is multiples of this effect. instead what happens is that (for generation=3) it draws the three lines together and then the next three and so on...
any ideas what i'm doing wrong?
Pages: 1 2