コード例 #1
0
        public void Grow()
        {
            if (axiomObject == null)
            {
                Debug.LogError("The axiom object is not set.");
                return;
            }

            if (axiomObject.GetComponent <AxiomObject>() == null)
            {
                Debug.LogError("The axiom object does not have the AxiomObject component.");
                return;
            }

            if (ruleCollectionObject == null)
            {
                Debug.LogError("The rule collection object is not set.");
                return;
            }

            if (ruleCollectionObject.GetComponent <RuleCollectionObject>() == null)
            {
                Debug.LogError("The rule collection object does not have the RuleCollectionObject component.");
                return;
            }

            List <Variable> axiom = axiomObject.GetComponent <AxiomObject>().Axiom;

            RuleCollection ruleCollection = ruleCollectionObject.GetComponent <RuleCollectionObject>().RuleCollection;

            variables = LSystem.Grow(axiom, ruleCollection, numberOfIterations);

            if (printResultInConsole)
            {
                string result = "";

                foreach (Variable variable in variables)
                {
                    result += variable.ToString();
                }

                Debug.Log("Result:");
                Debug.Log("Number of variables: " + variables.Count);
                Debug.Log(result);
            }
        }
コード例 #2
0
        public static List <Variable> Grow(List <Variable> axiom, RuleCollection ruleCollection, int numberOfIterations)
        {
            List <Variable> variables = new List <Variable>();

            variables.AddRange(axiom);

            for (int i = 0; i < numberOfIterations; i++)
            {
                List <Variable> newVariables = new List <Variable>();

                foreach (Variable action in variables)
                {
                    newVariables.AddRange(ruleCollection.Provide(action));
                }

                variables = newVariables;
            }

            return(variables);
        }