POV-Ray : Newsgroups : povray.general : LSystems and Turtle-Like movement : LSystems and Turtle-Like movement Server Time
30 Jul 2024 22:16:57 EDT (-0400)
  LSystems and Turtle-Like movement  
From: Bytter
Date: 3 May 2008 13:00:01
Message: <web.481c99c8de4dbeeaaae9c1ef0@news.povray.org>
Hi!

I'm having a difficult time trying to cope with relative movement and
translation using POVRay for an implementation of an LSystem. I don't want the
generator to be aware of the real-size of objects.

For example, for an expression like "FF", my generator gives me this:

union { object { ramo translate -x }  ramo translate -x }

where 'ramo' is a macro that draw a twig. For "F+F-F", it gives me this:

union { object {union { object {union { object {union { object { ramo translate
-x }  rotate -z*90 }}  ramo translate -x }}  rotate  z*90 }}  ramo translate -x
}

It is getting a little verbose, but this is the best I've got so far. However,
I'm finding hard to cope with '[' and ']', which should save the state and
probably be translated to a paralel (instead of recursive) union of objects.

This is the python code I'm writting to convert an L expression into a POV
object:

-------

result = "F+F-F"

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

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

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

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

print trans(result)

-------

Can anyone give me an hint here? Maybe there is another way to get relative
transformations in POV without using all that recursive definition?

Thanks in advance,

Hugo Sereno Ferreira


Post a reply to this message

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