Exemple #1
0
        public override void Initialize(object[] parameters)
        {
            ForestFire ff = parameters[0] as ForestFire;

            this.startAngles = new float[ff.States.Count()];
            this.sweepAngles = new float[ff.States.Count()];
            this.pieSprites  = new CustomSprite[ff.States.Count()];

            ResourceManager.TryGetResource("internal_circleShader", out IShader shader, true);

            int cellCount0 = ff.CellCount * ff.CellCount;

            float globalStartAngle = 0;
            int   i = 0;

            foreach (long ffState in ff.States)
            {
                if (i == 0)
                {
                    continue;
                }

                float pct0 = ff.StateCount(ffState) / (float)cellCount0;

                // uniforms
                Color cSpriteColor = ff.GetStateColor(ffState, 0.5f);
                float innerRadius  = 0.01f;
                startAngles[i]    = globalStartAngle;
                sweepAngles[i]    = pct0;
                globalStartAngle += pct0;

                // vertex attributes
                (VertexAttribute va, float[][] data)[] vertexAttributes =
Exemple #2
0
    public static void AddForestFireColony(List <Colony> Colonies, int width, int height, int x, int y, double Density, double F, double P, Color color, List <Cell> Neighborhood, bool Cyclic = false)
    {
        var ForestFireColony = new ForestFire(width, height, color);

        ForestFireColony.SetParameters(new List <Parameter>
        {
            new Parameter("P", P, 1, 1000),
            new Parameter("F", F, 1, 1000),
            new Parameter("Density", Density, (double)1 / 100, 1)
        });

        ForestFireColony.Randomize();
        ForestFireColony.SetNeighborhood(Neighborhood);
        ForestFireColony.SetCyclic(Cyclic);

        Colonies.Add(new Colony(x, y, ForestFireColony));
    }
Exemple #3
0
        private void OnSceneLoad_CellularAutomata()
        {
            IGameObject go_viewport = Scene.CreateGameObject("go_viewport");
            Viewport    viewport    = go_viewport.AddComponent <Viewport>();

            Scene.MainViewport = viewport;
            GUIHandler guiHandler = go_viewport.AddComponent <GUIHandler>();

            IGameObject gO_cellularAutomata = Scene.CreateGameObject("gO_cellularAutomata");
            ForestFire  forestFire          = gO_cellularAutomata.AddComponent <ForestFire>(new CellularAutomataInitializationData(2, 100, true, NeighbourhoodMode.Moore));

            gO_cellularAutomata.Transform.Position.x -= (viewport.Width - 1) / 2f;

            IGameObject gO_pieChart = Scene.CreateGameObject("go_pieChart");
            PieChart    pieChart    = gO_pieChart.AddComponent <PieChart>(forestFire);

            gO_pieChart.Transform.Scale       = new Vector2(0.25f, 0.25f);
            gO_pieChart.Transform.Position.x += 0.25f;
        }
    public static ArtificialLife Convert(ColonyTypes.Type type, Gtk.Image image, int Width, int Height, List <Parameter> Parameters, Color color, List <Cell> Neighborhood, bool Cyclic = false, bool Gradient = false)
    {
        int population = 0;

        if (image.Pixbuf != null)
        {
            if (type == ColonyTypes.Type.YinYangFire)
            {
                var maxStates = (int)Utility.GetNumeric(Parameters, "MaxStates");

                var colony = new YinYangFire(Width, Height, color);

                colony.SetParameters(new List <Parameter> {
                    new Parameter("MaxStates", maxStates, 2, 256),
                    new Parameter("Density", 1, (double)1 / 100, 1)
                });

                if (Gradient)
                {
                    colony.GradientPalette();
                }

                Draw(image.Pixbuf, Width, Height, colony, maxStates, ref population);

                colony.SetNeighborhood(Neighborhood);
                colony.SetCyclic(Cyclic);

                colony.ApplyChanges();

                return(colony);
            }

            if (type == ColonyTypes.Type.Zhabotinsky)
            {
                var colony = new Zhabotinsky(Width, Height, color);

                Draw(image.Pixbuf, Width, Height, colony, 256, ref population);

                colony.SetParameters(new List <Parameter> {
                    new Parameter("g", Utility.GetNumeric(Parameters, "g"), 1, 100),
                    new Parameter("k1", Utility.GetNumeric(Parameters, "k1"), 1, 100),
                    new Parameter("k2", Utility.GetNumeric(Parameters, "k2"), 1, 100),
                    new Parameter("Density", (double)population / (Width * Height), (double)1 / 100, 1)
                });

                if (Gradient)
                {
                    colony.GradientPalette();
                }

                colony.SetNeighborhood(Neighborhood);
                colony.SetCyclic(Cyclic);

                colony.ApplyChanges();

                return(colony);
            }

            if (type == ColonyTypes.Type.Life)
            {
                var colony = new Life(Width, Height, color);

                Draw(image.Pixbuf, Width, Height, colony, 2, ref population);

                colony.SetParameters(new List <Parameter>
                {
                    new Parameter("Birth", Utility.GetString(Parameters, "Birth")),
                    new Parameter("Survival", Utility.GetString(Parameters, "Survival")),
                    new Parameter("Density", (double)population / (Width * Height), (double)1 / 100, 1)
                });

                colony.SetNeighborhood(Neighborhood);
                colony.SetCyclic(Cyclic);

                colony.ApplyChanges();

                return(colony);
            }

            if (type == ColonyTypes.Type.ForestFire)
            {
                var colony = new ForestFire(Width, Height, color);

                Draw(image.Pixbuf, Width, Height, colony, 3, ref population);

                colony.SetParameters(new List <Parameter>
                {
                    new Parameter("P", Utility.GetNumeric(Parameters, "P"), 1, 1000),
                    new Parameter("F", Utility.GetNumeric(Parameters, "F"), 1, 1000),
                    new Parameter("Density", (double)population / (Width * Height), (double)1 / 100, 1)
                });

                colony.SetNeighborhood(Neighborhood);
                colony.SetCyclic(Cyclic);

                colony.ApplyChanges();

                return(colony);
            }

            if (type == ColonyTypes.Type.LangtonAnt)
            {
                var rules = Utility.GetString(Parameters, "Rule");
                var ants  = (int)Utility.GetNumeric(Parameters, "Ants");

                var colony = new LangtonAnt(Width, Height, color);

                colony.Random(!Gradient);
                colony.SetNeighborhood(Neighborhood);

                colony.SetParameters(new List <Parameter>
                {
                    new Parameter("Ants", ants, 1, 1000),
                    new Parameter("Rule", rules)
                });

                colony.SetCyclic(Cyclic);

                Draw(image.Pixbuf, Width, Height, colony, rules.Length, ref population);

                colony.ApplyChanges();

                return(colony);
            }

            if (type == ColonyTypes.Type.Snowflake)
            {
                var maxStates = (int)Utility.GetNumeric(Parameters, "MaxStates");

                var colony = new Snowflake(Width, Height, color);

                colony.SetParameters(new List <Parameter>
                {
                    new Parameter("Growth", Utility.GetString(Parameters, "Growth")),
                    new Parameter("MaxStates", maxStates, 1, 256)
                });

                if (Gradient)
                {
                    colony.GradientPalette();
                }

                Draw(image.Pixbuf, Width, Height, colony, maxStates, ref population);

                colony.SetNeighborhood(Neighborhood);
                colony.SetCyclic(Cyclic);

                colony.ApplyChanges();

                return(colony);
            }

            if (type == ColonyTypes.Type.Ice)
            {
                var colony = new Ice(Width, Height, color);

                Draw(image.Pixbuf, Width, Height, colony, 3, ref population);

                colony.SetParameters(new List <Parameter>
                {
                    new Parameter("Freeze", Utility.GetNumeric(Parameters, "Freeze"), 1, 1000),
                    new Parameter("Density", (double)population / (Width * Height), (double)1 / 100, 1)
                });

                colony.SetNeighborhood(Neighborhood);
                colony.SetCyclic(Cyclic);

                colony.ApplyChanges();

                return(colony);
            }

            if (type == ColonyTypes.Type.Cyclic)
            {
                var maxstates = (int)Utility.GetNumeric(Parameters, "MaxStates");

                var colony = new Cyclic(Width, Height, color);

                colony.SetParameters(new List <Parameter> {
                    new Parameter("MaxStates", maxstates, 2, 256)
                });

                if (Gradient)
                {
                    colony.GradientPalette();
                }

                colony.SetNeighborhood(Neighborhood);
                colony.SetCyclic(Cyclic);

                Draw(image.Pixbuf, Width, Height, colony, maxstates, ref population);

                colony.ApplyChanges();

                return(colony);
            }
        }

        return(new EmptyArtificialLife());
    }