Animator Script Component

Konfabulator-like animation object

By on January 31, 2009 3:01:44 PM from WinCustomize Forums WinCustomize Forums

Littleboy

Join Date 03/2001
+95

Update:

You can find the script along with a sample widget in the DesktopX Objects gallery.


I have this animation script I wrote 2 years ago for a widget (that I never finished ), and I recently got back to work on a package tracking widget that is going to use some part of it. Still 70% of the script is never going to be used and I don't want to throw it away, especially if it can help other people.

I've noticed a lot of questions on how to animate groups of objects, and everybody seems to write semi-custom code over and over. My script takes the form of a Script Component (an external script file you reference in your DesktopX script), which means it can be reused without cut&pasting dozens of lines of code every time.

 

Let me give you an example. In the script below Animator is the main object (already initalized, 3 lines of code, not of interest here). The last argument of each XXXAnim.Init methods is a callback that you can use to call a function when the animation is done. It's especially interesting if you need to coordinate several complex animations. I've added variables so you can understand what each Init call does, but in practice the script would be a little bit simpler.

Code: vbscript
  1. opacity = 75
  2. length_fade = 1500
  3. delay_fade = 500
  4. toX = 300
  5. toY = 300
  6. length_move = 5000
  7. delay_move  = 0
  8.  
  9. Set fadeAnim = CreateObject("DXScriptLibrary.FadeAnimation")
  10. Set moveAnim = CreateObject("DXScriptLibrary.MoveAnimation")
  11.  
  12. fadeAnim.Init DesktopX.Object("My_Object_Layer"), opacity, length_fade, delay_fade, Animator.EaseNone, ""
  13. moveAnim.Init DesktopX.Object("My_Object_Layer"), toX, toY, length_move, delay_move, Animator.EaseIn, ""
  14.  
  15. Animator.Add Array(fadeAnim, moveAnim)
  16. Animator.Start

So, what this code does is prepare 2 animations with different length and start time, give them to the animator component and then start the animations. The Animator object will automatically manage the animations, starting each one after the delay (and of course fade will apply to all child objects). You can also add a new animation while the previous ones are playing, it will be handled transparently, adjusting delays and total animation length.

As a bonus, you can specify the easing type. In the example, the object will start to move slowly and speed up as it moves through the animation.

There are 4 different animation objects (Fade, Move, Rotate, Resize) and 5 types of easing (EaseIn, EaseOut, EaseInOut, EaseOutElasticBig, BackOut). Everything is in separate components with minimal dependencies, so adding new stuff is relatively easy should you wish to so (new easing types for example)

 

Right now, the component has a few dependencies (I like to keep stuff clean, and I have my own pre-processor which automatically parses all that stuff and creates merged dxpacks with all needed files ), but this can be merged in a single file to be used more easily.

If there are enough people interested, I can cleanup the component and write a quick tutorial on how to use it. Let me know what you think!

 

 

6 Replies +1
Search this post
Subscription Options


Reason for Karma (Optional)
Successfully updated karma reason!
January 31, 2009 4:34:01 PM from WinCustomize Forums WinCustomize Forums

Littleboy

I am very interested,most of my windowblinds and DX objects has a decent amount of animation.Though WB's are of course very limited as far as animation parameters so DX has been fun to work with with the limitations of Windowblinds I decided to create my first DX Theme and of course very animated but scripting is definately not my forte' so a fade in and out animation has 3x the # of frmes necessary

ex...10 frames for fade in  10 frame animation 10 frames fade out

If you would like to see a static sreen shot you can see here LINK Oh I see your tracker right below very nice!

Also if you are interested Ihave a project I have done all of the graphics for but I just dont know where to go from here .Milksama was helping but he sent me an email telling me he was very busy right now .

Stand Alone Frame Builder Anyway if you are interested please let me know!

Thank you A/V

Reason for Karma (Optional)
Successfully updated karma reason!
January 31, 2009 6:35:41 PM from Stardock Forums Stardock Forums

Nice Julien.  YOu know I have a vested interest in you DX work. 

Reason for Karma (Optional)
Successfully updated karma reason!
February 1, 2009 12:59:00 AM from WinCustomize Forums WinCustomize Forums

ex...10 frames for fade in 10 frame animation 10 frames fade out

My FadeAnimation object only deals with the opacity property, so if your animation is using frames, you're going to need to do the work by hand. Yahoo Widget provides a CustomAnimation class, but it's easily replaced with a timer and a callback function.  You can write your own animation class easily anyway (2 properties, a constructor, one Animate method) and use it with the animator component.

As for the Frame Builder, I'm quite busy right now too, so I can't promise you anything. I'll be happy to discuss it over email though, as it sounds a good candidate for DXCanvas (it can loads images, arrange them on a custom sized surface and export the result to png). If you have the UI done as a DX pack, a prototype can probably be built in a couple of hours. Layers and gifs probably aren't going to be possible though.

Nice Julien. YOu know I have a vested interest in you DX work.

Thanks. Too bad most of my script library is closely interdependent, as a few other components might be of interest (I18N support with fallback to supported language files, a console class with logging to file at the same time and a Wincustomize/Stardock.Net class). Some of them could be extracted, but it would require a lot of code duplication, or dozen more lines of code where one would be enough. And I choose to do the later and wrote a "compiler" to deal with all the crappy stuff . #defines, #ifdefs and #includes are really nice once you get use to them.

Reason for Karma (Optional)
Successfully updated karma reason!
Sign Up or Login and this ad disappears!
There are many great features available to you once you register. Sign Up for a free account and browse the forums without ads.
February 2, 2009 9:22:56 AM from WinCustomize Forums WinCustomize Forums

My FadeAnimation object only deals with the opacity property, so if your animation is using frames, you're going to need to do the work by hand. Yahoo Widget provides a CustomAnimation class, but it's easily replaced with a timer and a callback function. You can write your own animation class easily anyway (2 properties, a constructor, one Animate method) and use it with the animator component.

This kinda what I was thinking (Excuse my lamens tenology).

*1 animation 10 frames

* a script(?) thats basically says ....Play animation 1 time starting at 10% opacity ending at 100% ....Then loop animation at 100% opacity ( X ) # of times then start animation at 100% fading to 10%

anyway if it is still not aplicable I understand but I am still interested for some other project I have in mind!

As for the Frame Builder, I'm quite busy right now too, so I can't promise you anything. I'll be happy to discuss it over email though, as it sounds a good candidate for DXCanvas (it can loads images, arrange them on a custom sized surface and export the result to png). If you have the UI done as a DX pack, a prototype can probably be built in a couple of hours. Layers and gifs probably aren't going to be possible though.
(it can loads images, arrange them on a custom sized surface and export the result to png)

That is the most important part the gif not so important.Main goal when buliding cursor or Start menu animation that are rendered in 3D they all have a file sequence so you have a foldr with 50 single frame images that need to be image with 50 frames horizontal for Cursor FX(XP) and Verticle for Windowblind animation!

I understand you are busy ,so any help is much appreciated!

I wiil start putting the image into a DX pack

email =audiomasters at mail dot com

Thank you

Harley

Reason for Karma (Optional)
Successfully updated karma reason!
February 2, 2009 6:58:30 PM from WinCustomize Forums WinCustomize Forums

a script(?) thats basically says ....Play animation 1 time starting at 10% opacity ending at 100% ....Then loop animation at 100% opacity ( X ) # of times then start animation at 100% fading to 10%

You can write your own FrameAnimation that takes a loop number. Everything in my script is time-based, so you will have to convert the loop time to a length in milliseconds. The fading will be done by the included FadeAnimation.

Code: vbscript
  1. Dim fadeAnimStart, fadeAnimEnd, frameAnimStart, frameAnimMiddle, frameAnimEnd
  2. Dim loops, totalFrames, interval, fadeEndLength
  3. loops = 3
  4. totalFrames = 10
  5. interval = 250
  6. fadeEndLength = 1000
  7. 'Init object
  8. myObject.Opacity = 10
  9. ' Init animation objects
  10. Set frameAnimStart = Animator.getFrameAnimation
  11. Set frameAnimMiddle = Animator.getFrameAnimation
  12. Set fadeAnimStart = Animator.getFadeAnimation
  13. Set fadeAnimEnd = Animator.getFadeAnimation
  14. frameAnimStart.Init myObject, 0, totalFrames, interval, 1, 0, ""
  15. fadeAnimStart.Init myObject, 100, frameAnimStart.Length, 0, Animator.EaseNone, ""
  16. frameAnimMiddle.Init myObject, 0, totalFrames, interval, loops, frameAnimStart.Length, ""
  17. fadeAnimEnd.Init myObject, 10, fadeEndLength, frameAnimStart.Length + frameAnimMiddle.Length, Animator.EaseNone, ""
  18. Animator.Add Array(frameAnimStart, frameAnimMiddle, fadeAnimStart, fadeAnimEnd)
  19. Animator.Start
Reason for Karma (Optional)
Successfully updated karma reason!
February 5, 2009 11:58:56 PM from WinCustomize Forums WinCustomize Forums

I finished rewriting some parts to remove external dependencies a few days ago and the animator component is now entirely self contained. I also fixed a few bugs along the way and it's much more robust now (until all you people proceed to break it ).

It includes the FrameAnimation component given as an example in my latest reply too. You have to initialize it with the total number of frames and the interval as it doesn't seems to be exposed to script. It then internally converts the number of frames to show into a time in ms. So contrary to the other animation objects, you don't need to pass it the length of the animation. If you have to synchronize several animations, you will simply initialize it first and then query it's Length property to be used to compute your other animations' delay&length.

Please also note that the RotationAnimation uses Object.Rotation directly and thus is broken with DX3.5. If someone wants to donate code to correct it, I'll be happy to add it .

And there is also a DX bug with rotation and multi-frame objects (already reported) that make them jump to their last frame when Object.Rotation is anything else than 0.

Reason for Karma (Optional)
Successfully updated karma reason!
Stardock Forums v1.0.0.0    #101114  walnut1   Server Load Time: 00:00:00.0000500   Page Render Time:

Home | About | Privacy | Upload Guidelines | Terms of Service | Help
WinCustomize © 2014 Stardock Corporation. All Rights Reserved.