This is a simple lstrings implementation in python. Do lots of iterations to see some pretty output (empty lines omitted).
What are LStrings? LStrings are strings with three possible characters: ‘f’ – meaning forward, ‘l’ meaning left, and ‘r’ meaning right. Drawing such a string is easy – just like ‘ye olde Logo’. So far nothing interesting – until you iterate on them. Iterating on a string means replacing each occurrence of ‘f’ with the original string. This gives a fractal like behavior, and can actually be used to draw some fractals.
Here is the example usage:
(note: the ASCII-art output was edited (underscores instead of spaces. WordPress is killing me) and lots of empty lines removed)
>>> s = "flfrfrflf"
#this code outputs to a file.
>>> a = lstrings.create_array(90)
>>> lstrings.plot_lstring(lstrings.iterate(s,3), -1,-1, a)
>>> lstrings.draw_array(a, "temp.txt")
#output to screen
>>> a = lstrings.create_array(60)
>>> lstrings.plot_lstring(lstrings.iterate(s,1), -1,-1, a)
>>> lstrings.draw_array(a)
________###________
________#_#________
______###_###______
______#_____#______
____###_____###____
____#_________#____
__#####_____#####__
__#_#_#_____#_#_#__
###_###_____###_###
>>>
Leave a Reply