Lシステムとそれらが許容するもの

基本から始めましょう。有名で愛されているウィキペディアから定義をとると、Lシステム(またはリンデンマイヤーのシステム)は並列書き換えシステムであり、形式文法の形式です。





簡単に言うと、Lシステムは、文字列の作成に使用できる文字のアルファベット、各文字の置換規則を指定する一連の生成規則、構築が始まる最初の文字列("axiom")で構成されます。線によって幾何学的構造に形成される変換メカニズム。Lシステムの最も単純な例は、ツリー構築の問題です。





入力データ:





文字列以下、公理):AB





変数ツリーの構築に使用できます):ABC





ルール次の行の各変数が変更されるルール):





  • A-> AB





  • B-> AC





  • C-> A





次の変換が得られます。                                        





世代





調子





1





AB





2





AB AC





3





AB AC AB A





4





AB AC AB A AB AC AB









AB AC AB A AB AC AB AB AC AB A AB AC





6





等…





Lシステムが使用される主な方向は、生物と無生物(結晶、軟体動物の殻、またはハニカム)の両方の成長プロセスをモデル化することです





例:





このようなプロセスをシミュレートするために、「turtle」ライブラリが組み込まれているPythonなどのプログラミング言語を使用します





それでは始めましょう:





  1. ここでは、Turtleライブラリをプロジェクトにインポートしています。





    import turtle







  2. 次に、タートルに必要なすべての構成を含めます





    turtle.hideturtle()







    turtle.tracer(1)







    turtle.penup()







    turtle.setposition(-300,340)







    turtle.pendown()







    turtle.pensize(1)







  3. , :





    axiom = "F+F+F+F"







    tempAx = ""







    itr = 3







    (itr- , )





  4. , itr-, "" /:





    for k in range(itr):







    for ch in axiom:







    if ch == "+":







    tempAx = tempAx + "+"







    elif ch == "-":







    tempAx = tempAx + "-"







    elif ch == "F": #F







    tempAx = tempAx + "F+F-f-F+F"







    else:







    tempAx = tempAx + "f"







    axiom = tempAx







    tempAx = " "







    print(axiom)







    , "+":





    if ch == "+":







    tempAx = tempAx + "+"







    ( ) “+” “+” . “-” “f”, “-” “f” . “F”, “F + F – f – F + F”, . , “”, . :





    axiom = tempAx







    tempAx = " "







    ( ):





  5. , , . , :





    for ch in axiom:







    if ch == "+":







    turtle.right(45)







    turtle.forward(10)







    turtle.right(45)







    elif ch == "-":







    turtle.left(45)







    turtle.forward(10)







    turtle.left(45)







    else:







    turtle.forward(20)







    , , "+", "-", "F" "f". , "+":





    if ch == "+":







    turtle.right(45)







    turtle.forward(10)







    turtle.right(45)







    , 45 , , 10, , 45 . "-":





    elif ch == "-":







    turtle.left(45)







    turtle.forward(10)







    turtle.left(45)







    , "+", , . "F" "f", 20 :





    else:







    turtle.forward(20)







    -:





  6. -, :





    turtle.fillcolor("#99BBFF")







    turtle.begin_fill()







    #99BBFF - (RGB: 153, 187, 255), begin_fill() . , , :





    turtle.end_fill()







    turtle.update()







    turtle.done()







    end_fill() . "". -:





, "" , .





最後に、このトピックについての作業と執筆が本当に楽しかったことを付け加えたいと思います。おそらく将来的には、「L-システム」のトピックに関する記事をいくつか書く予定ですが、それまでの間、私の突っついた創造性の結果をあなたに提示してください












All Articles