“Star Dust” demo for Trident
October 21st, 2009 | 9 Comments »With the release 1.1 of Trident animation library available a couple of weeks ago, it’s time to start the development of version 1.2 (code-named Cookie Jar). The first 1.2dev drop has a few minor API enhancements, as well as a small new demo. This demo is based on the Flash mouse star trailer, and is slightly reminiscent of the Glitzer applet from Paul Schmidinger. Here is a video showing “Star Dust” in action:
The code is quite straightforward (see the test.swing.StarDust class). It has a looping timeline that spawns new stars. At every pulse this timeline checks the current location of the mouse. If the mouse is inside the panel, it creates a new Star object, as well as a matching Timeline object. The paintComponent() method of the panel iterates over all “live” stars and paints them based on their current position, size, rotation, alpha and color.
Here is the relevant code for the spawner timeline:
Timeline spawner = new Timeline(); spawner.addCallback(new UIThreadTimelineCallbackAdapter() { private float currHue = 0.0f; @Override public void onTimelinePulse(float durationFraction, float timelinePosition) { Point mouseLoc = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(mouseLoc, mainPanel); double currX = mouseLoc.getX(); double currY = mouseLoc.getY(); if ((currX < 0) || (currY < 0) || (currX > mainPanel.getWidth()) || (currY > mainPanel.getHeight())) return; double outerStartSpan = 5; double outerFinalSpan = 20; Star star = new Star(currX, currY, outerStartSpan);
Here, we use the MouseInfo class to get the mouse location, and then create a Star object centered at that point. Then, we create a timeline to animate the star location, size, rotation and alpha:
Timeline starTimeline = new Timeline(star); double angle = Math.random() * 2.0 * Math.PI; double distance = 20.0 + 30.0 * Math.random(); starTimeline.addPropertyToInterpolate("x", currX, currX + distance * Math.cos(angle)); starTimeline.addPropertyToInterpolate("y", currY, currY + distance * Math.sin(angle)); starTimeline.addPropertyToInterpolate("alpha", 1.0f, 0.0f); starTimeline.addPropertyToInterpolate("rotation", 0.0f, (float) (2 * Math.PI * Math.random())); starTimeline.addPropertyToInterpolate("outerSpan", outerStartSpan, outerFinalSpan); starTimeline.addPropertyToInterpolate("color", Color.white, new Color(Color.HSBtoRGB(currHue, 0.8f, 0.7f))); currHue += 0.01f;
When the timeline for the specific star is created, it is simply played for 3 seconds. The main spawning timeline is looped indefinitely:
starTimeline.setDuration(3000); starTimeline.play(); } }); spawner.playLoop(RepeatBehavior.LOOP);
If you have Java 6 or later on your machine, click on the button below to launch the WebStart demo of “Star Dust”:
Related posts:
- Trident part 8 – timeline scenarios Over the course of this week i’m talking about different concepts in the Trident animation...
- Trident part 2 – interpolating fields Over the course of the next few days i’m going to talk about different concepts...
- Project Marble – augmented reality in Java with JMF, Java3D, NYArToolkit and Trident Today i’m going to talk about setting up the development environment for running the augmented...

Looks nice and the performance is very very good.
Thanks Kirill.
I would like to see a “Shelf” example, like the shelf in javafx, but the javafx is too much slow, and needs a lot of memory, do you have something like to show?
Cheers
Maxwell
Maxwell,
At the present moment i will leave the implementation of Trident-powered shelf / coverflow component to the interested members of the community.
Thanks
Kirill
Hi Kirill,
I understand that you’d rather work on the framework instead of creating examples. But perhaps you can keep an updated list on applications or examples created by the community?
Nice demo
Pete,
Trident comes bundled with 11 Swing and 8 SWT examples. It also has four larger demos – Onyx, Granite, Marble and Amber (all referenced on this blog and available on Kenai). There is only so many demos that i can write.
There is a number of open-source implementations of Coverflow components in Java, and interested members of the community are more than welcome to scratch their own itch and see how these can be ported to Trident – instead of waiting for me to do so.
Thanks
Kirill
Hi Kirill,
Nice demo. Just wondering, why does it require full permissions?
Cheers,
Keith
Keith,
I’m using the same signed version of Trident for all the relevant demos. Some of them require permissions, and i don’t want to spend too much time on maintaining two versions of each jar for the WebStart links.
Thanks
Kirill
Ah ok, makes sense.
By the way, a competent programmer at javagaming.org has done the impossible: remade swing without the EDT. As soon as i saw it i thought you would be interested. Check it out here: http://www.javagaming.org/index.php/topic,21430.0.html
Best wishes,
Keith
Awesome Demo Kirill !!!!
Maybe you should work on something like kirill FX !! :-)
thanks for your work !