POV-Ray : Newsgroups : povray.newusers : Tips on code Server Time
4 Nov 2024 17:36:33 EST (-0500)
  Tips on code (Message 1 to 7 of 7)  
From: Loek Peters
Subject: Tips on code
Date: 5 Aug 2003 08:32:13
Message: <3f2fa3cd$1@news.povray.org>
Hello all

Is there a way to optimize the code I have writen, or is this the shortes
way to this shape?

Thanx
Loek Peters

// begin
#include "colors.inc"
background { color Black }

camera  {
        location <0, 0, 10>
        look_at  <0, 0,  -1>
        }

light_source { <1, 3, 6> color White}

declare myTexture =
        texture {
                pigment { color rgb <0.56,0.35,0.30> }
                normal { bumps 0.7 scale 0.02 }
                finish {ambient 0.27 diffuse 0.8 phong 0.2}
                }
        }

declare rod = union {
        sphere {
                <0, 3, 2>, 0.5
                }
        sphere {
                <0, -3, 2>, 0.5
                }
        cylinder {
                <0, 3, 2>,
                <0, -3, 2>,
                0.5
                }
        texture { myTexture }
        }

difference {
        intersection{
                object { rod }
                box {
                <-0.6, -3.6,   1>,
                < 0.6, 3.6,  2>
                }
                texture { myTexture }
        }
                object {rod scale <-0.7, 0.954, 0>}
                object {rod scale <-0.1, 0.875, 1> translate <0,0,-0.5>}
  }
//end


Post a reply to this message

From: Christoph Hormann
Subject: Re: Tips on code
Date: 5 Aug 2003 11:59:13
Message: <3F2FD450.96DE30BF@gmx.de>
Loek Peters wrote:
> 
> Hello all

Hello.

> Is there a way to optimize the code I have writen, or is this the shortes
> way to this shape?

Shortest?

background{rgb 0}camera{location 10*z 
look_at-z}light_source{<1,3,6>1}#declare 
T=texture{pigment{rgb<.56,.35,.3>}normal{bumps.7 
scale.02}finish{ambient.27 diffuse.8 phong.2}}#declare 
R=union{sphere{<0,3,2>,.5}sphere{<0,-3, 2>,.5}cylinder{
<0,3,2>,<0,-3,2>,.5}texture{T}}difference{intersection{
object{R}box{<-.6,-3.6,1>,<.6,3.6,2>}texture{T}}object{R 
scale<-.7,.954,>}object{R scale<-.1,.875,1>translate<0,0,-.5>}} 

(i am sure ABX can significantly improve this of course...)

But i have the impression this is not what you wanted to know...

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 17 Jun. 2003 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: ABX
Subject: Re: Tips on code
Date: 5 Aug 2003 12:16:18
Message: <2plvivgur7vcbff694eghqm3v0tqs5ckfo@4ax.com>
On Tue, 05 Aug 2003 17:59:12 +0200, Christoph Hormann <chr### [at] gmxde>
wrote:
> background{rgb 0}

background{0}

>finish{ambient.27 diffuse.8 phong.2}

finish{ambient.27diffuse.8phong.2}

>sphere{<0,3,2>,.5}sphere{<0,-3, 2>,.5}cylinder{<0,3,2>,<0,-3,2>,.5}

sphere{<0,3,2>.5}sphere{<0,-3,2>.5}cylinder{<0,3,2><0,-3,2>.5}

> (i am sure ABX can significantly improve this of course...)

i am sure Warp can be even better :-)

> But i have the impression this is not what you wanted to know...

Using macros from shapes.inc can make it shorter probably but I also think
something different was expected.

ABX


Post a reply to this message

From: Jeffry Reifel
Subject: Re: Tips on code
Date: 5 Aug 2003 15:20:43
Message: <3f30038b@news.povray.org>
"Loek Peters" <loe### [at] hotmailcom> wrote in message
news:3f2fa3cd$1@news.povray.org...
> Hello all
>
> Is there a way to optimize the code I have writen, or is this the shortes
> way to this shape?
>
> Thanx
> Loek Peters
>
> // begin
> #include "colors.inc"
> background { color Black }
>
> camera  {
>         location <0, 0, 10>
>         look_at  <0, 0,  -1>
>         }
>
> light_source { <1, 3, 6> color White}
>
> declare myTexture =
>         texture {
>                 pigment { color rgb <0.56,0.35,0.30> }
>                 normal { bumps 0.7 scale 0.02 }
>                 finish {ambient 0.27 diffuse 0.8 phong 0.2}
>                 }
>         }
>
> declare rod = union {
>         sphere {
>                 <0, 3, 2>, 0.5
>                 }
>         sphere {
>                 <0, -3, 2>, 0.5
>                 }
>         cylinder {
>                 <0, 3, 2>,
>                 <0, -3, 2>,
>                 0.5
>                 }
>         texture { myTexture }
>         }
>
> difference {
>         intersection{
>                 object { rod }
>                 box {
>                 <-0.6, -3.6,   1>,
>                 < 0.6, 3.6,  2>
>                 }
>                 texture { myTexture }
>         }
>                 object {rod scale <-0.7, 0.954, 0>}
>                 object {rod scale <-0.1, 0.875, 1> translate <0,0,-0.5>}
>   }
> //end
// This is as short as I could get it.

#macro _(R,O,D)blob{threshold.01cylinder{<0,3,-2><0,-3,-2>.5,1scale<R,O
>translate z*D}}#end difference{_(1,1,0)_(.7.954,0)_(.1.875.5)box{-<1,4
2><1,4,-3>}pigment{rgb<.56.35.3>}normal{bumps.7scale.02}finish{ambient
.27diffuse.8phong.2}translate z*11}light_source{<-1,3,-6>1}//rod

//Would someone like to take a crack at shortening mine?

#macro _(J,E,F)sphere{J,1,1rotate z*E-20translate<F,0,24-A>pigment{rgb
9/A}}#end#local B=-1;blob{#while(B<1)#local C=6*sin(B*5+3);#local A=3*
abs(sin(B*3));_(<B-A,C-7*B-1>,2,-4)_(<2*sin(B*3-1)+B,3*sin(B*3-3)+2*B>
,-22,-1)_(<A+B,C-7*B>,9,1)_(<A+B,C-7*B>,9,5)#local B=B+.01;#end}//jef


Post a reply to this message

From: Francois Labreque
Subject: Re: Tips on code
Date: 5 Aug 2003 20:06:57
Message: <3f3046a1$1@news.povray.org>
Program ended abnormally on 2003-08-05 08:33, Due to a catastrophic Loek
Peters error:
> Hello all
> 
> Is there a way to optimize the code I have writen, or is this the shortes
> way to this shape?
> 
> Thanx
> Loek Peters
> 
> // begin
> #include "colors.inc"

Not required.

> background { color Black }
> 

Not required.  The default background is black.

> camera  {
>         location <0, 0, 10>
>         look_at  <0, 0,  -1>
>         }
> 

camera  {
         location z*10
         look_at -z
         }

> light_source { <1, 3, 6> color White}

light_source { < 1, 3, 6 > color rgb 1}

> 
> declare myTexture =
>         texture {
>                 pigment { color rgb <0.56,0.35,0.30> }
>                 normal { bumps 0.7 scale 0.02 }
>                 finish {ambient 0.27 diffuse 0.8 phong 0.2}
>                 }
>         }

No need for a #declared texture as everything uses the same.

> 
> declare rod = union {
>         sphere {
>                 <0, 3, 2>, 0.5
>                 }
>         sphere {
>                 <0, -3, 2>, 0.5
>                 }
>         cylinder {
>                 <0, 3, 2>,
>                 <0, -3, 2>,
>                 0.5
>                 }
>         texture { myTexture }
>         }
> 

#declare P = < 0, 3, 2 >;
#declare rod = union {
         sphere{ P, 0.5 }
         sphere{ P-6*y, 0.5 }
         cylinder{ P, P-6*y, 0.5 }
         }
// no need to texture the rod as the same texture will be applied to the whole 
object below.


> difference {
>         intersection{
>                 object { rod }
>                 box {
>                 <-0.6, -3.6,   1>,
>                 < 0.6, 3.6,  2>
>                 }
>                 texture { myTexture }
>         }
>                 object {rod scale <-0.7, 0.954, 0>}
>                 object {rod scale <-0.1, 0.875, 1> translate <0,0,-0.5>}
>   }
> //end
> 

difference {
         intersection {
                  object { rod }
                  box { < -0.6, -3.6, 1 > < 0.6, 3.6, 2 > }
                  }
         object{ rod scale < -0.7, 0.954, 1 > } // don't scale by 0!!!!
         object{ rod scale < -0.1, 0.875, 1 > translate -0.5*z }
         texture{
                 pigment { color rgb <0.56,0.35,0.30> }
                 normal { bumps 0.7 scale 0.02 }
                 finish {ambient 0.27 diffuse 0.8 phong 0.2}
                 }
         }
//end

Or in short form:

camera{location z*10look_at-z}light_source{<1,3,6>color 1}#local P=<0,3,2>;
#local R=union{sphere{P,.5}sphere{P-6*y,.5}cylinder{P,P-6*y,.5}}difference{
intersection{object{R}box{<-.6,-3.6,1><.6,3.6,2>}}object{R scale<-.7,.954,1>} 
object{R scale<-.1,.875,1>translate -0.5*z}texture{pigment{color <.56,.35,.3>} 
normal{bumps.7scale.02}finish{ambient.27diffuse.8phong.2}}}




-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   videotron.ca  */}camera{orthographic location<6,1.25,-6>look_at a }


Post a reply to this message

From: Warp
Subject: Re: Tips on code
Date: 6 Aug 2003 05:36:11
Message: <3f30cc0b@news.povray.org>
Francois Labreque <fla### [at] videotronca> wrote:
>> light_source { <1, 3, 6> color White}

> light_source { < 1, 3, 6 > color rgb 1}

  You don't mean light_source { <1,3,6>, 1 } ?

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Friedrich A  Lohmueller
Subject: Re: Tips on code
Date: 6 Aug 2003 17:13:48
Message: <3F316F5C.15B06196@t-online.de>
Loek Peters wrote:
> 
> Hello all
> 
> Is there a way to optimize the code I have writen, or is this the shortes
> way to this shape?
> 

Just a more serious answer:
Try this
// begin --------------------------------------------------------------
#include "colors.inc"
background { color Black }

camera  {
        location <0, 0, 10>
        look_at  <0, 0,  -1>
        }

light_source { <1, 3, 6> color White}

declare MyTexture =
        texture {
                pigment { color rgb <0.56,0.35,0.30> }
                normal { bumps 0.7 scale 0.02 }
                finish {ambient 0.27 diffuse 0.8 phong 0.2}
                }
        }
// Hint: use capitals for the first letters of objects defined by your
own!
//       Otherwise sooner or later you'll hit a reserved word!
declare Rod = union {
        sphere {
                <0, 3,  0>, 0.5
                }
        sphere {
                <0, -3, 0>, 0.5
                }
        cylinder {
                <0,  3, 0>,
                <0, -3, 0>,
                0.5
                }
//        texture { myTexture }
// Hint: use textures like wood at the end of caved out objects 
//       otherwise the grain may not be consequent on objects objects
with csg  
// Hint: declare symmetric objects right at zero! 
// Much easier to immagine what's going on there!!!
        }

difference {
                object { Rod }
                box    {  // a box to the other side!
                         <-0.6, -3.6,  0>,
                         < 0.6,  3.6,  1>
                       }
//              object {rod scale <-0.7, 0.954, 0>}
//                                      //scale 0 is "nonsense"!!!
                object {Rod scale <-0.7, 0.954, 1> }
                object {Rod scale <-0.1, 0.875, 1> translate <0,0,-0.5>}

                texture { MyTexture }
                translate<0,0,2>
  }
//end  -------------------------------------------------------------

// -----------------------------------------------------------------
//      intersection { A with B }
//    = difference   { A with NotB }

//      difference   { intersection { A with B)  minus C  minus  D } 
//    = difference   { A  minus NotB  minus C  minus  D }
// -----------------------------------------------------------------

Greetings


Friedrich  

------------------------------------------------------
email: Fri### [at] t-onlinede

homepage of Andrea and Friedrich Lohmueller:
http://www.f-lohmueller.de/index.htm
my students workshop raytracing gallery and the
homepage of the computer graphics course at KHS-school:
http://khs-kappeln.lernnetz.de/cg/cindex_e.htm
----------------------------------------------------end


Post a reply to this message

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