Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthorppdev5
    • CommentTimeJul 17th 2009
     
    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 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?
    • CommentAuthorppdev5
    • CommentTimeJul 17th 2009 edited
     
    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 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;
    }
    }