POV-Ray : Newsgroups : povray.general : show a line in 3D ? : Re: show a line in 3D ? Server Time
3 Aug 2024 06:11:55 EDT (-0400)
  Re: show a line in 3D ?  
From: Harold
Date: 18 Jun 2004 15:20:16
Message: <40d34070$1@news.povray.org>
Wow, thanks Sputnik!
Yeah, I know it is awful POV code. Probably shouldn't
have shared it.

H


news:40d24a6d$1@news.povray.org...
> /*
>
> Hi Harold,
>
> you definitely should learn to use while loops,
> arrays and macros; I don't think your chart script
> is helpful for beginners.
>
> Your code is very edit-unfriendly -- just try to
> leave out the first three months and append three
> new months at the end. In your script extensive
> rearrangements would be required, in my version
> below only the data arrays need to be changed.
>
> Or assume you want other symbols for the blue
> graph: this would require changing 16 textures.
> In my code this is concentrated in a single place:
> the declaration of Box, used in the statement
> Sweep (CaliData, Box, Blue_Agate)
>
> Of course much more could be done: automatic
> adaption to the number of data points and the
> number of graphs, automatic determination of the
> range of the values and of nice min/max/stepsize
> for the y-axis, automatic fitting to the aspect
> ratio of the picture, ...
>
> This whole post is a POV-Ray scene file -- just
> render it at 800 by 600 with options
> // +SP4 +EP4 +GD +A0.3 +AM2 +R3 -FN
> to see an almost exact replica of your chart; then
> change the macros and have fun!
>
> I hope this didn't sound too rude, but as this was
> offered as help to a beginner, I had to react ...
>
>    Sputnik
>
>
> */
>
> //=========BEGIN POV===============================
> //--- POV Ray Line Chart Scene File --- 


>
> global_settings { assumed_gamma 2.2 }
> #include "colors.inc"
> #include "textures.inc"
> #include "shapes.inc"
>
>
> // ---------- Data -----------
>
> #declare ButteData = array [16] {
>   1.0337,
>   1.0155,
>   1.0074,
>   1.0398,
>   1.0196,
>   1.0115,
>   1.058 ,
>   1.058 ,
>   1.0721,
>   1.0742,
>   1.0984,
>   1.1065,
>   1.0863,
>   1.0519,
>   1.0438,
>   1.0641 }
>
> #declare CaliData = array [16] {
>   0.5581,
>   0.5568,
>   0.5586,
>   0.5595,
>   0.5585,
>   0.5549,
>   0.5537,
>   0.5540,
>   0.5534,
>   0.5576,
>   0.5531,
>   0.5503,
>   0.5519,
>   0.5493,
>   0.5518,
>   0.5499 }
>
> #declare Months = array [16] {
>   "Jul-01",
>   "Aug-01",
>   "Sep-01",
>   "Oct-01",
>   "Nov-01",
>   "Dec-01",
>   "Jan-02",
>   "Feb-02",
>   "Mar-02",
>   "Apr-02",
>   "May-02",
>   "Jun-02",
>   "Jul-02",
>   "Aug-02",
>   "Sep-02",
>   "Oct-02" }
>
> // ---------- macro to draw a data line and symbols -----------
>
> #macro Sweep (DataArray, Symbol, Tex)
>
>   union {
>
>     sphere_sweep {linear_spline 16,
>
>       #local Index = 0;
>       #while (Index<16)
>         <Index/10-.8, DataArray[Index], 0>, .01
>         #local Index = Index+1;
>       #end//while
>     }
>
>     #local Index = 0;
>     #while (Index<16)
>       object { Symbol translate <Index/10-.8, DataArray[Index], 0> }
>       #local Index = Index+1;
>     #end//while
>
>     texture {Tex}
>
>   }
>
> #end//macro Sweep
>
>
> // ---------- untextured symbols for data points -----------
>
> #declare Sphere = sphere { 0, 0.02 }
>
> #declare Box = box { -0.02, 0.02 rotate y*45 }
>
>
> // ---------- macro to draw vertical labels and lines -----------
>
> #macro LabelsAndLines (LabelTex, LineTex)
>
>   #local Index = 0;
>   #while (Index<=12)
>
>     text {ttf "times.ttf",str(Index/10,3,1), 0.5, 0
>       scale 0.05
>       texture {LabelTex}
>       translate <-0.9, Index/10, 0 >
>     }
>
>     sphere_sweep {linear_spline 2,
>       <-.81, Index/10, 0>, .002
>       < .71, Index/10, 0>, .002
>       texture {LineTex}
>     }
>
>     #local Index = Index+1;
>   #end//while
>
> #end//macro LabelsAndLines
>
>
> // ---------- macro to make centered text -----------
>
> #macro CenteredText (TTFFont, TextString, Thick)
>
>   #local Txt = text {ttf TTFFont, TextString, Thick, 0 }
>   #local Mid = max_extent(Txt)/2;
>
>   object { Txt translate -Mid*x }
>
> #end//macro CenteredText
>
>
> // ---------- macro to draw months and x-ticks -----------
>
> #macro MonthsAndTicks (MonthThick, MonthTex, TickTex)
>
>   #local Index = 0;
>   #while (Index<16)
>
>     object { CenteredText ("times.ttf", Months[Index], MonthThick)
>       scale 0.03
>       texture {MonthTex}
>       translate <Index/10-0.8, -0.05, 0>
>     }
>
>     cylinder { 0, 0.01*y, 0.002
>       texture {TickTex}
>       translate (Index/10-0.8)*x
>     }
>
>     #local Index = Index+1;
>   #end//while
>
> #end//macro LabelsAndLines
>
>
> // ---------- Lights, Camera, Action -----------
>
> //  Single camera
> #declare Camx=-0.1;
>
>  camera {location <Camx, 0.6, -3> look_at <Camx,0.6,0> angle 40}
>
>  light_source { < 10,10,-40> color rgb <1,1,1> }
>  light_source { <-30,20,-40> color rgb <0.75,0.75,0.75> }
>  light_source { <0.5,10,-12> color rgb <0.55,0.55,0.55> }
>
>
> background {Black}
>
> // Un-comment the following lines to check parameter values,
> //   put the name of the parameter after Str(
> //text {ttf  "crystal.ttf",  str(l1P1,8,4), 2, 0 translate <-1,1,-2>
> texture{White_Marble}}
> //text {ttf  "crystal.ttf",  str(l1P2,8,4), 2, 0 translate <-1,0,-2>
> texture{White_Marble}}
> //text {ttf  "crystal.ttf",  str(l1P3,8,4), 2, 0 translate <-1,-1,-2>
> texture{White_Marble}}
>
> //#declare VertScale =  0.03658 ;
>
>
> // draw it all (short, readable, editable, isn't it?)
>
> Sweep (ButteData, Sphere, PinkAlabaster)
> Sweep (CaliData, Box, Blue_Agate)
> LabelsAndLines (PinkAlabaster, Blue_Agate)
> MonthsAndTicks (0.5, PinkAlabaster, Blue_Agate)
>
>
> object { CenteredText ("times.ttf", "Out of Home Placements", 1)
>   scale 0.10
>   texture {pigment{color rgb <1.9,1.2,0.15>}}
>   translate <   0, 1.35, 0.2  >
>   rotate x*-1 // why this?!?
> }
>
> object { CenteredText ("times.ttf", "Butte County and California", 1)
>   scale 0.06
>   texture {pigment{color rgb <1.2,1.1,0.05>}}
>   translate <   0, 1.27, 0.23 >
>   rotate x*-1
> }
>
> text {
>   ttf "timesi.ttf",
>   "Source: California Department of Social Services, Research and
> Development Division",
>   1, 0
>   scale 0.025
>   texture {PinkAlabaster}
>   translate <-1.05, -0.1, 0>
> }
>
> object { CenteredText ("times.ttf", "", 2)
>   scale 0.20
>   texture {PinkAlabaster}
>   translate 2.2*x
>   rotate y*10
> }
>
> object { CenteredText ("times.ttf", "Percent of Youth Population", 1)
>   scale 0.045
>   texture {PinkAlabaster}
>   rotate <-8,0,90>
>   translate < -0.95, 0.6,  0   >
> }
>
> object { CenteredText ("times.ttf", "", 2)
>   scale 0.08
>   texture {PinkAlabaster}
>   translate <0,-1.47,-4.5 >
>   rotate x*5
> }
>
> // ========= That's all =================
>
>


Post a reply to this message

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