POV-Ray : Newsgroups : povray.newusers : Tips on code : Re: Tips on code Server Time
4 Nov 2024 13:04:15 EST (-0500)
  Re: Tips on code  
From: Francois Labreque
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

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