Exploring Ballistic Deposition with PNGwriter
As opposed to Diffusion-Limited Aggregates (see a page I made comparing simulated DLAs (made with PPMWriter, PNGwriter's precursor) with real, copper-based DLAs for more info), which model particles undergoing brownian motion in a solution, Ballistic Deposition aggregates are simulated by modelling particles hitting a sticky surface from one direction only. They will stick to particles already a part of the growing mass from the front or sides.
Here are some images generated with different rules.
 Sticks on right and left, 114854 particles, initial layer is the width of the image |
 Sticks on right and left, 60642 particles, initial layer is one point in the middle |
 Sticks on right and left, 90978 particles, initial layer is the middle third |
 Sticks only on right side, 135070 particles, initial layer is the width of the image |
 Sticks only on right side, 41995 particles, initial layer is one point in the middle |
 Sticks only on right side, 75423 particles, initial layer is the middle third |
Here's the code:
/* Ballistic Deposition - Test program for PNGwriter
* http://pngwriter.sourceforge.net/
* By Paul Blackburn
* */
#include <pngwriter.h>
#include <stdlib.h>
#include <time.h>
#define rand_max 2147483647
int main()
{
int width = 500;
int height = 500;
int maxiter = 50000000;
// Create PNGwriter instance
pngwriter out(width, height, 0, "out.png");
unsigned long int number_particles=0;
// Seed random number generator.
srandom( time(NULL) );
int rrr, iii;
double r;
int rr;
bool end = 0;
// Plot a line at the bottom to serve as a deposition site.
out.line(width/2.0,1,width/2.0,1,65535,0,0);
for( iii = 0; iii < maxiter; iii++)
{
// Go down one pixel, and if your neighbour is occupied, stop there.
rr = 1 + (random()%width);
for( rrr = height; rrr > 0; rrr--)
{
if(out.read(rr,rrr,1) == 65535)
{
end = 1;
break;
}
if( (out.read(rr-1, rrr, 1) == 65535)||(out.read(rr+1, rrr, 1) == 65535)||(out.read(rr, rrr-1, 1) == 65535) )
{
out.plot(rr, rrr, 65535, 0, 0);
number_particles++;
break;
}
}
if(end == 1)
{
break;
}
}
// Rename the image given the number of particles and write the image to disk.
out.pngwriter_rename(number_particles);
out.close();
return 0;
}
syntax highlighted by Code2HTML, v. 0.9.1
|
|