POV-Ray : Newsgroups : povray.newusers : Pulsing the color of an object : Re: Pulsing the color of an object Server Time
28 Jul 2024 14:27:31 EDT (-0400)
  Re: Pulsing the color of an object  
From: Chris B
Date: 11 Jan 2009 13:17:42
Message: <496a37c6@news.povray.org>
"james lake" <gum### [at] sprintmailcom> wrote in message 
news:web.496a24eb295358cc7352b36c0@news.povray.org...
> Hello:
>
> I am creating an animation of an object and want to pulse the color like 
> this:
>
> Red -> fade to -> White -> fade to -> Red -> fade to -> White -> fade 
> to -> Red
>
> And so on, depending on the length of that particular shot.
>
> Q: How can I do this?

Hi James,

Assuming you use command-line options, such as: +kfi0 +kff199 to generate a 
sequence of frames (in this case 200) you can either use the clock variable 
or the frame_number variable to control the color. The clock variable will 
vary from 0 to 1 during the animation cycle and frame_number will vary 
between 0 and 199.

The simplest way to code the color is to specify RGB colors rather than the 
predefined colors. For example, you can use:

  pigment {rgb <1,clock,clock>}

to move from Red to White once during the cycle in a linear way.

Or something like:

  #include "math.inc"
  #declare MyGB = 0.5*(cosd(clock*720)+1);
  pigment {rgb <1, MyGB, MyGB>}

to get a smooth cycle. This uses the cosine of an angle that cycles from 0 
to 720 to calculate a value for the Green and Blue channels. The cosine 
therefore cycles from 1 to -1, so adding one and dividing by 2 makes it 
cycle smoothly between 1 and 0 and back again, 4 times in a row. The Red 
channel is hardcoded as 1. Doubling the 720 to 1440 would give you twice as 
many complete color cycles within the animation cycle.

The following very short example provides a complete scene file for you to 
experiment with.
Regards,
Chris B.

// Use command-line options +kfi0 +kff59
// and render at 160x120, No AA

camera {location -5*z look_at <0,0,0>}
light_source { <-2, 3, -5>, rgb 1 }

#include "math.inc"
#declare MyGB = 0.5*(cosd(clock*720)+1);

sphere {0,1
  pigment {rgb <1, MyGB, MyGB>}
}


Post a reply to this message

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