POV-Ray : Newsgroups : povray.general : LSystems and Turtle-Like movement : Re: LSystems and Turtle-Like movement Server Time
30 Jul 2024 22:20:35 EDT (-0400)
  Re: LSystems and Turtle-Like movement  
From: Bytter
Date: 3 May 2008 13:30:00
Message: <web.481c9fb8f9934732aae9c1ef0@news.povray.org>
I think I got it, maybe it can be usefull for someone:

------

# Convert expression to pov
angle = '20'
macros = {'F': ' ramo translate -x ',
          'X': ' ramo translate -x ',
          '-': ' rotate -z*' + angle + ' ',
          '+': ' rotate  z*' + angle + ' '}

def getsubstr(p):
 count = 1;
 pos = 0;
 while count > 0:
  if p[pos] == '[': count += 1
  if p[pos] == ']': count -= 1
  pos += 1;
 return p[:pos]

def applymacro(p):
 return macros.has_key(p) and macros[p] or ''

def trans(result):
 p = result[0]
 t = result[1:]

 if p == '[':
  sub  = getsubstr(t)
  newt = t[len(sub)+1:]
  return "union { object {" + trans(sub) + "} object {" + trans(newt) + "} }"

 if len(result) > 1:
  r = trans(t)
  if len(r) > 0:
   return "union { object {" + r + "} " + applymacro(p) + "}"

 return applymacro(p)

print trans(result)

------


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.