POV-Ray : Newsgroups : povray.general : LSystems and Turtle-Like movement : Re: LSystems and Turtle-Like movement Server Time
30 Jul 2024 22:17:18 EDT (-0400)
  Re: LSystems and Turtle-Like movement  
From: Paolo Gibellini
Date: 5 May 2008 05:36:55
Message: <481ed537@news.povray.org>
Hallo, Hugo!
Years ago I wrote a L-Systems parser in POV-Ray.
Perhaps could be interesting for you compare the sources:

http://ozviz.wasp.uwa.edu.au/~pbourke/exhibition/povfrac/final/0025.pov

Bye,
    ;-)
    Paolo

 >Bytter wrote:
> 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.