POV-Ray : Newsgroups : povray.advanced-users : Randomly timed events Server Time
22 Dec 2024 21:13:03 EST (-0500)
  Randomly timed events (Message 1 to 7 of 7)  
From: Bald Eagle
Subject: Randomly timed events
Date: 29 Aug 2013 08:25:00
Message: <web.521f3cdb71b5bb97dd2ebc560@news.povray.org>
I'm trying to do a quick and dirty simulation of lightning flashes with
momentarily appearing point light_sources in a scene, and it appears that I
don't get any flashes except coincidentally and suspiciously in what appears to
be the very last frame.

All I'm doing right now is

#if (Flash = clock)
light_source { < rand(FlashX), rand(FlashY), rand(FlashZ) > color rgb <1,1,1> *
rand(Brightness) }
#end

I'm thinking that I need to "open the window" of where the random value and the
clock coincide to increase the probability of a flash - although I'm concerned
that my lack of insight into pseudo-random numbers in POV-Ray might doom me to
pre-destined failure here...  (See other thread on random placement of objects)

Has anyone worked with this type of thing before?
Helpful suggestions?


Post a reply to this message

From: scott
Subject: Re: Randomly timed events
Date: 29 Aug 2013 09:16:50
Message: <521f49c2$1@news.povray.org>
> All I'm doing right now is
>
> #if (Flash = clock)
> light_source { < rand(FlashX), rand(FlashY), rand(FlashZ) > color rgb <1,1,1> *
> rand(Brightness) }
> #end

How are you defining the variables Flash, FlashX, FlashY, FlashZ, 
Brightness?


Post a reply to this message

From: Bald Eagle
Subject: Re: Randomly timed events
Date: 29 Aug 2013 10:15:01
Message: <web.521f5729fc2c9d36dd2ebc560@news.povray.org>
> How are you defining the variables Flash, FlashX, FlashY, FlashZ,
> Brightness?

#declare Flash = seed (1);
#declare Brightness = seed (2);
#declare FlashX = seed (3);
#declare FlashY = seed (4);
#declare FlashZ = seed (5);


Post a reply to this message

From: scott
Subject: Re: Randomly timed events
Date: 29 Aug 2013 10:55:58
Message: <521f60fe$1@news.povray.org>
>> How are you defining the variables Flash, FlashX, FlashY, FlashZ,
>> Brightness?
>
> #declare Flash = seed (1);
> #declare Brightness = seed (2);
> #declare FlashX = seed (3);
> #declare FlashY = seed (4);
> #declare FlashZ = seed (5);

There is no real reason to create a separate seed for every random 
variable, you can just keep calling rand() on the same seed and it will 
keep generating new random numbers.

I guess you probably meant to write:

#if( rand(Flash) = clock )

But that won't work as you want, because rand() returns a float between 
0 and 1 and it's extremely unlikely to ever equal your clock value. If 
you want your flash to last just one frame try something like:

#declare Flash = seed(1);
...
#declare flashFrame = int( rand(Flash) * final_frame);
#if( frame_number = flashFrame)
...

Or if you want your flash to last a specific amount of clock (eg 0.1):

#declare flashStart = rand(Flash) * final_clock;
#if( clock>flashStart & clock<flashStart+0.1)
...

Note this will create the flash at exactly the same frame every time you 
run the animation - because the first random number generated after 
seed(1) is always the same.


Post a reply to this message

From: Bald Eagle
Subject: Re: Randomly timed events
Date: 29 Aug 2013 11:35:01
Message: <web.521f69a1fc2c9d36dd2ebc560@news.povray.org>
> I guess you probably meant to write:
>
> #if( rand(Flash) = clock )

Oops.  Late-night POV coding strikes again.

> But that won't work as you want, because rand() returns a float between
> 0 and 1 and it's extremely unlikely to ever equal your clock value.

Yes, that's what I was worried about, and with some food and coffee fueling the
brain, I can likely see just how probable the unlikelihood of the clock and
random number probably, or improbably matching is, or isn't.  Though that could
change.  :D

>If  you want your flash to last just one frame try something like:
>
> #declare Flash = seed(1);
> ...
> #declare flashFrame = int( rand(Flash) * final_frame);
> #if( frame_number = flashFrame)
> ...
>
> Or if you want your flash to last a specific amount of clock (eg 0.1):
>
> #declare flashStart = rand(Flash) * final_clock;
> #if( clock>flashStart & clock<flashStart+0.1)
> ...
>
> Note this will create the flash at exactly the same frame every time you
> run the animation - because the first random number generated after
> seed(1) is always the same.

_Most_ excellent.  That instantly cleared up that little problem.

I think if I consider the pseudorandom numbers as simply a library of selctable
one-dimensional arrays, it will be less confusing than "Hey, I need a 'random'
number" - because they're NOT.

I was also considering defining an object such as an image_map of noise, or a
cloud, and then just grabbing a pixel value, though I don't know if adding
layers of convolution get me anything better than declaring the seed value for
each frame with the clock value...  #declare RanDUMB_Number = seed (clock)


Post a reply to this message

From: scott
Subject: Re: Randomly timed events
Date: 29 Aug 2013 11:44:32
Message: <521f6c60$1@news.povray.org>
> I think if I consider the pseudorandom numbers as simply a library of selctable
> one-dimensional arrays, it will be less confusing than "Hey, I need a 'random'
> number" - because they're NOT.

I think (I could be wrong) but it's better to think of it as just one 
huge one-dimensional circular array (that wraps back to the start once 
you get to the end). The different seeds will just get you started at 
different points in the array.

> I was also considering defining an object such as an image_map of noise, or a
> cloud, and then just grabbing a pixel value, though I don't know if adding
> layers of convolution get me anything better than declaring the seed value for
> each frame with the clock value...  #declare RanDUMB_Number = seed (clock)

Using "frame_number" rather than "clock" would be better, as AFAIK the 
seed function takes the integer part only.


Post a reply to this message

From: Stephen
Subject: Re: Randomly timed events
Date: 29 Aug 2013 13:15:01
Message: <web.521f8153fc2c9d36e426a2320@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I'm trying to do a quick and dirty simulation of lightning flashes with
> momentarily appearing point light_sources in a scene,

[snip]

> Has anyone worked with this type of thing before?
> Helpful suggestions?

I did a scene with lightning flashes, a few years ago. I wanted the flashes to
appear at the correct place in the animation. So they were not random. I did
find that single flash in one frame was singularly unimpressive. So I made each
flash consist of several lit frames followed by a gap then several more.

As for trying to get rand and clock to match up. Best of luck there. ;-)

The variable final_frame is useful in these occasions to give you a way of
working out where in the animation your flashes will be.

Stephen


Post a reply to this message

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