Vaibhav's Blog Space

Playing with Color in JavaFX

Wednesday Dec 17, 2008

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
                }
            },
         ]

    }
}

[7] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

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

Posted by Silveira Neto on December 26, 2008 at 06:32 AM IST #

welcome :)

Posted by Vaibhav Choudhary on December 26, 2008 at 02:12 PM 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 07:47 PM 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 07:54 PM IST #

Thanks for the idea!

Posted by Uncle SAM on December 29, 2008 at 07:56 PM 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 05:39 PM 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 05:41 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed