首页 > 其他分享 >Lindenmayer systems (or L-systems)

Lindenmayer systems (or L-systems)

时间:2024-08-09 16:05:25浏览次数:14  
标签:DISTANCE ANGLE RULES gg drawer STEPS systems Lindenmayer

Among the most conspicuous properties of a plant shape are symmetry and self-similarity.

 

import turtle
from dataclasses import dataclass


WIDTH = 800
HEIGHT = 600
PEDESTRAL = 50

# a simple plant with a bud
AXIOM = "A"
RULES = {"A": "g[+A][-A]"}
ANGLE = 20
DISTANCE = 25
STEPS = 6

# the LRI plant with a bud
# AXIOM = "A"
# RULES = {"A": "AILR", "I": "g", "L": "[+g]", "R": "[-g]"}
# ANGLE = 30
# DISTANCE = 20
# STEPS = 4

# another example plant
# AXIOM = "X"  # "g"
# RULES = {"X": "g[+X]g[-X]+X", "g": "gg"}
# ANGLE = 40
# DISTANCE = 10
# STEPS = 4

# AXIOM = "X"
# RULES = {"X": "g-[[X]+X]+g[+gX]-X", "g": "gg"}
# ANGLE = 22.5
# DISTANCE = 5
# STEPS = 4

# AXIOM = "X"
# RULES = {"X": "g[+X]g[-X]+X", "g": "gg"}
# ANGLE = 25
# DISTANCE = 15
# STEPS = 4

# AXIOM = "g"
# RULES = {"g": "gg-[-g+g+g]+[+g-g-g]"}
# ANGLE = 22.5
# DISTANCE = 5
# STEPS = 4

# AXIOM = "X"
# RULES = {"X": "g[+X][-X]gX", "g": "gg"}
# ANGLE = 25.7
# DISTANCE = 2
# STEPS = 7

# AXIOM = "f"
# RULES = {"f": "f+g", "g": "f-g"}
# ANGLE = 90
# DISTANCE = 10
# STEPS = 7

# AXIOM = "g-g-g-g"
# RULES = {"g": "g-g+g+gg-g-g+g"}
# DISTANCE = 4
# ANGLE = 90
# STEPS = 3

# AXIOM = "g"
# RULES = {"g": "g[+g][-g]"}
# ANGLE = 20
# DISTANCE = 25
# STEPS = 6


def setup_screen(title):
    turtle.setup(WIDTH, HEIGHT)
    # turtle.tracer(0, 0)
    turtle.title(title)


@dataclass
class LSystem:
    script: str

    @classmethod
    def create(cls):
        r = cls(AXIOM)
        for i in range(STEPS):
            r.transform()
        return r

    def transform(self):
        self.script = "".join([self.apply_rule(c) for c in self.script])

    def apply_rule(self, c):
        return c if c not in RULES else RULES[c]

    def draw(self, drawer):
        while self.script:
            c = self.script[0]
            self.script = self.script[1:]

            if c.islower():
                drawer.forward(DISTANCE)
                turtle.update()
            elif c == "+":
                drawer.color("red")
                drawer.left(ANGLE)
            elif c == "-":
                drawer.color("green")
                drawer.right(ANGLE)
            elif c == "[":
                self.draw(drawer.clone())
            elif c == "]":
                return


setup_screen("L-systems")

drawer = turtle.Turtle()  # place at the bottom, point upward
drawer.color("blue")
drawer.hideturtle()
drawer.penup()
drawer.goto(0, -HEIGHT / 2 + PEDESTRAL)
drawer.left(90)
drawer.pendown()

LSystem.create().draw(drawer)

turtle.done()

 

 

 

# the LRI plant with a bud
AXIOM = "A"
RULES = {"A": "AILR", "I": "g", "L": "[+g]", "R": "[-g]"}
ANGLE = 30
DISTANCE = 20
STEPS = 4

 

 

# another example plant
AXIOM = "X"  # "g"
RULES = {"X": "g[+X]g[-X]+X", "g": "gg"}
ANGLE = 40
DISTANCE = 10
STEPS = 4

 

 

 

AXIOM = "X"
RULES = {"X": "g[+X]g[-X]+X", "g": "gg"}
ANGLE = 25
DISTANCE = 15
STEPS = 4

Step 1: g[+X]g[-X]+X
Step 2: gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X
Step 3: gggg[+gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]gggg[-gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]+gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X
Step 4: gggggggg[+gggg[+gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]gggg[-gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]+gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]gggggggg[-gggg[+gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]gggg[-gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]+gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]+gggg[+gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]gggg[-gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X]+gg[+g[+X]g[-X]+X]gg[-g[+X]g[-X]+X]+g[+X]g[-X]+X

 

标签:DISTANCE,ANGLE,RULES,gg,drawer,STEPS,systems,Lindenmayer
From: https://www.cnblogs.com/zhangzhihui/p/18350912

相关文章

  • OSI(Open Systems Interconnection Model)七层模型
    前情提要:是一个描述计算机网络通信协议设计的概念模型。它由国际标准化组织(ISO)在1984年发布,用于帮助不同系统之间的通信。这个模型将网络通信过程分为七个层次,每一层都承担着特定的功能:1.物理层(PhysicalLayer):负责在物理媒体上传输原始比特流。它关注的是比特在电缆、光纤......
  • Mobile Systems, Applications, and Services (MobiSys, MOBISYS)
    MobileSystems,Applications,andServices{MobiSys,MOBISYS}1.AssociationforComputingMachinery(ACM)2.ACMConferences3.MobileSystems,Applications,andServices(MobiSys,MOBISYS)3.1.Proceedingsofthe22ndAnnualInternationalCon......
  • SystemServer 进程的启动流程
    一、SystemServer 进程简介1. SystemServer进程主要的作用是启动各种系统服务,比如ActivityManagerService,PackageManagerService,WindowManagerService等各种服务。当我们的应用需要使用各种系统服务的时候也是通过与SystemServer进程通讯获取各种服......
  • INFO6030 - Systems Analysis and Design
    **INFO****6030-****Systems********Analysis********and********Design****Assignment2PartB:SystemD****esign********(30%)****Due:11:59pmFriday2ndAu****gust(Week********12)****Introduction**TheUniversityofNewcastleisreplacingitso......
  • 推荐系统(Recommender Systems) 原理与代码实例讲解
    推荐系统(RecommenderSystems)-原理与代码实例讲解1.背景介绍1.1问题的由来在海量信息时代,用户面对的信息量爆炸性增长,如何在庞大的数据中找到符合个人兴趣和需求的内容成了一个挑战。推荐系统正是为了解决这个问题而诞生的。通过分析用户的偏好、行为以及历史记录,......
  • redsystems教程的使用:忘记密码如何重置密码
    当我们使用redsystems的时候,电脑没有保存密码,然后自己也忘记了密码,如果你登录了,点击更改密码后,还是需要填写登录密码才能修改。我们该怎么办?问题描述:当我们点击重置密码后输入我们注册时的email后(也就是要找回密码账户的email),也会报错下面就是解决方法!!!一、修改邮件配置信息......
  • 《Optimizing the LINPACK Algorithm for Large-Scale PCIe-Based CPU-GPU Heterogene
    论文标题《OptimizingtheLINPACKAlgorithmforLarge-ScalePCIe-BasedCPU-GPUHeterogeneousSystems》为基于PCIe的大规模CPU-GPU异构系统优化LINPACK算法作者GuangmingTan、ChaoyangShui、YinshanWang、XianzhiYu和YujinYan来自中科院计算所初读摘要......
  • 【Microelectronic Systems】期末速通
    PART1嵌入式系统概述与玩转mbed1嵌入式系统,微控制器,与ARM1.1什么是嵌入式系统?微处理器不仅仅存在于通用计算机中,也可以安置在一些不需要计算的设备内部,比如洗衣机,摄像机。微处理器常常可以控制这些产品。因为这类产品的微处理器镶嵌在内部,所以称这类产品为嵌入式系统。......
  • Uncovering ChatGPT’s Capabilities in Recommender Systems论文阅读笔记
    UncoveringChatGPT’sCapabilitiesinRecommenderSystems论文阅读笔记Abstract​ 在本研究中,我们的目标是通过将ChatGPT的推荐能力与传统的信息检索(IR)排名能力对齐,包括点排序、成对排序和列表排序。为了实现这一目标,我们将上述三种建议策略重新制定为专门针对现有领域而定制......
  • Large Language Models are Zero-Shot Rankers for Recommender Systems论文阅读笔记
    LargeLanguageModelsareZero-ShotRankersforRecommenderSystems论文阅读笔记Abstract​ 本工作旨在调查作为推荐系统的排名模型的LLM的能力。我们首先将推荐问题形式化为一个条件排序任务,将顺序交互历史作为条件,并将其他候选生成模型检索到的项目作为候选项。为了解决LL......