Flint Particle System Forum - Cellular Automata 2010-12-25T17:32:04+00:00 http://flintparticles.org/forum/ Lussumo Vanilla & Feed Publisher Cellular Automata http://flintparticles.org/forum/comments.php?DiscussionID=240&Focus=866#Comment_866 2009-07-17T19:10:31+01:00 2010-12-25T17:32:04+00:00 ppdev5 http://flintparticles.org/forum/account.php?u=225 Hello, I've been playing around with Flint for some days and I like it very much. Thanks Richard! I've thought about it and I would think i't woul be really cool to have an action to ...
I've been playing around with Flint for some days and I like it very much. Thanks Richard!

I've thought about it and I would think i't woul be really cool to have an action to incorporate cellular automata!(example :http://blog.soulwire.co.uk/flash/actionscript-3/2d-cellular-automata/)

You can change the rules around for the cellular automata to create cool effects.
For example there is a "copy random neighbor" rule that creates a perfect explosion effect.
I suggest you read more : http://en.wikipedia.org/wiki/Cellular_automaton

I'm thinking of creating my own action that makes a cellular automata that can be extended to create differnet rules, but I have no idea how to start.

Any ideas on how to do this?]]>
Cellular Automata http://flintparticles.org/forum/comments.php?DiscussionID=240&Focus=868#Comment_868 2009-07-17T22:33:50+01:00 2009-07-17T22:41:28+01:00 ppdev5 http://flintparticles.org/forum/account.php?u=225 Hey guys, I'm finished with the CellularAutomata action, it still needs some work(e.g. particles can't come back to life)! Here is the source code: package ...
I'm finished with the CellularAutomata action, it still needs some work(e.g. particles can't come back to life)!

Here is the source code:

package org.flintparticles.twoD.actions{
//Author Priyank Patel
//Uses Flint Particle System
import org.flintparticles.common.actions.ActionBase;
import org.flintparticles.common.emitters.Emitter;
import org.flintparticles.common.particles.Particle;
import org.flintparticles.twoD.emitters.Emitter2D;
import org.flintparticles.twoD.particles.Particle2D;

public class CellularAutomata extends ActionBase{

public var automate:Function;
public var boxw:int;
public var boxh:int;
public var result:Boolean;


public function CellularAutomata(rule:Function,width:int=3,height:int=3){

automate=rule;
boxw=(width-1)/2;
boxh=(height-1)/2;

}

public override function update(emitter:Emitter,particle:Particle,time:Number):void{


var p:Particle2D = Particle2D( particle );
var e:Emitter2D = Emitter2D( emitter );
var particles:Array = e.particles;
var neighbors:Array = new Array();

for(var i:int=0;i<particles.length;i++){
if((particles[i].x<(p.x+boxw)) && (particles[i].x>(p.x-boxw)) && (particles[i].y<(p.y+boxh)) && (particles[i].y>(p.y-boxh))){
neighbors.push(particles[i]);
}
}
result=automate(neighbors,p);
if(result==true){
particle.isDead=false;
}
if(result==false){
particle.isDead=true;
}
}
}
}

Implement it like this:

emitter.addAction( new CellularAutomata(rule,101,101));
function rule(neighbors:Array,particle:Particle2D){
if(neighbors.length>1){
return true;
}
else{
trace("died!");
return false;
}
}
]]>