|
![](/i/fill.gif) |
"stevenvh" <nomail@nomail> wrote in message
news:web.49893e4a14f123fac0721a1d0@news.povray.org...
> In my code I want to generate a series of prisms dynamically, where both
> the
> number of points and their coordinates are read from a file. I have no
> idea how
> to do this, so any hints be greatly appreciated.
> Regards,
> Steven
Or, if you want to #read straight from an existing data file that is in csv
format you can do that too. The only tricky bit with mixed data types (point
counts and coordinates) is making sure you don't get out of step when trying
to read the file. The end of the file needs to be quite tidy too (e.g. no
trailing comma on the last line), otherwise the end-of-file may not be
detected when it needs to be detected.
If you have a csv file containing:
7,
<-1 ,0>,
<-0.5,0>,
< 0 ,1>,
<-0.5,2>,
<-1 ,2>,
<-1.5,1>,
<-1 ,0>,
7,
< 1 ,0>,
< 0.5,0>,
< 0 ,1>,
< 0.5,2>,
< 1 ,2>,
< 1.5,1>,
< 1 ,0>
You can read this in and use it to draw prisms as follows:
camera {location <0,3,-2> look_at <0,1,1>}
light_source {<-10,20,50>, rgb 1}
// Randomisation seed is just for the color
#declare S = seed(3);
#fopen MyFile "datafile.csv" read
#while (defined(MyFile))
#read(MyFile,PointCount)
prism{
0,1,PointCount
#declare I=0;
#while(I<PointCount)
#undef ThisPoint
#read(MyFile,ThisPoint)
// Add this point into the prism:
ThisPoint
#declare I=I+1;
#end
pigment{rgb <rand(S),rand(S),rand(S)>}
}
#end
This uses two nested #while loops. The first reads the file till there's no
more values to read. Inside the first loop we read a value which needs to be
a whole number of points, then the second #while loop reads each point (uv
vector) in turn and uses it in the prism definition. When the first prism is
finished the outer loop looks for the next point count, and so on, until the
end of the file. You can add as many sets of points to the file as you need.
Regards,
Chris B.
Post a reply to this message
|
![](/i/fill.gif) |