Beispiel #1
0
def main():
    im = Image.new("RGB", (1000, 1000))
    turtle = Turtle([500, 1000], -90)

    lsystem = LSystem((F(), ))
    lsystem.step(5)
    lsystem.interpret(turtle)

    turtle.draw(im)
    im.show()
Beispiel #2
0
def main():
    im = Image.new("RGB", (1000, 1000))
    turtle = Turtle([500, 1000], -90)

    lsystem = LSystem((F(), One())*3, context_limit=1)
    lsystem.step(30)
    lsystem.interpret(turtle)

    turtle.draw(im)
    im.show()
Beispiel #3
0
def main():
    im = Image.new("RGB", (1000, 1000))
    turtle = Turtle([500, 1000], -90)

    system = LSystem(axiom=(Branch(300, 20), ))

    system.step(7)
    system.interpret(turtle)

    turtle.draw(im)
    im.show()
Beispiel #4
0
def main():
    im = Image.new("RGB", (1000, 1000))

    turtle = Turtle([750, 250], 180)

    snowflake = LSystem((F(), Rot(-120), F(), Rot(-120), F()))
    snowflake.step(5)
    snowflake.interpret(turtle)

    turtle.draw(im)

    im.show()
Beispiel #5
0
def main():
    im = Image.new("RGB", (1000, 1000))

    turtle = Turtle()
    turtle.pos = [500, 500]

    kolam = LSystem((A(), ) * 4)
    kolam.step(14)
    kolam.interpret(turtle)

    turtle.draw(im)

    im.show()
Beispiel #6
0
# Koch snowflake
class F(Var):
    def replace(self):
        return (F(), Plus(), F(), Minus(), Minus(), F(), Plus(), F())


# Constants
class SqrBracketOpen(Const):
    def __str__(self):
        return "["


class SqrBracketClose(Const):
    def __str__(self):
        return "]"


class Plus(Const):
    def __str__(self):
        return "+"


class Minus(Const):
    def __str__(self):
        return "-"


# LSystems
algae = lambda: LSystem((A(), ))
fractal_binary_tree = lambda: LSystem((Zero(), ))
koch_snowflake = lambda: LSystem((F(), ))
Beispiel #7
0
    pass

class F(Forward, Var):
    def replace(self):
        x = self.dist
        return (
            S(x),
            Push(), R(80), T(10), Pop(),
            Push(), R(-80), T(10), Pop(),
            F(x)
        )

class T(Forward, Var):
    def replace(self):
        x = self.dist
        return (T(x*1.2),)

class S(Forward, Const):
    pass


if __name__ == "__main__":
    im = Image.new("RGB", (1000, 1000))
    turtle = Turtle([500, 1000], -90)

    system = LSystem((F(50), ))
    system.step(14)
    system.interpret(turtle)

    turtle.draw(im)
    im.show()