Die Bahnwelt Technical

□ Diffusion-Limited-Aggregation

Simulation of DLA

In the scene of "Lar Keior" transitions, I used simulation of DLA (Diffusion-limited aggregation). DLA is the process whereby particles undergoing a random walk due to Brownian motion cluster together to form aggregates of such particles.(from wikipedia)


/*
 *  DLA Simulation
 *     by H.Kuwata   '92/4/14
 */
#define  segment_max   2048

int		segment_count;

struct	segment_list {
	char  sx,sy;
	char  x,y;
}		segment[4096];

short	segment_mapping[256][256];

segment_regist(int x, int y, int sx, int sy)
{
	segment[segment_count].x = x;
	segment[segment_count].y = y;
	segment[segment_count].sx = sx;
	segment[segment_count].sy = sy;
	segment_mapping[x+128][y+128] = ++segment_count;
	// line draw s{x,y} - {x,y}
	__draw_registed_segment(sx, sy, x, y);
}

void aggregates_simulation(float radius)
{
	int  r, i ,k;

	// clear
	segment_count = 0;
	for (i=0; i<256; i++) {
		for (k=0; k<256; k++) {
			segment_mapping[i][k] = 0;
		}
	}
	// center seed
	segment_regist(0, 0, 0, 0);

	// simulate and regist segment
	for (i = 1; i < segment_max; i++) {
		// start position
		float th = __random_value() * 3.141592 * 2;
		float px = r * cos(th);
		float py = r * sin(th);
		for (;;) {
			// approach to center
			float xx = px + 2*(rand() - 0.5) - (px / 150.);
			float yy = py + 2*(rand() - 0.5) - (py / 150.);
			int    nx = (int)xx;
			int    ny = (int)yy;

			// if contact, regist segment
			if (segment_mapping[nx+128][ny+128]) {
				segment_regist((int)px, (int)py, nx, ny);
				break;
			}

			// move walker point
			px = xx;
			py = yy;
			__put_walker_point(px,py);
		}
	}
}