|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
From: Paolo Gibellini
Subject: Re: LSystems and Turtle-Like movement
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
|
|
| |
| |
|
|
|
|
| |
|
|