JavaFx Effect

posting ini, adalah untuk menunjukkan bagaimana membuat effect dengan manggunakan javafx. malam ini lagi gak mood banget, jadi untuk sementara posting langsung code, dan screenshotnya dulu, semoga lain kali bisa menjelaskan satu persatu.

semoga kode program berikut, cukup mudah dipahami :

/*
 * RectReflection.fx
 *
 * Created on 03 Mar 09, 21:58:29
 * updated on 04 Mar 09, 20:39:00
 */

package flower;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.effect.*;
import javafx.scene.shape.Rectangle;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;

/**
 * @author Hakim
 */
def imgurl: String = "file:///D:/Users/Hakim/Pictures/kittens-cups.jpg";
var border = Rectangle {
    x: 10,
    y: 10
    width: 140,
    height: 90
    fill: Color.BLACK
}

var img = Image{
    url: imgurl;
}

// reflection
var imgview = ImageView {
    effect: Reflection {
        fraction: 0.75
        topOffset: 0.0
        topOpacity: 0.5
        bottomOpacity: 0.0
    }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}
// motion blur
var imgview2 = ImageView {
    effect: MotionBlur {
        angle: 45
        radius: 10
    }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}

// lighting
var imgview3 = ImageView {
    effect: Lighting {
        diffuseConstant: 1.0
        specularConstant: 1.0
        specularExponent: 20
        surfaceScale: 1.5
    }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}

// inner shadow
var imgview4 = ImageView {
    effect: InnerShadow {
        choke: 0.5
        offsetX: 10
        offsetY: 10
        radius: 10
        color: Color.WHEAT
    }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}

// glow
var imgview5 = ImageView {
    effect: Glow {
        level: 0.5
    }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}

// gausian blur
var imgview6 = ImageView {
    effect: GaussianBlur {
            radius: 4.5
    }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}
// flood
var imgview7 = ImageView {
    effect:  Flood {
            paint: Color.GREENYELLOW
            width: 50
            height: 60
            x: 5
            y: 23
        }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}
// drop shadow
var imgview8 = ImageView {
    effect:  DropShadow {
                offsetX: 10
                offsetY: 10
                color: Color.WHITESMOKE
                radius: 10
            }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}
// color adjust
var imgview9 = ImageView {
    effect:  ColorAdjust {
                brightness: 0.0
                contrast: 1.0
                hue: 0.2
                saturation: 0.2
            }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}

// bloom
var imgview10 = ImageView {
    effect:  Bloom {
                threshold: 0.7
            }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}

// blend
var imgview11 = ImageView {
    effect:  Blend {
                mode: BlendMode.ADD
                opacity: 0.5
            }
    image: img
    fitWidth: 200
    preserveRatio: true
    smooth: true
    cache: true
}
var h1 = HBox{
    content:[imgview, imgview2, imgview3, imgview4, imgview6]
}
var h2 = HBox{
    content:[imgview8, imgview9, imgview10, imgview11]
}
Stage {
    title: "Reflection sample"
    //width: 450
    //height: 310
    scene: Scene {
        content: VBox{
            content:[h1,h2]
        }
        fill: Color.BLACK
    }
}

screenshotnya:
reflections

2 thoughts on “JavaFx Effect

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s