X

Vaibhav's Blog Space

  • Java
    August 5, 2008

Reflection in JavaFX - Crying baby !

Guest Author

On the way to exploring little more API of JavaFX, I reached to a fair animation. That is reflection. Here is the output of "crying baby". I always scare of using cartoon character because those are Copyright Image. 

 And lots of guys kicked me in the last post because code size was too big, but now its Java FX and I can also show the power of scripting :-).  Here is the code:

import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.geometry.Circle;
import javafx.scene.paint.Color;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.effect.\*;
Frame {
    title: "Crying Baby"
    width: 400
    height: 700
    closeAction: function() { java.lang.System.exit( 0 );
    }
    visible: true
    stage: Stage {
        fill: Color.WHITE
        content: [
            ImageView {
                x: 100
                y:10
                image: Image {
                    url: "http://www.powermixradio.com/GGG-SAD-CARTOON.jpg"
                }
                effect: Reflection {
                    bottomOpacity:0.1
                    fraction: 1
                    topOffset: 50
                } 
            },
            ImageView {
                x:0
                y:300
                image: Image {
                    url: "http://www.toyotapartsstore.com/images/71111_2_%20mirror_8CE1.jpg"
                }
                opacity:0.5
            }
        ]
    }  
}

Things to watch:

1. Effect: Reflection -

bottomOpacity:0.1 - set the opacity of image in reflection.

fraction: 1 - set how much part of the image should come in reflection. 

topOffset: 50 - How far image from the focus. There are some more useful parameters in this.

2. Opacity of second Imageview allow me to see the reflection of first image, else it will cover the reflection.

On the way to make some moving animation, but I don't know what happened to the support of gif image. gif image works like static image, don't know why ?

Join the discussion

Comments ( 5 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.