POV-Ray : Newsgroups : povray.general : L-Systems in Povray Server Time
28 Apr 2024 03:33:24 EDT (-0400)
  L-Systems in Povray (Message 11 to 20 of 64)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Bald Eagle
Subject: Re: L-Systems in Povray
Date: 31 May 2023 18:25:00
Message: <web.6477c887453cebfc1f9dae3025979125@news.povray.org>
"Droj" <803### [at] drojde> wrote:

> No, it's not the shortcomings of the developer's documentation. I was lamenting
> about my own shortcomings not being able to add some little code which outputs a
> file with something like 'sphere - cylinder -'. The developer is innocent.

Well, you can search the povray website - or perhaps the wayback machine, and
look for the #read and #write directives.
But I can assure you that we have puzzled out such things before.
That's a lot of what user "yesbird" was working on.

Just write out what you want in pseudocode, and it may just wind up in a .pov or
..inc file for you.   ;)

> I did not know that you have such a 'wiki' treasure cove. At the moment I do not
> use Povray 3.8 (still 3.7) but I will try your treasures when beta phase is
> over.

Yes, things like user pages on the wiki are a little bit harder to find, even
when we know that they exist....

- BE


Post a reply to this message

From: jr
Subject: Re: L-Systems in Povray
Date: 1 Jun 2023 10:20:00
Message: <web.6478a906453cebfcb49d80446cde94f1@news.povray.org>
hi,

"Droj" <803### [at] drojde> wrote:
> ...
> At the moment I do not
> use Povray 3.8 (still 3.7) but I will try your treasures when beta phase is
> over.

patience is a virtue.  </grin>


regards, jr.


Post a reply to this message

From: Droj
Subject: Re: L-Systems in Povray
Date: 2 Jun 2023 16:40:00
Message: <web.647a5205453cebfc2064eda13b2af915@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> hi,
>
> "Droj" <803### [at] drojde> wrote:
> > ...
> > At the moment I do not
> > use Povray 3.8 (still 3.7) but I will try your treasures when beta phase is
> > over.
>
> patience is a virtue.  </grin>
>
>
> regards, jr.

hi jr,

> patience is a virtue.  </grin>
>
how true!
I developed that virtue to more or less perfection after using Povray
(as a bloody user of course) for more than 35 years.
But you know:
No vices, no virtue   </huge_grin>

cheers, Droj


Post a reply to this message

From: Droj
Subject: Re: L-Systems in Povray
Date: 2 Jun 2023 17:20:00
Message: <web.647a5974453cebfc2064eda13b2af915@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Droj" <803### [at] drojde> wrote:
>
> > No, it's not the shortcomings of the developer's documentation. I was lamenting
> > about my own shortcomings not being able to add some little code which outputs a
> > file with something like 'sphere - cylinder -'. The developer is innocent.
>
> Well, you can search the povray website - or perhaps the wayback machine, and
> look for the #read and #write directives.
> But I can assure you that we have puzzled out such things before.
> That's a lot of what user "yesbird" was working on.
>
> Just write out what you want in pseudocode, and it may just wind up in a .pov or
> ..inc file for you.   ;)
>
> > I did not know that you have such a 'wiki' treasure cove. At the moment I do not
> > use Povray 3.8 (still 3.7) but I will try your treasures when beta phase is
> > over.
>
> Yes, things like user pages on the wiki are a little bit harder to find, even
> when we know that they exist....
>
> - BE

Hi BE,

> Well, you can search the povray website - or perhaps the wayback machine, and
> look for the #read and #write directives.
> But I can assure you that we have puzzled out such things before.
>
Yep, maybe that's the only way but it's like searching a needle in a haystack.
And the catch is even if I find something I do not have the slightest idea where
to hook in.
BE, thanks for your advice and for sending me to the right direction.

> Yes, things like user pages on the wiki are a little bit harder to find, even
> when we know that they exist....
>
Right, wonders never cease. Well might be a good time to explore.

> Just write out what you want in pseudocode, and it may just wind up in a .pov or
> ..inc file for you.   ;)
>

Pseudocode?? Is pseudocode catching (truely sorry about that)? It means: I have
no clue.

- Droj


Post a reply to this message

From: Bald Eagle
Subject: Re: L-Systems in Povray
Date: 2 Jun 2023 17:50:00
Message: <web.647a6338453cebfc1f9dae3025979125@news.povray.org>
"Droj" <803### [at] drojde> wrote:

> > Just write out what you want in pseudocode, and it may just wind up in a .pov or
> > ..inc file for you.   ;)

What you do is just write what you'd like to see the code do.  As though you
were writing code, but you just describe the goal instead of using a real
computer language.

You can use SDL to make exactly what you want clearer, but just write down
anything you want and pretend like it would actually work.

Then someone can go, "Oh, that's not too hard..." and translate it into working
SDL.


#declare Radius = 1;
Write untextured sphere to file
#declare P = pigment {bozo}
Write pigmented sphere to file

.... etc


Post a reply to this message

From: Droj
Subject: Re: L-Systems in Povray
Date: 3 Jun 2023 14:50:00
Message: <web.647b8a2a453cebfc4e78ec763b2af915@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Droj" <803### [at] drojde> wrote:
>
> > > Just write out what you want in pseudocode, and it may just wind up in a .pov or
> > > ..inc file for you.   ;)
>
> What you do is just write what you'd like to see the code do.  As though you
> were writing code, but you just describe the goal instead of using a real
> computer language.
>
> You can use SDL to make exactly what you want clearer, but just write down
> anything you want and pretend like it would actually work.
>
> Then someone can go, "Oh, that's not too hard..." and translate it into working
> SDL.
>
>
> #declare Radius = 1;
> Write untextured sphere to file
> #declare P = pigment {bozo}
> Write pigmented sphere to file
>
> .... etc

Hi BE,

understood! I am going to gather my marbles and try your 'hideous' approach.
Maybe the guys here devour me alive or worse: ban me from using the forum.
Nevertheless you are a well of secret wisdom.

Cheers Droj


Post a reply to this message

From: ingo
Subject: Re: L-Systems in Povray
Date: 4 Jun 2023 04:50:00
Message: <web.647c4eab453cebfc17bac71e8ffb8ce3@news.povray.org>
Never tried a L-system in POV-Ray, so gave it a go this morning. It's a bit
crude and simple but works.

First a long string is generated from the axiom and a dict with rules. Then the
resulting string is used to generate vertices based upon the build rule macros.
Finally the vertices are used for cylinders.

---%<------%<------%<---
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 }}

//build rules
#declare BuildRules = dictionary;

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

#macro Plus(Pos)
  <Pos.x, Pos.y, Pos.z + (pi/2)>
#end
#declare BuildRules["+"] = 43;

#macro Min(Pos)
  <Pos.x, Pos.y, Pos.z - (pi/2)>
#end
#declare BuildRules["-"] = 45;
//


#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 Pos = <0, 0, 0>; // <x, y, angle>
  #local Return = array{<Pos.x, Pos.y>};

  #for (i, 0, strlen(Lstr)-1)
    #local CurrentSymbol = substr(Lstr, i, 1);
    #ifdef (BuildRules[CurrentSymbol])
      #switch (BuildRules[CurrentSymbol])
        #case(70)
          #local Pos = F(Pos);
        #break
        #case(43)
          #local Pos = Plus(Pos);
        #break
        #case(45)
          #local Pos = Min(Pos);
        #break
      #end
      #local InArr = Return[dimension_size(Return,1)-1];
      #if (Pos.x != InArr.x | Pos.y != InArr.y)
        #local Return[dimension_size(Return,1)] = <Pos.x, Pos.y>;
      #end
    #end
  #end
  Return
#end

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

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

#declare Vertices = Lvertices(Lstr);

#for(i, 0, dimension_size(Vertices,1)-2)
  cylinder{
    Vertices[i],Vertices[i+1],0.1
    texture{pigment{rgb 1}}
  }
#end

camera{
  location <-20,0,-40>
  look_at <-20,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: Cousin Ricky
Subject: Re: L-Systems in Povray
Date: 4 Jun 2023 11:55:00
Message: <web.647cb27f453cebfc60e0cc3d949c357d@news.povray.org>
"Droj" <803### [at] drojde> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > "Droj" <803### [at] drojde> wrote:
> >
> > > > Just write out what you want in pseudocode, and it may just wind up in a .pov
or
> > > > ..inc file for you.   ;)
>
> understood! I am going to gather my marbles and try your 'hideous' approach.
> Maybe the guys here devour me alive or worse: ban me from using the forum.
> Nevertheless you are a well of secret wisdom.

Software engineers write pseudocode all the time.  It helps clarify the thought
process.


Post a reply to this message

From: Droj
Subject: Re: L-Systems in Povray
Date: 4 Jun 2023 19:05:00
Message: <web.647d134f453cebfc812b1a4a3b2af915@news.povray.org>
"ingo" <nomail@nomail> wrote:
> Never tried a L-system in POV-Ray, so gave it a go this morning. It's a bit
> crude and simple but works.
>
> First a long string is generated from the axiom and a dict with rules. Then the
> resulting string is used to generate vertices based upon the build rule macros.
> Finally the vertices are used for cylinders.
>
> ---%<------%<------%<---
> 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 }}
>
> //build rules
> #declare BuildRules = dictionary;
>
> #macro F(Pos)
>   <Pos.x + cos(Pos.z), Pos.y + sin(Pos.z), Pos.z> // <x, y, angle>
> #end
> #declare BuildRules["F"] = 70; //chr(70) = F
>
> #macro Plus(Pos)
>   <Pos.x, Pos.y, Pos.z + (pi/2)>
> #end
> #declare BuildRules["+"] = 43;
>
> #macro Min(Pos)
>   <Pos.x, Pos.y, Pos.z - (pi/2)>
> #end
> #declare BuildRules["-"] = 45;
> //
>
>
> #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 Pos = <0, 0, 0>; // <x, y, angle>
>   #local Return = array{<Pos.x, Pos.y>};
>
>   #for (i, 0, strlen(Lstr)-1)
>     #local CurrentSymbol = substr(Lstr, i, 1);
>     #ifdef (BuildRules[CurrentSymbol])
>       #switch (BuildRules[CurrentSymbol])
>         #case(70)
>           #local Pos = F(Pos);
>         #break
>         #case(43)
>           #local Pos = Plus(Pos);
>         #break
>         #case(45)
>           #local Pos = Min(Pos);
>         #break
>       #end
>       #local InArr = Return[dimension_size(Return,1)-1];
>       #if (Pos.x != InArr.x | Pos.y != InArr.y)
>         #local Return[dimension_size(Return,1)] = <Pos.x, Pos.y>;
>       #end
>     #end
>   #end
>   Return
> #end
>
> #declare Axiom = "FX";
> #declare Rules = dictionary{
>   ["X"] : "X+YF",
>   ["Y"] : "FX-Y"
> }
> #declare Iterations = 12;
>
> #declare Lstr = Ltransform(Axiom, Rules, Iterations);
>
> #declare Vertices = Lvertices(Lstr);
>
> #for(i, 0, dimension_size(Vertices,1)-2)
>   cylinder{
>     Vertices[i],Vertices[i+1],0.1
>     texture{pigment{rgb 1}}
>   }
> #end
>
> camera{
>   location <-20,0,-40>
>   look_at <-20,0,0>
>   angle 120
>   right x*image_width/image_height
> }
>
> light_source{
>   <3000,3000,-3000>
>   color rgb 1
> }
>
> ---%<------%<------%<---

Hi Ingo,

I was so excited to test your code I simply copied it and started it in Povray
not aware that I use version 3.7. So Povray showed me the finger.
I quickly installed 3.8 beta2 and alas: your code worked flawlessly!
The LSystem Dragon curve!

I could not refrain from testing some more - and see what I came up with.
(had to change angle from pi/2 to 2*pi/var in order to get 60 and 72 degrees)

Thank you so much sharing your code and for supporting the idea of giving
L-systems a chance in POV-Ray. I guess you know that L-systems are not
restricted to 2D although turtles (of turtle graphics) don't climb trees.

I would love to see how you implement the third dimension!

Regards, Droj


Post a reply to this message


Attachments:
Download 'lsys4.png' (333 KB)

Preview of image 'lsys4.png'
lsys4.png


 

From: ingo
Subject: Re: L-Systems in Povray
Date: 5 Jun 2023 01:35:00
Message: <web.647d72b5453cebfc17bac71e8ffb8ce3@news.povray.org>
"Droj" <803### [at] drojde> wrote:


> I would love to see how you implement the third dimension!
>

Go ahead Droj,

grab the code and experiment. I abused the vector to make it work for 2d + angle
in a single data container. For 3, or more, dimensions, you have to separate
angle and position. Use two separate vectors or arrays. Or use a dictionary that
contains the pos and angle and other stuff you want to add in the future. For
example a LIFO array as a stack for push and pop operations.

#macro F(Pos, Angle)
  ....
#end

For me it was a proof of concept and I'll keep it that way. No new rabbit hole
for me at the moment.

Cheers,

ingo


Post a reply to this message

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

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