POV-Ray : Newsgroups : povray.general : L-Systems in Povray Server Time
27 Jul 2024 20:17:34 EDT (-0400)
  L-Systems in Povray (Message 15 to 24 of 64)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
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

From: ingo
Subject: Re: L-Systems in Povray
Date: 5 Jun 2023 13:25:00
Message: <web.647e1a39453cebfc17bac71e8ffb8ce3@news.povray.org>
"ingo" <nomail@nomail> wrote:
>
> ---%<------%<------%<---
> 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;

A little bit of code to stick to the end of the lsys.pov scene file, render and
have a look in your source directory.

Just for fun and again, a little crude:

---%<------%<------%<---

#declare Height = 10;
#declare Width = 10;
#declare StrokeWidth = 0.3;
#declare FileName = "SVGfile.svg";

#fopen SVG FileName write
#write (SVG concat("<svg xmlns=\"http://www.w3.org/2000/svg\" height='",
str(Height,0,0), "' width='", str(Width,0,0), "' fill='blue' stroke='blue'
stroke-width='", str(StrokeWidth,0,3),"'>\n"))

#for(i, 0, dimension_size(Vertices,1)-2)
  #declare Line = concat("<line x1='", str(Vertices[i].x,0,1),"'
y1='",str(Vertices[i].y,0,1),"' x2='",str(Vertices[i+1].x,0,1),"'
y2='",str(Vertices[i+1].y,0,1),"'/>\n") ;
  #write(SVG Line)
#end
#fclose SVG

---%<------%<------%<---


Post a reply to this message

From: jr
Subject: Re: L-Systems in Povray
Date: 5 Jun 2023 15:55:00
Message: <web.647e3d46453cebfcb49d80446cde94f1@news.povray.org>
hi,

"ingo" <nomail@nomail> wrote:
> "ingo" <nomail@nomail> wrote:
> >
> > ---%<------%<------%<---
> > Pov-Ray    : 3.8
> > Scene File : lsys.pov
> > Author     : Ingo Janssen
> > Date       : 2023-06-04

have copied the code and run once, but not yet investigated.  looking forward to
that, though :-).


> A little bit of code to stick to the end of the lsys.pov scene file, render and
> have a look in your source directory.

missing the closing '</svg>'.  size too is .. suspect, I see only a small part
of the curve.  (sorry, hope to find some time tomorrow)


regards, jr.


Post a reply to this message

From: ingo
Subject: Re: L-Systems in Povray
Date: 5 Jun 2023 16:20:00
Message: <web.647e4364453cebfc17bac71e8ffb8ce3@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

> missing the closing '</svg>'.  size too is .. suspect, I see only a small part
> of the curve.  (sorry, hope to find some time tomorrow)

Ah, good catch on the closing tag.
I didn't scale it. Havingthe origin at the top left point of the screen always
makes my brain hurt.

ingo


Post a reply to this message

From: Droj
Subject: Re: L-Systems in Povray
Date: 6 Jun 2023 09:20:00
Message: <web.647f3222453cebfcf62c2adc3b2af915@news.povray.org>
"ingo" <nomail@nomail> wrote:
> "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

Ingo,

thanks for your advice. It will all take a WHILE. Have to learn coding first.

Cheers

Droj


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.