FX animations contd - A rudimentary screensaver
By mohanpraveen on Aug 23, 2007
I was little off the hook with FX for a week now since Consumer JRE has taken up most of my time. As stated in Chet's blog, there is so much of cool stuff lined up for the Java community through consumer JRE and catch a glimpse of it when you get time.
Coming back to FX, I wanted to spend some time on Groups which can be considered as a non-visual container that offers the capability of combining multiple visual objects together and performing various transformations on the group as a whole. Groups by default introduces a new coordinate system and graphical objects assigned to the group are placed with respect to the group's origin.
The flexibility and convenience that the group offers to FX programmers is significant in my view and the ability to treat multiple objects as one and being able to perform operations/transformations on the group of objects as a whole is simply awesome. Groups directly exposes one of the primary advantages of the underlying scenegraph model, to the FX developer.
As I stated in one of my earlier postings, one of my other goals was to use pure FX animation loops in lieu of Swing Timer. But I was little short of ideas when it came to developing a small demo. Sitting in front of my machine, I was thinking for a while and fortunately it was long enough to trigger the screensaver on my linux box that broke my desktop into pieces. That gave me the necessary jolt to overcome the inertia and I came up with a small screensaver kind of application.
I still call it rudimentary because it is nowhere near the original screensaver that triggered it but nevertheless, it was a good starting point for me.
In this application, I am rotating and zooming various geometric objects individually and as a group as well. In addition to that, I am also trying animate multiple rectangles on the screen which would show the contents of the desktop right below it. All the objects would zoom out and zoom in repeatedly.
Click on the image to launch it. You would need JDK5+. While the screensaver is running, click on it to alternate between 'Transforming individual objects' vs 'Transforming a group'. You will see the difference pretty clearly. Right click on the screensaver to exit.
This animation is using Pure FX animation loops. It was little hard to get the synchronization right for zoom in/zoom out. Zooming should reverse only when all the objects reach the min/Max possible size and I am also changing the rotation angle at the same time alongwith opacity.
Take a look at the script -
I have slightly modified the screensaver demo given above to set the clipping region to the union of 4 different shapes shown in the screenshot, keeping the background intact. FX provides Clip class to this. I have defined the 'shape' attribute of the Clip class to be the union of 4 different shapes. Additions, Intersections, Subtractions, Xor of shapes can be achieved through built-in subclasses of Area - Add, Subtract, Intersect and XOR. That's pretty straight-forwrd. However, I am not clear why the commented part of the code inside the Clip construct in the source is not working?!!. That should ideally do the same what the uncommented piece of code does.
(Click on the screenshot to launch the application. You would need jdk5+. Click the mouse to exit)
Source Script -
I am going to take a small break (perhaps a week!) from FX to get back to Consumer JRE. Stay Tuned ...