POV-Ray : Newsgroups : povray.newusers : trying to animate with the color_map : Re: trying to animate with the color_map Server Time
28 Jul 2024 12:31:27 EDT (-0400)
  Re: trying to animate with the color_map  
From: Chris B
Date: 19 Mar 2009 13:02:22
Message: <49c27a9e@news.povray.org>
"The_FD" <nomail@nomail> wrote in message 
news:web.49c26ef7c67a81a0d3bf6faf0@news.povray.org...
> Hello,
>
> this is the second time I pop my head in there... I am still pretty new to
> Povray.

Welcome back :-)

> Here is how you could help:
> I am building an animation in which the color of an object will vary with 
> time.
> Here is how the color is given to the object (I removed the object from 
> the
> code to make this message shorter):
>
> #declare i=1;
> #while (i<imax)
>  pigment {
>    gradient x
>    color_map {
>      [0.00 rgbt <0,0,Sv(i),0.7>]
>      [1.00 rgbt <Sa(i),0,0,0.4>]
>    }
>    scale 28
>    translate <-14,0,0>
>  }
> #declare i=i+1;
> #end
>
> Now I need to get the values of Sa and Sv from a .csv file. I just don't 
> now how
> to transfer them in an array in Povray and then get a given value of Sa 
> and Sv
> in each loop
>

I'm assuming,(as clipka did), that, you probably only want to get one pair 
of values for each frame of the animation. Here's an example of using the 
#read to do that. Assuming you have a file 'ngtest88.csv' containing:

0.1,0.9,
0.2,0.8,
0.3,0.7,
0.4,0.6,
0.5,0.5

Then you can use the following code to read all of the values into two 
arrays. You probably only actually need the values corresponding to the 
current frame number. Note that the array syntax uses square brackets not 
round ones.


#declare Sv = array [100];
#declare Sa = array [100];

#fopen MyFile "ngtest88.csv" read
#local MyCounter = 0;
#while (defined(MyFile))
  #read (MyFile,Var1,Var2)
  #declare Sv[MyCounter] = Var1;
  #declare Sa[MyCounter] = Var2;
  #local MyCounter = MyCounter+1;
#end
#fclose MyFile

// ... Your single pigment statement goes in here
#debug concat("Sv: ",str(Sv[frame_number],1,2),"\n")
#debug concat("Sa: ",str(Sa[frame_number],1,2),"\n")


In fact you probably don't really need the arrays, in which case this 
simplifies down to:


#fopen MyFile "ngtest88.csv" read
#local MyCounter = 0;
#while (MyCounter<=frame_number)
  #read (MyFile,Var1,Var2)
  #local MyCounter = MyCounter+1;
#end
#fclose MyFile

// ... Your single pigment statement goes in here
#debug concat("Var1: ",str(Var1,1,2),"\n")
#debug concat("Var2: ",str(Var2,1,2),"\n")


ChrisB.


Post a reply to this message

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