POV-Ray : Newsgroups : povray.general : L-Systems in Povray Server Time
13 Jul 2025 20:11:39 EDT (-0400)
  L-Systems in Povray (Message 46 to 55 of 64)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 9 Messages >>>
From: ingo
Subject: Re: L-Systems in Povray
Date: 12 Jul 2023 13:05:00
Message: <web.64aedcd4453cebfc17bac71e8ffb8ce3@news.povray.org>
"Droj" <803### [at] drojde> wrote:

worked a bit on you lsys7. Simplified a few minor things. Changed a bit in
LVertices and added debugging.

We're at "Parse Error: Expected 'RValue to declare', End of File found instead"
now.

ingo


---%<---------%<---------%<---
/*Pov-Ray    : 3.8
Scene File : lsys.pov
Author     : Ingo Janssen
Date       : 2023-06-04
*/
#version 3.8;

global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}

#declare T_Pos = <0, 0, 0>;
#declare A_F = 14; // Angle increment
#declare Max_Items = 200;
#declare Curr_Items = 0;
#declare VXY_Arr = array[Max_Items]; // Pos stack for xy-plane
#declare AZZ_Arr = array[Max_Items]; // Angle stack for xy-plane


//build rules
#declare BuildRules = dictionary;


#macro F(T_Pos, AngleZZ)
 #local T_Pos = <0, 0, 0>;
    <T_Pos.x + cos(AngleZZ), T_Pos.y + sin(AngleZZ), T_Pos.z> // <x, y, 0>
#end
#declare BuildRules["F"] = 70; //chr(70) = F


#macro YawR(AngleZZ)
 #local AngleZZ = 0;
  AngleZZ + (tau/A_F)
#end
#declare BuildRules["+"] = 43;


#macro YawL(AngleZZ)
 #local AngleZZ = 0;
  AngleZZ - (tau/A_F)
#end
#declare BuildRules["-"] = 45;


#macro Turn(AngleZZ)
 #local AngleZZ = 0;
   AngleZZ - (tau/2)
#end
#declare BuildRules["|"] = 124;


// the following macros are needed for branching
#macro Push(T_Pos, AngleZZ)
  #declare VXY_Arr[Curr_Items] = T_Pos;
  #declare AZZ_Arr[Curr_Items] = AngleZZ;
  #declare Curr_Items = Curr_Items + 1;
#end
#declare BuildRules["["] = 91;


#macro Pop(T_Pos, AngleZZ)
  #declare Curr_Items = Curr_Items - 1;
  #declare T_Pos = VXY_Arr[Curr_Items];
  #declare AngleZZ = AZZ_Arr[Curr_Items];
#end
#declare BuildRules["]"] = 93;

//

// I left Ingo's brilliant rewrite macro untouched
#macro Ltransform(Axiom, Rules, Iterations)
  #local Result = Axiom;
  #for (i, 1, Iterations)
      #local NewResult = "";
      #local N = strlen(Result);
      #local j = 1;
      #while (j <= N)
        #local CurrentSymbol = substr(Result, j, 1);
        #ifdef(Rules[CurrentSymbol])
          #local NewResult = concat(NewResult, Rules[CurrentSymbol]);
        #else
          #local NewResult = concat(NewResult, CurrentSymbol);
        #end
        #local j = j + 1;
      #end
      #local Result = NewResult;
      #debug concat(Result, "\n")
  #end
  Result
#end


#macro Lvertices(Lstr)
  #local T_Pos = <0, 0, 0>; // <x, y, z>
  #local AngleZZ = 0;
  //#local Curr_Item = 0;
  #declare Return = array; //{<T_Pos.x, T_Pos.y, T_Pos.z>};
 #declare Return[0] = <T_Pos.x, T_Pos.y, T_Pos.z>;
  #for (i, 0, strlen(Lstr)-1)
    #local CurrentSymbol = substr(Lstr, i, 1);
    #ifdef (BuildRules[CurrentSymbol])
      #switch (BuildRules[CurrentSymbol])
        #case(70)
          #debug "70 F \n"
          #local T_Pos = F(T_Pos, AngleZZ);
        #break
        #case(43)
          #debug "43 + \n"
          #local AngleZZ = YawR(AngleZZ);
        #break
        #case(45)
          #debug "45 - \n"
          #local AngleZZ = YawL(AngleZZ);
        #break
        #case(124)
          #debug "124 | \n"
          #local AngleZZ = Turn(AngleZZ);
        #break

        #case(91)
          #debug "91 [ \n"
          #local Curr_Item = Push(T_Pos, AngleZZ);
        #break


        #case(93)
          #debug "93 ] \n"
          #local Curr_Item = Pop(T_Pos, AngleZZ);
        #break

      #end
      #local InArr = Return[dimension_size(Return,1)-1];
      #if (T_Pos.x != InArr.x | T_Pos.y != InArr.y | T_Pos.z != InArr.z)
        #declare Return[dimension_size(Return,1)] = <T_Pos.x, T_Pos.y, T_Pos.z>;
      #end
    #end
  #end
  #declare Vertices = Return;
  Vertices
#end

#declare Axiom = "FFFFX";
#declare Rules = dictionary{
  ["X"] : "F[-FX][+FX]",
  ["Y"] : "FX-Y"
};
#declare Iterations = 1;

#declare Lstr = Ltransform(Axiom, Rules, Iterations);

#declare Vertices = Lvertices(Lstr);

/*
#ifdef (Vertices)
 #debug "OK \n"
#else
 #debug "Undefined! \n"
#end
*/
/*#for(i, 0, dimension_size(Vertices,1)-2) // <== here Povray complains
  cylinder{
    Vertices[i],Vertices[i+1],0.1
    texture{pigment{rgb 1}}
    translate <-25, -5, 0>
    rotate <0, 0, 0>
  }
#end*/

camera{
  location <0,0,-30>
  look_at <0,0,0>
  angle 120
  right x*image_width/image_height
}

light_source{
  <3000,3000,-3000>
  color rgb 1
}
---%<---------%<---------%<---


Post a reply to this message

From: ingo
Subject: Re: L-Systems in Povray
Date: 12 Jul 2023 13:15:00
Message: <web.64aedf3b453cebfc17bac71e8ffb8ce3@news.povray.org>
"ingo" <nomail@nomail> wrote:

>
> #macro Lvertices(Lstr)
>   #local T_Pos = <0, 0, 0>; // <x, y, z>
>   #local AngleZZ = 0;
>   //#local Curr_Item = 0;
>   #declare Return = array; //{<T_Pos.x, T_Pos.y, T_Pos.z>};
>  #declare Return[0] = <T_Pos.x, T_Pos.y, T_Pos.z>;
>   #for (i, 0, strlen(Lstr)-1) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>     #local CurrentSymbol = substr(Lstr, i, 1);
>     #ifdef (BuildRules[CurrentSymbol])
>       #switch (BuildRules[CurrentSymbol])
>         #case(70)
>           #debug "70 F \n"
>           #local T_Pos = F(T_Pos, AngleZZ);
>         #break
>         #case(43)
>           #debug "43 + \n"
>           #local AngleZZ = YawR(AngleZZ);
>         #break
>         #case(45)
>           #debug "45 - \n"
>           #local AngleZZ = YawL(AngleZZ);
>         #break
>         #case(124)
>           #debug "124 | \n"
>           #local AngleZZ = Turn(AngleZZ);
>         #break
>
>         #case(91)
>           #debug "91 [ \n"
>           #local Curr_Item = Push(T_Pos, AngleZZ);
>         #break
>
>
>         #case(93)
>           #debug "93 ] \n"
>           #local Curr_Item = Pop(T_Pos, AngleZZ);
>         #break
>
>       #end
>       #local InArr = Return[dimension_size(Return,1)-1];
>       #if (T_Pos.x != InArr.x | T_Pos.y != InArr.y | T_Pos.z != InArr.z)
>         #declare Return[dimension_size(Return,1)] = <T_Pos.x, T_Pos.y, T_Pos.z>;
>       #end
>     #end
>   #end
>   #declare Vertices = Return;
>   Vertices
> #end

  try: #for (i, 0, strlen(Lstr)) in the macro. The it runs and renders a small
white stick? But with Iterations = 2 it fails.

ingo


Post a reply to this message

From: ingo
Subject: Re: L-Systems in Povray
Date: 12 Jul 2023 14:15:00
Message: <web.64aeeca8453cebfc17bac71e8ffb8ce3@news.povray.org>
Try this.
Your pop and push macros didn't return anything.
image looks strange.

ingo

/*Pov-Ray    : 3.8
Scene File : lsys.pov
Author     : Ingo Janssen
Date       : 2023-06-04
*/
#version 3.8;

global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}

#declare T_Pos = <0, 0, 0>;
#declare A_F = 14; // Angle increment
#declare Max_Items = 200;
//#declare Curr_Items = 0;
#declare VXY_Arr = array[Max_Items]; // Pos stack for xy-plane
#declare AZZ_Arr = array[Max_Items]; // Angle stack for xy-plane


//build rules
#declare BuildRules = dictionary;


#macro F(T_Pos, AngleZZ)
 #local T_Pos = <0, 0, 0>;
    <T_Pos.x + cos(AngleZZ), T_Pos.y + sin(AngleZZ), T_Pos.z> // <x, y, 0>
#end
#declare BuildRules["F"] = 70; //chr(70) = F


#macro YawR(AngleZZ)
 #local AngleZZ = 0;
  AngleZZ + (tau/A_F)
#end
#declare BuildRules["+"] = 43;


#macro YawL(AngleZZ)
 #local AngleZZ = 0;
  AngleZZ - (tau/A_F)
#end
#declare BuildRules["-"] = 45;


#macro Turn(AngleZZ)
 #local AngleZZ = 0;
   AngleZZ - (tau/2)
#end
#declare BuildRules["|"] = 124;


// the following macros are needed for branching
#macro Push(Curr_Item, T_Pos, AngleZZ)
  #debug "push macro runs\n"
  #declare VXY_Arr[Curr_Item] = T_Pos;
  #declare AZZ_Arr[Curr_Item] = AngleZZ;
  #local Curr_Item = Curr_Item + 1;
  Curr_Item
#end
#declare BuildRules["["] = 91;


#macro Pop(Curr_Item, T_Pos, AngleZZ)
  #debug "pop macro runs\n"
  #local Curr_Item = Curr_Item - 1;
  #declare T_Pos = VXY_Arr[Curr_Item];
  #declare AngleZZ = AZZ_Arr[Curr_Item];
  Curr_Item
#end
#declare BuildRules["]"] = 93;

//

// I left Ingo's brilliant rewrite macro untouched
#macro Ltransform(Axiom, Rules, Iterations)
  #local Result = Axiom;
  #for (i, 1, Iterations)
      #local NewResult = "";
      #local N = strlen(Result);
      #local j = 1;
      #while (j <= N)
        #local CurrentSymbol = substr(Result, j, 1);
        #ifdef(Rules[CurrentSymbol])
          #local NewResult = concat(NewResult, Rules[CurrentSymbol]);
        #else
          #local NewResult = concat(NewResult, CurrentSymbol);
        #end
        #local j = j + 1;
      #end
      #local Result = NewResult;
      #debug concat(Result, "\n")
  #end
  Result
#end


#macro Lvertices(Lstr)
  #local T_Pos = <0, 0, 0>; // <x, y, z>
  #local AngleZZ = 0;
  #local Curr_Item = 0;
  #declare Return = array; //{<T_Pos.x, T_Pos.y, T_Pos.z>};
 #declare Return[0] = <T_Pos.x, T_Pos.y, T_Pos.z>;
  #for (i, 0, strlen(Lstr))
    #local CurrentSymbol = substr(Lstr, i, 1);
    #ifdef (BuildRules[CurrentSymbol])
      #switch (BuildRules[CurrentSymbol])
        #case(70)
          #debug "70 F \n"
          #local T_Pos = F(T_Pos, AngleZZ);
        #break
        #case(43)
          #debug "43 + \n"
          #local AngleZZ = YawR(AngleZZ);
        #break
        #case(45)
          #debug "45 - \n"
          #local AngleZZ = YawL(AngleZZ);
        #break
        #case(124)
          #debug "124 | \n"
          #local AngleZZ = Turn(AngleZZ);
        #break
        #case(91)
          #debug "91 [ \n"
          #local Curr_Item = Push(Curr_Item, T_Pos, AngleZZ);
        #break
        #case(93)
          #debug "93 ] \n"
          #local Curr_Item = Pop(Curr_Item, T_Pos, AngleZZ);
        #break
      #end
      #local InArr = Return[dimension_size(Return,1)-1];
      #if (T_Pos.x != InArr.x | T_Pos.y != InArr.y | T_Pos.z != InArr.z)
        #declare Return[dimension_size(Return,1)] = <T_Pos.x, T_Pos.y, T_Pos.z>;
      #end
    #end
  #end
  #declare Vertices = Return;
  Vertices
#end

#declare Axiom = "FFFFX";
#declare Rules = dictionary{
  ["X"] : "F[-FX][+FX]",
  ["Y"] : "FX-Y"
};
#declare Iterations = 6;

#declare Lstr = Ltransform(Axiom, Rules, Iterations);

#declare Vertices = Lvertices(Lstr);


#ifdef (Vertices)
 #debug "OK \n"
#else
 #debug "Undefined! \n"
#end

#for(i, 0, dimension_size(Vertices,1)-2) // <== here Povray complains
  cylinder{
    Vertices[i],Vertices[i+1],0.1
    texture{pigment{rgb 1}}
    translate <-25, -5, 0>
    rotate <0, 0, 0>
  }
#end

camera{
  location <0,0,-30>
  look_at <0,0,0>
  angle 120
  right x*image_width/image_height
}

light_source{
  <3000,3000,-3000>
  color rgb 1
}


Post a reply to this message

From: Droj
Subject: Re: L-Systems in Povray
Date: 12 Jul 2023 16:10:00
Message: <web.64af07a7453cebfc763e4a273b2af915@news.povray.org>
"ingo" <nomail@nomail> wrote:
> Try this.
> Your pop and push macros didn't return anything.
> image looks strange.
>
> ingo
>
Hi,
Gee, I didn't want to open a new rabbit hole for you.

I tried your code and yes: the image DOES look strange.
It seems like the whole thing stops after 1 iteration not knowing where to go
next or what to do next.

But at least Povray does not complain anymore.

I suppose you cannot borrow me your 'muse with the glass eye' for a moment or
two just to find out what's wrong with my push and pop macros.

I promise I'm shaven and like to photograph.

See how this thing we are talking about should look like.

Thanks for your patience

Droj


Post a reply to this message


Attachments:
Download 'ls_plants01.png' (363 KB)

Preview of image 'ls_plants01.png'
ls_plants01.png


 

From: ingo
Subject: Re: L-Systems in Povray
Date: 13 Jul 2023 00:50:00
Message: <web.64af815b453cebfc17bac71e8ffb8ce3@news.povray.org>
"Droj" <803### [at] drojde> wrote:
> I tried your code and yes: the image DOES look strange.
> It seems like the whole thing stops after 1 iteration not knowing where to go
> next or what to do next.
>

Next thing to do is to debug the stack content and the vertices content.

Where it probably goes wrong:
The first point is added to the array and from then on only the "end points"
(last endpoint is next start point). But when branching you need a new start
point. That gets confusing. It is probably better to write [startpoint,
endpoint] to the array. The loop it with a stride of 2.

ingo


Post a reply to this message

From: jr
Subject: Re: L-Systems in Povray
Date: 16 Jul 2023 16:45:00
Message: <web.64b455ce453cebfc80c03e9d6cde94f1@news.povray.org>
hi,

"ingo" <nomail@nomail> wrote:
> ...
> Next thing to do is to debug the stack content and the vertices content.

see attached for 'Vertices' content.  something's amiss :-)


regards, jr.


Post a reply to this message


Attachments:
Download 'droj_ingo.png' (13 KB)

Preview of image 'droj_ingo.png'
droj_ingo.png


 

From: jr
Subject: Re: L-Systems in Povray
Date: 16 Jul 2023 16:45:00
Message: <web.64b4563c453cebfc80c03e9d6cde94f1@news.povray.org>
hi,

"Droj" <803### [at] drojde> wrote:
> ...
> See how this thing we are talking about should look like.

fwiw, I really like(d) 'lsys3'.  made me think that it is v close to a Hilbert
Curve, and it'd be interesting to find the right "production rules" for that.


regards, jr.


Post a reply to this message

From: Droj
Subject: Re: L-Systems in Povray
Date: 17 Jul 2023 12:15:00
Message: <web.64b566de453cebfcdec7f1e73b2af915@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> hi,
>
> "Droj" <803### [at] drojde> wrote:
> > ...
> > See how this thing we are talking about should look like.
>
> fwiw, I really like(d) 'lsys3'.  made me think that it is v close to a Hilbert
> Curve, and it'd be interesting to find the right "production rules" for that.
>
>
> regards, jr.

Hi,

yes indeed looks similar to Hilbert curve. If I remember correctly it's called
Peano curve and here is Hilbert curve.

I saw your screenshot of debugging the stack/vertices content and it looks like
the whole thing loops in itself.

Axiom and production rule(s) look okay but the 'turtle' seems to be stuck in a
tar pit.

At the moment I have no idea how to get rid of the glitch. I tried using a
vector expression for the angles but Povray simply shut down.

regards, Droj

PS: Could you let me know how you debugged the stack getting a list of contents?


Post a reply to this message


Attachments:
Download 'lsys9.pov.txt' (3 KB)

From: jr
Subject: Re: L-Systems in Povray
Date: 17 Jul 2023 12:50:00
Message: <web.64b5711c453cebfc80c03e9d6cde94f1@news.povray.org>
hi,

"Droj" <803### [at] drojde> wrote:
> ...
> yes indeed looks similar to Hilbert curve. If I remember correctly it's called
> Peano curve and here is Hilbert curve.

thank you, very much.  (for later tonight :-))


> ...
> PS: Could you let me know how you debugged the stack getting a list of contents?

attached the "playing around" copy.  :-)  hth.


regards, jr.


Post a reply to this message


Attachments:
Download 'droj_dbg.pov.txt' (5 KB)

From: Droj
Subject: Re: L-Systems in Povray
Date: 17 Jul 2023 13:40:00
Message: <web.64b57bd8453cebfcdec7f1e73b2af915@news.povray.org>
Hi,

"jr" <cre### [at] gmailcom> wrote:
>
> thank you, very much.  (for later tonight :-))
>

you are more than welcome (hope you don't do overtime <grin>)

>
> attached the "playing around" copy.  :-)  hth.
>

thank you so much for the copy - I will put it in my treasure box.

The "foreach.inc" is not a standard inc-file, I guess.
Can I find it somewhere in the forum or is it something out of your treasure
box?

Cheers, Droj

PS: I have to check what TOK posted (L-system of course). Seems like I caused a
palace revolution :-))


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 9 Messages >>>

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