POV-Ray : Newsgroups : povray.general : Sphere with longitudes and latitudes? : Re: Sphere with longitudes and latitudes? Server Time
31 Jul 2024 10:17:14 EDT (-0400)
  Re: Sphere with longitudes and latitudes?  
From: Trevor G Quayle
Date: 8 Jan 2008 23:05:01
Message: <web.478447b8a8d0eaa2ae8612c0@news.povray.org>
No gridlines, stepped gradient, cutout outlined in black.
To remove outline, replace "pigment{PGrid}" with "pigment{HSL}" in the last
object.

//START

camera {
  location  <5,10,-10>
  right     x*image_width/image_height
  look_at   <0.0, 0.0,  0.0>
  angle 12
}

light_source {
  <30, 50, -40>
  rgb <1, 1, 1>
}

plane {
  y, -1
  pigment {rgb 1}
}

//HSL to RGB
#declare tHSL=function(H,C){(H/360+C/3)-floor(H/360+C/3)}
#declare qHSL=function(H,S,L){select(L-1/2,L*(1+S),L+S-L*S)}
#declare pHSL=function(H,S,L){2*L-qHSL(H,S,L)}
#declare CHSL=function(H,S,L,C)
{
  select(
    -S
  ,//S>0
    select(
      tHSL(H,C)-1/6
    ,//tc<1/6
      pHSL(H,S,L)+2*(qHSL(H,S,L)-L)*6*tHSL(H,C)
    ,
      select(
        tHSL(H,C)-1/2
      ,//tc<1/2
        qHSL(H,S,L)
      ,
        select(
          tHSL(H,C)-2/3
        ,//tc<2/3
          pHSL(H,S,L)+2*(qHSL(H,S,L)-L)*6*(2/3-tHSL(H,C))
        ,//esle
          pHSL(H,S,L)
        )
      )
    )
  ,//S=0
    L
  )
}
#declare RHSL=function (H,S,L){CHSL(H,S,L,+1)}
#declare GHSL=function (H,S,L){CHSL(H,S,L, 0)}
#declare BHSL=function (H,S,L){CHSL(H,S,L,-1)}
//END HSL to RGB


#declare LatDiv=6;    //Number of Latitude divisions, used for long too
(degrees= 90/LatDiv)
#declare GRDTHK=0.01;  //Line thickness for 1 unit radius sphere

#declare FX=function(x){360/(LatDiv*4)*int(x*LatDiv*4+0.5)}
#declare FY=function(y){int(y*LatDiv*2+0.5)/(LatDiv*2)}
#declare FZ=function(y){int(y*LatDiv+0.5)/LatDiv}

#declare FR= function(x,y,z){RHSL(FX(x),FZ(z),FY(y))}
#declare FG= function(x,y,z){GHSL(FX(x),FZ(z),FY(y))}
#declare FB= function(x,y,z){BHSL(FX(x),FZ(z),FY(y))}

#declare HSL=
pigment{
  average
  pigment_map{
    [function{   FR(x,y,z)   } color_map{[0 rgb 0][1 rgb <3,0,0>]}]
    [function{   FG(x,y,z)   } color_map{[0 rgb 0][1 rgb <0,3,0>]}]
    [function{   FB(x,y,z)   } color_map{[0 rgb 0][1 rgb <0,0,3>]}]
  }
  warp{spherical}
}

#declare AA=sin(GRDTHK/2);//GRDTHK*LatDiv/2/(pi*2/4);
#declare ABC=pigment{rgb 1}


#declare LONG =
intersection{
  union{
    torus{1,GRDTHK}
    torus{1,GRDTHK rotate x*90}
    torus{1,GRDTHK rotate z*90}
    cylinder{0,x,GRDTHK}
    cylinder{0,y,GRDTHK}
    cylinder{0,-z,GRDTHK}
  }
  box{<-1,-1,1>*GRDTHK,<1,1,-1>}
}

#declare PGrid=
pigment{
  object{
    LONG
    pigment{HSL}
    pigment{rgb 0}
  }
}

difference{
  sphere{0,1}
  box{0,<1,1,-1>}
  pigment{PGrid}//change to HSL for no black outlines
  finish{ambient 0 diffuse 0.5}
}

//END


Post a reply to this message

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