Wednesday, July 30, 2008

Small Java FX example

OK, nothing to laugh. I know my animation sense is little poor. But here I tried to move a ship, in the way they show in movies -D. Nothing like that, I have tried to give a sinusoidal movement of a ship. In the comment section, you can see there is a sea image as well. Animation was looking little ugly with sea, so I removed it :-). But point to note, you can give any animation to a image based on any mathematical methods. And if you have a complex equation, you can fit that in, in place of my simple sin curve. Here is the code:

package move;

import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.paint.Color;
import java.lang.Math;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;

var time : Number = 0.0;


var timeline : Timeline = Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames :
KeyFrame {
time : 5ms
action: function() {
time += 0.02;
}
}
};
Frame {
title: "MyApplication"
width: 1200
height: 500
closeAction: function() {
java.lang.System.exit( 0 );
}
visible: true

stage: Stage {
fill: Color.AQUA
content: [
/* ImageView {
image: Image {
url: "http://birdblog.merseyblogs.co.uk/sea21206.jpg"
}
},
*/
ImageView {
x:bind(100 + time * 10)
y:bind(100 + Math.cos(time) * 10)
image: Image {
url: "http://lal.cas.psu.edu/Research/visualiz/images/boat.gif"
}
}
]

}
}
timeline.start();


Just 3-4 drags from Netbeans 6.1 FX viewer :

1. One Timeline and an action inside it.

2. One Frame.

3. One Image.

Thats it ! Set the code logic and rest leave all the work on binding :-). Quite simple, just that I am not able to make some good animation out of it !

Originally posted on http://blogs.sun.com/vaibhav

7 comments:

Anonymous said...

people like me searches for tiny simple and understandable stuff.

So this is great. Thnx a lot.
I've just started, and this is very helpful

Vaibhav Choudhary said...

great, I am writing some more small samples. So, hope for a post soon.

Here is the orkut community, we can discuss some other samples here :

http://www.orkut.co.in/Main#Community.aspx?rl=cpp&cmm=51255156

Anonymous said...

Unglaublich! viagra online rezept cialis ohne rezept [url=http//t7-isis.org]viagra billig online bestellen[/url]

Anonymous said...

free sex dating [url=http://loveepicentre.com/]dating advice for fifty year olds[/url] singles dating http://loveepicentre.com/ adult on line personals canada

Anonymous said...

musculus lumbricalis pedis http://soundcloud.com/buy-clomid-online clomid Courvoisier gallbladder clomid
phosphoglyceracetals [url=http://soundcloud.com/buy-clomid-online]clomid
[/url] Ofuji disease http://subscene.com/members/Buy-Clomid-_2D00_-Online-Pharmacy.aspx generic clomid tissue weighting factor clomid success stories
croup [url=http://subscene.com/members/Buy-Clomid-_2D00_-Online-Pharmacy.aspx]buy clomid
[/url]

Anonymous said...

prescription methadone [url=http://usadrugstoretoday.com/categories/arthrite.htm]arthrite[/url] cheap wood stem smoking pipe http://usadrugstoretoday.com/catalogue/s.htm online licensed us pharmacy insurance http://usadrugstoretoday.com/catalogue/c.htm
penis en main [url=http://usadrugstoretoday.com/products/abilify.htm]abilify[/url] lpl financial benefits medical [url=http://usadrugstoretoday.com/products/hytrin.htm]heart shaped wall clocks[/url]

Anonymous said...

certamed dental [url=http://usadrugstoretoday.com/products/viagra-jelly.htm]viagra jelly[/url] smoking ads http://usadrugstoretoday.com/categories/dejar-de-fumar.htm nutone medicine cabinet http://usadrugstoretoday.com/products/zyloprim.htm
hand held smoke machine [url=http://usadrugstoretoday.com/products/prednisone.htm]prednisone[/url] gum graft surgery [url=http://usadrugstoretoday.com/products/relafen.htm]free milking breast[/url]