Vaibhav's Blog Space

Reflection in JavaFX - Crying baby !

Tuesday Aug 05, 2008

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 ?

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

Cool pics! I liked the concept. BTW, is this PowerPuff girls cartoon. LOL :D

Posted by Varun on August 06, 2008 at 12:02 AM IST #

o ya, this is PowerPuff. Company will sue on me ! I have to find a different girl and crying too :).

Posted by Vaibhav on August 06, 2008 at 12:07 AM IST #

Is it possible to apply an effect (e.g. transparency) only on the reflected image?

Posted by 140.78.145.36 on December 02, 2008 at 03:29 PM IST #

Yes it is ...

inside the reflection you need to use input and then effect !

something like :

effect: Reflection {
bottomOpacity:0.1
fraction: 1
topOffset: 50
input: //other effects
}

Posted by Vaibhav Choudhary on December 02, 2008 at 04:18 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed