POV-Ray : Newsgroups : povray.newusers : Pulsing the color of an object Server Time
1 Nov 2024 12:24:19 EDT (-0400)
  Pulsing the color of an object (Message 1 to 4 of 4)  
From: james lake
Subject: Pulsing the color of an object
Date: 11 Jan 2009 12:00:00
Message: <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?

Thanks,

James


Post a reply to this message

From: Chris B
Subject: Re: Pulsing the color of an object
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

From: Stephen
Subject: Re: Pulsing the color of an object
Date: 11 Jan 2009 13:22:00
Message: <j5ekm4lq01irfc034l5vpskdt3kvcodk6s@4ax.com>
On Sun, 11 Jan 2009 11:57:15 EST, "james lake" <gum### [at] sprintmailcom> wrote:

>And so on, depending on the length of that particular shot.
>
>Q: How can I do this?

Just to add to Chris's answer: What you want to do is not difficult but it
depends on exactly what you want. 
The "clock" or "frame_number" variables are the key. Read about them in the help
file 3.2.1.3.6  Built-in Variables.
You might also want to use the #switch directive. 3.2.2.6.3  The #switch, #case,
#range and #break Directives
-- 

Regards
     Stephen


Post a reply to this message

From: james lake
Subject: Re: Pulsing the color of an object
Date: 11 Jan 2009 15:10:00
Message: <web.496a50e93deb915b7352b36c0@news.povray.org>
Thanks to both of you.  It works great!

James


Post a reply to this message

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