Example #1
0
    void Update()
    {
        // Construct a next generation of tree type with each click
        if (Input.GetKeyDown(treeGrowthKey) && clickedTimes < generations)
        {
            clickedTimes++;
            // Save current transform position & rotation
            Vector3    currentP = transform.position;
            Quaternion currentR = transform.rotation;

            // Generate the alphabet
            lsystem.Generate();

            // Generate the alphabet & pass it to the turtle
            turtle.SetAlphabet(lsystem.GetAlphabet());
            turtle.DrawPlant();


            // Get vector arrays
            GetTreeBranches();
            transform.position = currentP;
            transform.rotation = currentR;

            // Adjust turtle ratios
            turtle.ChangeLength(lengthRatio);
            turtle.ChangeWidth(widthRatio);

            // Finally render the tree structure
            DestroyTree();
            RenderTree(branches);
        }
    }
Example #2
0
    void Start()
    {
        //Randomize generation numbers
        generations = Random.Range(1, generations);

        // Look up so we rotate the tree structure
        transform.Rotate(Vector3.right * -90.0f);
        // Rules can be applied in an inspector, once game is started all information is
        // taken from an editor
        if (ruleChars != null)
        {
            ruleset = new Rule[ruleChars.Length];
            for (int i = 0; i < ruleChars.Length; i++)
            {
                ruleset[i] = new Rule(ruleChars[i], ruleStrings[i]);
            }
        }
        // Create the L-System and a new Turtle
        lsystem = new LSystem(axiom, ruleset);

        turtle = new Turtle(startRadius, treeRoundness, lsystem.GetAlphabet(), length, angleX, angleY, gameObject);

        // Generate the alphabet n(generations) times
        for (int i = 0; i <= generations; i++)
        {
            lsystem.Generate();

            // Adjust turtle ratios
            // (normaly it happens after the skeleton generation,
            // in this case we need to apply it now)
            turtle.ChangeLength(lengthRatio);
            turtle.ChangeWidth(widthRatio);
        }
        // Save current transform position & rotation
        Vector3    currentP = transform.position;
        Quaternion currentR = transform.rotation;


        // Generate the alphabet & pass it to the turtle
        turtle.SetAlphabet(lsystem.GetAlphabet());
        turtle.DrawPlant();


        // Get vector arrays
        GetTreeBranches();
        transform.position = currentP;
        transform.rotation = currentR;

        DestroyTree();
        RenderTree(branches);
    }
    void Start()
    {
        //Randomize generation numbers
        generations = Random.Range(1,generations);

        // Look up so we rotate the tree structure
        transform.Rotate(Vector3.right * -90.0f);
        // Rules can be applied in an inspector, once game is started all information is
        // taken from an editor
        if (ruleChars != null)
        {
            ruleset = new Rule[ruleChars.Length];
            for(int i = 0; i < ruleChars.Length; i++)
            {
                ruleset[i] = new Rule(ruleChars[i], ruleStrings[i]);
            }
        }
        // Create the L-System and a new Turtle
        lsystem = new LSystem(axiom,ruleset);

        turtle = new Turtle(startRadius, treeRoundness, lsystem.GetAlphabet(), length, angleX, angleY, gameObject);

        // Generate the alphabet n(generations) times
        for (int i = 0; i <= generations; i++)
        {
            lsystem.Generate();

            // Adjust turtle ratios
            // (normaly it happens after the skeleton generation,
            // in this case we need to apply it now)
            turtle.ChangeLength(lengthRatio);
            turtle.ChangeWidth(widthRatio);
        }
        // Save current transform position & rotation
        Vector3 currentP = transform.position;
        Quaternion currentR = transform.rotation;

        // Generate the alphabet & pass it to the turtle
        turtle.SetAlphabet(lsystem.GetAlphabet());
        turtle.DrawPlant();

        // Get vector arrays
        GetTreeBranches();
        transform.position = currentP;
        transform.rotation = currentR;

        DestroyTree();
        RenderTree(branches);
    }