var buttonstext = "On" on replace {
            if (buttonstext == "Off") {
                lightOpacity1 = .1;
                lightOpacity3 = .3;
                lightOpacity4 = 1;
                controlVisible = true;
                slider.value = .3;
            } else {
                lightOpacity1 = 0;
                lightOpacity3 = 0;
                lightOpacity4 = 0;
                controlVisible = false;
                slider.value = 0;
            }
        };
var lightOpacity1: Number = 0;
var lightOpacity2: Number = bind slider.value;
var lightOpacity3: Number = 0;
var lightOpacity4: Number = 0;
var lightbulbImg = ImageView {
            image: Image {
                url: "{__DIR__}resources/lightbulb.jpg"
            }
        }
var controlVisible = false;
var effects = Group {
            content: [
                Rectangle {
                    width: 412
                    height: 520
                    fill: Color.YELLOW
                    opacity: bind lightOpacity1
                }
                LightBulbEffect {effectOpacity: bind lightOpacity2}
                LightBulbEffect {effectOpacity: bind lightOpacity3}
                Rectangle {
                    effect: GaussianBlur {
                        radius: 10
                        input: Glow {}
                    }
                    translateY: 178
                    translateX: 165
                    width: 65
                    height: 8
                    arcWidth: 8
                    arcHeight: 8
                    fill: Color.WHITE
                    stroke: Color.ORANGE
                    strokeWidth: 1.8
                    opacity: bind lightOpacity4
                }
                Path {
                    effect: GaussianBlur {
                        radius: 1
                        input: Glow {}
                    }
                    stroke: Color.WHITE
                    strokeWidth: 1.8
                    opacity: bind lightOpacity4
                    elements: [
                        MoveTo {x: 172 y: 183},
                        LineTo {x: 183 y: 182},
                        QuadCurveTo {
                            controlX: 198 controlY: 183
                            x: 213 y: 182
                        }
                        QuadCurveTo {
                            controlX: 214 controlY: 183
                            x: 225 y: 185
                        }
                    ]
                }
            ]
        }
var togglebutton = Button {
            translateY: 350
            translateX: 260
            text: bind buttonstext
            onMousePressed: function (ev: MouseEvent): Void {
                if (buttonstext == "Off") {
                    buttonstext = "On";
                } else {
                    buttonstext = "Off";
                }
                }
        }
var slider: Slider = Slider {
            translateY: 420
            translateX: 128
            max: .4
            min: 0
            visible: bind controlVisible
        }
var controls = Group {
            content: [
                togglebutton,
                slider,
                Label{ translateX: 120 translateY:419 text:"-" visible: bind controlVisible}
                Label{ translateX: 268 translateY:419 text:"+" visible: bind controlVisible}
            ]
        }

Stage {
    title: "JavaFX Light Bulb"
    scene: Scene {
        width: 402
        height: 499
        fill: Color.BLACK
        content: [
            lightbulbImg,
            effects,
            controls
        ]
    }
  }
}
public class LightBulbEffect extends CustomNode {

    public var effectOpacity: Number;

    override function create() {
        Path {
            translateX: -10
            translateY: -8
            effect: GaussianBlur {input: Glow {level: 1} radius: 63}
            fill: Color.YELLOW
            stroke: Color.YELLOW
            strokeWidth: 5
            opacity: bind effectOpacity
            elements: [
                MoveTo {x: 127 y: 132},
                QuadCurveTo {
                    controlX: 206 controlY: 48
                    x: 287 y: 132
                }
                QuadCurveTo {
                    controlX: 320 controlY: 180
                    x: 295 y: 230
                }
                QuadCurveTo {
                    controlX: 290 controlY: 240
                    x: 270 y: 280
                }
                QuadCurveTo {
                    controlX: 270 controlY: 295
                    x: 260 y: 320
                }
                LineTo {x: 153 y: 320}
                QuadCurveTo {
                    controlX: 143 controlY: 295
                    x: 143 y: 280
                }
                QuadCurveTo {
                    controlX: 118 controlY: 240
                    x: 115 y: 230
                }
                QuadCurveTo {
                    controlX: 95 controlY: 180
                    x: 127 y: 132
                }
            ]
        }
    }
Advertisements