I was watching this
video
on youtube that shows intelligent branching plug-in for Maya.
I have been playing around with L-Systems and branching scripts, but never came close to something this cool:
The branching in the video, has a self collision detection that prevents the branches from over-lapping like what happens in L-Systems.
So my question is: Does anyone have an idea about how to code such a system? Is an L-system a good starting point? can we introduce clash detection to it? or is there a totally different approach.
Any ideas, thoughts, tips, links would be highly appreciated. I don't even know where to start :)
I want to replace the results by probability, so for example if the board cell state is (1) and the neighbours are > 5 then the chance of death (0) is 60% (not 100% as it is now)...
I'm a real novice with Processing (or coding for that matter) so excuse my ignorance.
I'm trying to simulate some sort of urban growth using Cellular Automata and started by adapting the sketch for "Game of Life" by Daniel Shiffman on his book "Nature of Code".
What I'm hopping to do is to use an image (that in my case represents water on a map) to influence urban growth, by first preventing a black pixel (urban) to grow where water is (blue pixels)
But being a novice as I am :( , I'm unable to link the pixelated image map to the 2D array that is the CA to use the water pixels as a parameter for controlling growth.
Can anyone help please.
Thanks
// Daniel Shiffman, Nature of Code
// Cellular Automata defined by terrain map // Modified by Omar Helmy July 2013
GOL gol; PImage img;
void setup() { size(800, 800); img = loadImage ("Map.jpg"); //load the terrain image smooth(); frameRate (5); gol = new GOL(); }
void draw() { background(255);
//run the CA gol.generate(); gol.display(); }
// reset board when mouse is pressed void mousePressed() { gol.init(); }
class GOL {
int w = 4; int columns, rows; // Game of life board int[][] board;
GOL() { // Initialize rows, columns and set-up arrays columns = width/w; rows = height/w; board = new int[columns][rows]; }
// The process of creating the new generation void generate() { int pixlSize = w; //controles the pixelation of the terrain map
//pixelation loops for (int x= 0; x < img.width; x+= pixlSize) { for (int y= 0; y < img.height; y+= pixlSize) { int pixelColor = img.get(x, y);
fill(pixelColor); stroke(0); rect(x, y, pixlSize, pixlSize); } }
//Generating the CA int[][] next = new int[columns][rows];
// Loop through every spot in our 2D array and check spots neighbors for (int x = 1; x < columns-1; x++) { for (int y = 1; y < rows-1; y++) {
// Add up all the states in a 3x3 surrounding grid int neighbors = 0; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { neighbors += board[x+i][y+j]; } }
// A little trick to subtract the current cell's state since // we added it in the above loop neighbors -= board[x][y];
// Rules of Life if ((board[x][y] == 1) && (neighbors < 1)) next[x][y] = 0; // Loneliness else if ((board[x][y] == 1) && (neighbors > 5)) next[x][y] = 0; // Overpopulation else if ((board[x][y] == 0) && (neighbors == 2)) next[x][y] = int(random(2)); // Reproduction (gave it a random probability) else next[x][y] = board[x][y]; // Stasis } }
// drawing the cells, fill 255 for '1', fill 0 for '0' void display() { for ( int i = 0; i < columns;i++) { for ( int j = 0; j < rows;j++) { if ((board[i][j] == 1)) fill(0); else fill(255, 255, 255, 10); noStroke(); rect(i*w, j*w, w, w); } } } }