Playing with Color in JavaFX

JavaFX provide a rich API for playing with colors for an image or object. The best depicted in this sample but I will show you very quickly how to change the color of a car on JSlider. I have taken this nice car from Path Animation Sample and on JSlider, I will reproduce lot of Car color like this :

Actually this is very small but some one who want to develop car race required lot of car colors(it can be done at runtime)

Code here :

package carcolors;

import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
import javafx.ext.swing.SwingSlider;

var hue = 0;
var s = SwingSlider {
                minimum: -100
                maximum: 100
                value: hue
                vertical: false
            };
Stage {
    title: "Application title"
    width: 250
    height: 280
    scene: Scene {
        content: [
            s,
            ImageView {
                x: 100
                y: 100
                image: Image {
                    url: "{__DIR__}car.png"
                }
                effect: ColorAdjust {
                    hue: bind s.value/100.0
                }
            },
         ]

    }
}
Comments:

A very cool way to create new versions of entities at runtime! Certainly I use this tip.

Posted by Silveira Neto on December 25, 2008 at 10:32 PM IST #

welcome :)

Posted by Vaibhav Choudhary on December 26, 2008 at 06:12 AM IST #

[Trackback] Let's steal a car, repaint it, and do this quickly. What is more, do this in JavaFX and consider several programming hints by the way.

Posted by Sergey Malenkov's Blog on December 29, 2008 at 11:47 AM IST #

Ha ha ha ... this was the whole idea :). Stealing a car and make it own :D

Posted by Vaibhav on December 29, 2008 at 11:54 AM IST #

Thanks for the idea!

Posted by Uncle SAM on December 29, 2008 at 11:56 AM IST #

Hi,

I am delving into JavaFX... I am working with Java since its emergence in 1995... I am also familiar with Flash... and I cannot see the added value JavaFX brings comparing with Flash...

I am thinking about to include JavaFX in my next semester course (I lecture in CS programs).

Would love to get your feedback.

Thanks,

Haim.

Posted by Haim Michael on August 06, 2009 at 10:39 AM IST #

Hi,

I am delving into JavaFX... I am working with Java since its emergence in 1995... I am also familiar with Flash... and I cannot see the added value JavaFX brings comparing with Flash...

I am thinking about to include JavaFX in my next semester course (I lecture in CS programs).

Would love to get your feedback.

Thanks,

Haim.

Posted by Haim Michael on August 06, 2009 at 10:41 AM IST #

good

Posted by MBT Shoes on January 06, 2010 at 04:29 AM IST #

This is great news. Best of luck for the future and keep up the good work.

Posted by China Wholesale on January 09, 2010 at 04:42 AM IST #

thank you man

Posted by zeberkin on November 05, 2010 at 06:28 PM IST #

Good work vaibhav!!!!!
- Kalyan chowdary

Posted by guest on April 18, 2011 at 11:50 AM IST #

Post a Comment:
Comments are closed for this entry.
About

Hi, I am Vaibhav Choudhary working in Sun. This blog is all about simple concept of Java and JavaFX.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today