POV-Ray : Newsgroups : povray.general : Clock intervals Server Time: 25 Jun 2019 20:28:10 GMT
 Clock intervals (Message 1 to 10 of 10)
 From: Mike Horvath Subject: Clock intervals Date: 17 Jul 2018 21:35:02 Message: <5b4e6106\$1@news.povray.org>
```I want to be able to tie a variable to the clock value, but only for
certain portions.

For example, the variable should be equal to 0 before the clock is 0.3,
and equal to one after the clock is equal to 0.6. In between 0.3 and 0.6
the clock should interpolate from 0 to 1.

How would I do this using a macro? Thanks.

Mike
```
 From: Bald Eagle Subject: Re: Clock intervals Date: 17 Jul 2018 22:15:00 Message:
```Mike Horvath <mik### [at] gmailcom> wrote:
> I want to be able to tie a variable to the clock value, but only for
> certain portions.
>
> For example, the variable should be equal to 0 before the clock is 0.3,
> and equal to one after the clock is equal to 0.6. In between 0.3 and 0.6
> the clock should interpolate from 0 to 1.
>
> How would I do this using a macro? Thanks.
>
>
> Mike

#version 3.7;
global_settings {assumed_gamma 1.0}

#declare epsilon = 1e-6;
#declare Frames = 100;

#for (N, 1, Frames)

#switch (N)

#range (0, 0.3)
#declare Clock = 0;
#break

#range (0.3, 0.6)
#declare Clock = (n-0.3)*(1/0.3);
#break

#range (0.6, 1.0)
#declare Clock = 1;
#break

#else
// Do nothing
#end // end switch - case/range - break

#debug concat ("Variable = ", str (Clock, 1, 3), "\n")

#end
```
 From: Mike Horvath Subject: Re: Clock intervals Date: 17 Jul 2018 22:26:33 Message: <5b4e6d19\$1@news.povray.org>
```You have both a lowercase 'n' and a uppercase 'N'. Is that intentional?

On 7/17/2018 6:10 PM, Bald Eagle wrote:
> #switch (N)
>
> #range (0, 0.3)
>   #declare Clock = 0;
> #break
>
> #range (0.3, 0.6)
>   #declare Clock = (n-0.3)*(1/0.3);
> #break
>
> #range (0.6, 1.0)
>   #declare Clock = 1;
> #break
>
> #else
> // Do nothing
> #end // end switch - case/range - break
```
 From: Bald Eagle Subject: Re: Clock intervals Date: 17 Jul 2018 22:55:01 Message:
```Mike Horvath <mik### [at] gmailcom> wrote:
> You have both a lowercase 'n' and a uppercase 'N'. Is that intentional?

Whoops - no, I was ... multitasking.
```
 From: dick balaska Subject: Re: Clock intervals Date: 18 Jul 2018 00:08:11 Message: <5b4e84eb\$1@news.povray.org>
```On 07/17/2018 05:36 PM, Mike Horvath wrote:
> I want to be able to tie a variable to the clock value, but only for
> certain portions.
>
> For example, the variable should be equal to 0 before the clock is 0.3,
> and equal to one after the clock is equal to 0.6. In between 0.3 and 0.6
> the clock should interpolate from 0 to 1.
>
> How would I do this using a macro? Thanks.
>
>
> Mike

This might be the single most common thing I do in my anim.

I never hardcode 0.3 in the code. Because you will likely want to tweak
it [1] and here you only have to change it in one place.

#declare Start=0.3;
#declare End = 0.6;

#switch (myclock)
#range (0,Start)
#declare Out=0;
#break
#range(Start, End)
#declare Out=AniSegment(Start,End);
#break
#range(End,1)
#declare Out=1;
#break
#end

///////////////////////////////////////////////////////////////////////////////////////////////////
// Animate this segment of the clock from 0 to 1
#macro AniSegment(_start, _end)
((myclock-_start)/(_end-_start))
#end

#range(Start, End)
#local F=AniSegment(Start,End);
#declare Out=Curve0(F);
#break

where

#declare pi2=(pi*2);

///////////////////////////////////////////////////////////////////////////////////////////////////
// Curves: see http://www.buckosoft.com/~dick/pov/curves/
#macro Curve0(_i)
(0.5-(cos(_i/2*pi2)/2))
#end

[1] This smells like you really want
#declare Start=1/3;
#declare End=2/3;

--
dik
Rendered 328976 of 330000 (99%)
```
 From: Mike Horvath Subject: Re: Clock intervals Date: 18 Jul 2018 00:08:57 Message: <5b4e8519\$1@news.povray.org>
```I was able to figure it out. Here's the completed macro:

#macro get_time(tim_beg, tim_end)
#switch (clock)
#range (0, tim_beg)
#break
#range (tim_beg, tim_end)
#local t1 = clock - tim_beg;
#local t2 = tim_end - tim_beg;
#break
#range (tim_end, 1)
#break
#else
// Do nothing
#break
#end
#end

I will probably use this a lot if I continue to make animations.

:)

Mike

On 7/17/2018 6:50 PM, Bald Eagle wrote:
> Mike Horvath <mik### [at] gmailcom> wrote:
>> You have both a lowercase 'n' and a uppercase 'N'. Is that intentional?
>
> Whoops - no, I was ... multitasking.
>
>
>
>
```
 From: Mike Horvath Subject: Re: Clock intervals Date: 18 Jul 2018 00:51:31 Message: <5b4e8f13\$1@news.povray.org>
```Changing the speed is a neat idea!

Mike

On 7/17/2018 8:08 PM, dick balaska wrote:
> On 07/17/2018 05:36 PM, Mike Horvath wrote:
>> I want to be able to tie a variable to the clock value, but only for
>> certain portions.
>>
>> For example, the variable should be equal to 0 before the clock is 0.3,
>> and equal to one after the clock is equal to 0.6. In between 0.3 and 0.6
>> the clock should interpolate from 0 to 1.
>>
>> How would I do this using a macro? Thanks.
>>
>>
>> Mike
>
> This might be the single most common thing I do in my anim.
>
> I never hardcode 0.3 in the code. Because you will likely want to tweak
> it [1] and here you only have to change it in one place.
>
> #declare Start=0.3;
> #declare End = 0.6;
>
> #switch (myclock)
>    #range (0,Start)
>      #declare Out=0;
>      #break
>    #range(Start, End)
>      #declare Out=AniSegment(Start,End);
>      #break
>    #range(End,1)
>      #declare Out=1;
>      #break
> #end
>
>
///////////////////////////////////////////////////////////////////////////////////////////////////
> // Animate this segment of the clock from 0 to 1
> #macro AniSegment(_start, _end)
>    ((myclock-_start)/(_end-_start))
> #end
>
>
>    #range(Start, End)
>      #local F=AniSegment(Start,End);
>      #declare Out=Curve0(F);
>      #break
>
> where
>
> #declare pi2=(pi*2);
>
>
///////////////////////////////////////////////////////////////////////////////////////////////////
> // Curves: see http://www.buckosoft.com/~dick/pov/curves/
> #macro Curve0(_i)
>    (0.5-(cos(_i/2*pi2)/2))
> #end
>
>
> [1] This smells like you really want
>      #declare Start=1/3;
>      #declare End=2/3;
>
```
 From: Le Forgeron Subject: Re: Clock intervals Date: 18 Jul 2018 03:24:40 Message: <5b4eb2f8\$1@news.povray.org>
```Le 17/07/2018 Ã  23:36, Mike Horvath a Ã©critÂ :
> I want to be able to tie a variable to the clock value, but only for
> certain portions.
>
> For example, the variable should be equal to 0 before the clock is 0.3,
> and equal to one after the clock is equal to 0.6. In between 0.3 and 0.6
> the clock should interpolate from 0 to 1.
>
> How would I do this using a macro? Thanks.
>
>
> Mike

I saw the answers with macro, and you asked for macro, but you could
have used a linear spline instead.

#declare Spline = spline { linear_spline
0, 0,
0.3, 0,
0.6, 1,
1, 1
};

#declare Variable = Spline(clock).x ;
```
 From: Bald Eagle Subject: Re: Clock intervals Date: 18 Jul 2018 22:40:01 Message:
```Le_Forgeron <jgr### [at] freefr> wrote:

> I saw the answers with macro, and you asked for macro, but you could
> have used a linear spline instead.
>
> #declare Spline = spline { linear_spline
>   0, 0,
>   0.3, 0,
>   0.6, 1,
>   1, 1
> };
>
> #declare Variable = Spline(clock).x ;

Jerome:
This is VERY nice and elegant.
I figured it could be done with a spline, but I don't often use them and just
wanted to help solve the problem with a quick answer - but this is much better!

:)
```
 From: clipka Subject: Re: Clock intervals Date: 18 Jul 2018 22:58:38 Message: <5b4fc61e\$1@news.povray.org>
```Am 19.07.2018 um 00:39 schrieb Bald Eagle:
> Le_Forgeron <jgr### [at] freefr> wrote:
>
>> I saw the answers with macro, and you asked for macro, but you could
>> have used a linear spline instead.
>>
>> #declare Spline = spline { linear_spline
>>   0, 0,
>>   0.3, 0,
>>   0.6, 1,
>>   1, 1
>> };
>>
>> #declare Variable = Spline(clock).x ;
>
> Jerome:
> This is VERY nice and elegant.
> I figured it could be done with a spline, but I don't often use them and just
> wanted to help solve the problem with a quick answer - but this is much better!

I agree. The spline-based approach also has the added benefit that it
can be used to smoothly speed up and slow down some movement, by using
non-linear splines.
```