Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to produce smooth random motion



The easiest way I've found to generate random numbers for seeding an animation is with the Javascript patch:

    if ( outputs[0] == null )
        outputs[0] = Math.random();

This works in QC, but doesn't when the qtz is running as a screen saver: Javascript in a screen saver always returns the same sequence every time. I've tried to get around this by patching System Time into Javascript for a seed value, but there's another difference in the screen saver environment here: it works in QC, but it looks like any number derived from System Time always comes up as NaN in Javascript.

This actually makes sense, as each time the screen saver runs, it's like a new process and the JavaScript internals probably don't set the random seed with the current date / time but to a fixed constant. I guess you could observe the same thing if you were to quit / restart Quartz Composer to play your composition.


Anyone seen this before? Does someone have another method for generating random initial values for screen savers?

I don't think there's anyway to can change the original sequence of random numbers, however, you could post-process it with some mathematical operations that use the current date / time like multiply, modulo... this will ensure the final random sequence will never be the same.


________________________________________________________
Pierre-Olivier Latour                            email@hidden
Quartz Composer Architect                Graphics & Imaging Team

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/email@hidden

This email sent to email@hidden
References: 
 >Best way to produce smooth random motion (From: pete boardman <email@hidden>)
 >Re: Best way to produce smooth random motion (From: Pierre-Olivier Latour <email@hidden>)
 >Re: Best way to produce smooth random motion (From: Dave Hayden <email@hidden>)
 >Re: Best way to produce smooth random motion (From: David Coffin <email@hidden>)
 >Re: Best way to produce smooth random motion (From: Dave Hayden <email@hidden>)
 >Re: Best way to produce smooth random motion (From: Dave Hayden <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.