L-Systemのテスト

Balanced Evotree AccumulatorBalanced Evotree Accumulator / jonathanmccabe
 最も単純で簡単なL-Systemを作ってみた。

L-System

 リンデンマイヤー・システム(ライフ・システムだとずっと思ってた)の略。
当然リンデンマイヤーさんが名付け親。
初期値に置換を繰り返し加える事で、フラクタルなんかを作ったりできる。*1

藻類

 作ってみたのは、Wikipediaに載ってた「藻類」。
初期値はA。
置換ルールは A → AB, B → A の二つ。


Unity Web Player版

文字数制限とかしてないので、あんまりポチポチすると壊れる(多分)。


ソースコード
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Text;

public class LSys : MonoBehaviour
{
    public Text text;

    public StringBuilder[] str = new StringBuilder[2];
    private Dictionary<string, string> rule = new Dictionary<string, string>()
    {
        {"A", "AB"},
        {"B", "A"}
    };

    private string start = "A";

    void Awake()
    {
        for (int i = 0; i < 2; i++)
        {
            str[i] = new StringBuilder();
        }
        str[0].Append(start);

    }
    // Use this for initialization
    void Start()
    {
        this.text.text = str[0].ToString();
    }

    public void OnNextButton()
    {
        for (int i = 0; i < str[0].Length; i++)
        {
            str[1].Append(rule[str[0][i].ToString()]);
        }
        str[0].Remove(0, str[0].Length);
        str[0].Append(str[1].ToString());
        str[1].Remove(0, str[1].Length);

        this.text.text = str[0].ToString();
    }
}

L-System

L-System

新訂版 カオス力学系入門 第2版

新訂版 カオス力学系入門 第2版