POV-Ray : Newsgroups : povray.general : Clock intervals Server Time: 17 Dec 2018 00:23:51 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


Post a reply to this message

From: Bald Eagle
Subject: Re: Clock intervals
Date: 17 Jul 2018 22:15:00
Message: <web.5b4e693829c714e5458c7afe0@news.povray.org>
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


Post a reply to this message

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


Post a reply to this message

From: Bald Eagle
Subject: Re: Clock intervals
Date: 17 Jul 2018 22:55:01
Message: <web.5b4e72c429c714e5458c7afe0@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:
> You have both a lowercase 'n' and a uppercase 'N'. Is that intentional?

Whoops - no, I was ... multitasking.


Post a reply to this message

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


Additionally, I like to add acceleration/deceleration to the move. So:
  #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%)


Post a reply to this message

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)
	#local time_adj = -1;
	#switch (clock)
		#range (0, tim_beg)
			#local time_adj = 0;
		#break
		#range (tim_beg, tim_end)
			#local t1 = clock - tim_beg;
			#local t2 = tim_end - tim_beg;
			#local time_adj = t1/t2;
		#break
		#range (tim_end, 1)
			#local time_adj = 1;
		#break
		#else
			// Do nothing
		#break
	#end
	time_adj
#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.
> 
> 
> 
>


Post a reply to this message

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
> 
> 
> Additionally, I like to add acceleration/deceleration to the move. So:
>    #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;
>


Post a reply to this message

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 ;


Post a reply to this message

From: Bald Eagle
Subject: Re: Clock intervals
Date: 18 Jul 2018 22:40:01
Message: <web.5b4fc1bc29c714e5458c7afe0@news.povray.org>
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!

:)


Post a reply to this message

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.


Post a reply to this message

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