POV-Ray : Newsgroups : povray.newusers : trying to animate with the color_map Server Time
1 Nov 2024 10:18:17 EDT (-0400)
  trying to animate with the color_map (Message 1 to 4 of 4)  
From: The FD
Subject: trying to animate with the color_map
Date: 19 Mar 2009 12:15:01
Message: <web.49c26ef7c67a81a0d3bf6faf0@news.povray.org>
Hello,

this is the second time I pop my head in there... I am still pretty new to
Povray.

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

Does anyone have a tip for doing that?

Thank you so much in advance


Post a reply to this message

From: clipka
Subject: Re: trying to animate with the color_map
Date: 19 Mar 2009 12:40:00
Message: <web.49c2747ee1f54028f708085d0@news.povray.org>
"The_FD" <nomail@nomail> wrote:
> 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 {
....
>   }
> #declare i=i+1;
> #end

Are you aware that this will give you imax "pigment" statements? This usually
doesn't make any sense at all.

For animations, you should do something with the clock value or frame number.

Note that your SDL code should *always* generate the scene stuff for *one*
single frame, parameterized by either the clock value or frame number. It will
be parsed over and over again, once for each frame, with different values for
these parameters.


To read from a .csv file, use the "#fopen", "#read" and "#fclose" statements. To
read into an array, set up the array first (specifying the expected max number
of entries), then #read in a loop. See the online doc for details, including
how to detect end-of-file in case you are not sure in advance how many entries
you will actually have.


Post a reply to this message

From: Chris B
Subject: Re: trying to animate with the color_map
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

From: The FD
Subject: Re: trying to animate with the color_map
Date: 20 Mar 2009 10:00:00
Message: <web.49c3a018e1f54028d3bf6faf0@news.povray.org>
Thank you to both of you that really helped.
I finally picked up the following:

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

#fopen data "data_essai.txt" read
#local i = 0;
#while (defined(data))
  #read (data,Var1,Var2)
  #declare Sa[i] = Var1;
  #declare Sv[i] = Var2;
  #local i = i+1;
#end
#fclose data


#debug concat("Sv: ",str(Sv[clock*10],1,2),"\n")
#debug concat("Sa: ",str(Sa[clock*10],1,2),"\n")

//and then in the object the color goes:

  pigment {
    gradient x
    color_map {
      [0.00 rgbt <0,0,Sv[clock*10],0.7>]
      [1.00 rgbt <Sa[clock*10],0,0,0.4>]
    }
    scale 28
    translate <-14,0,0>
  }

Thanks again
and talk to you soon around


Post a reply to this message

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