3

The problem statement is as follows:

"Given an L-System with an alphabet set, an axiom, a set of rewriting rules, and a set of geometric rules in bijection with the alphabet set, how do we find the equivalent set of Iterated Function System (IFS) transformations (which includes but does not exhausts - translations, rotations and scalings)?"

Roughly, an L-System is a character rewriting system, where you start with an initial string (the axiom), and go on changing the characters according to the rewriting rules. To give it a geometric interpretation, you can associate an element of drawing and that gives you the diagram.

This is a python implementation of an L-System that generates the Koch Curve using Turtle.

import time
from turtle import *
from progress.bar import Bar


def Lrule(s):
    s2 = ''
    for i in range(len(s)):
        if s[i] == '>':
            s2 += '>+>-->+>' #rewriting rule
        else:
            s2 += s[i]
    return s2

def stringConstruct(n):
    axiom = '>' #initial string
    b = Bar('Creating string',fill = '=',max = n)
    for i in range(n):
        axiom = Lrule(axiom)
        b.next()
    return axiom

def drawit(distance,angle,n):
    s = stringConstruct(n)
    d = distance

    wn = Screen()
    t = Turtle()
    t.penup()
    t.back(700)
    t.right(90)
    t.forward(300)
    t.left(90)
    t.pendown()
    t.speed(0)

    for cmd in s:
        if cmd == '>':
            t.forward(d)
        elif cmd == '+':
            t.left(angle)
        elif cmd == '-':
            t.right(angle)
    wn.exitonclick()


if __name__ == '__main__':

    drawit(distance=5, angle=60, n=10)

An IFS is a set of contraction mappings or transformations that take a point to another point and tries to approximate the attractor set of the transformations.

A python implementation of IFS that generates the Koch Curve is given here. It is represented as a picture using the pillow library.

import random
from PIL import Image
from progress.bar import *
class snowflake(object):
    def __init__(self, img_width, img_height, paint_color=(19, 150, 100),
                 bg_color=(255, 255, 255)):
        self.img_width, self.img_height = img_width, img_height
        self.paint_color = paint_color
        self.x, self.y = 0, 0
        self.age = 0

        self.koch = Image.new('RGB', (img_width, img_height), bg_color)
        self.pix = self.koch.load()
        self.pix[self.scale(0, 0)] = paint_color


    def scale(self, x, y):
        h = (x)*(self.img_width-1)
        k = (0.7-y)*(self.img_height-1)
        return h, k

    def transform(self, x, y): #set of transformations
        rand = random.uniform(0, 100)#to make it more faster
        if rand < 25:
            return x/3, y/3
        elif 25 <= rand < 50:
            return (x-y*3**0.5+2)/6, (y+x*3**0.5)/6
        elif 50 <= rand < 75:
            return (x+y*3**0.5+3)/6, (y-x*3**0.5+3**0.5)/6
        else:
            return (x+2)/3, y/3

    def iterate(self, iterations):
        self.b = ChargingBar('Creating string',max = iterations, suffix='%(percent)d%%')
        for _ in range(iterations):
            self.b.next()
            self.x, self.y = self.transform(self.x, self.y)
            self.pix[self.scale(self.x, self.y)] = self.paint_color
        self.age += iterations

koch = snowflake(1080, 1080)
koch.iterate(200000)
koch.koch.show()

Upon going on it for a week, we formed the following conclusion:

  • Given an L-system with a set of drawing rules, such a set of transformations always exists.

But this doesn't help us except prove the existence.

We have coded L-Systems and IFS separately in python to generate the same fractals, but the relation relating one to the other is still unclear.

Is it possible to generate an algorithm to know (or generate) the IFS given the L-system with drawing rules? If yes, has it been done and what is it? If no, why is it not possible?

0 Answers0