package pacmantime; import javafx.stage.Stage; import javafx.scene.*; import javafx.scene.shape.*; import javafx.scene.paint.Color; import javafx.animation.*; import javafx.animation.transition.*; import javafx.scene.transform.*; import javafx.scene.text.*; import java.util.Calendar; import java.lang.Math; def h=360; def w=350; def s=300; def r=150; def c=150; var o=0; var hr=0; var min=0; var sec=0; def bg = Rectangle{x:0,y:0,width:w,height:h,fill:Color.BLACK};var pos:Duration = 0s; def forever=Timeline.INDEFINITE; function time():Void {def cal = Calendar.getInstance(); hr=cal.get(11); min=cal.get(12); sec=cal.get(13); pos=Duration.valueOf(sec * 1000.0);} function lz(t:Integer):String{if(t<10) "0{t}" else "{t}"} var pmpath = AnimationPath.createFromPath(SVGPath{content:"M150,0 A150,150 0 0,1,150,300 A150,150 0 0,1,150,0"}); var pacman = Arc {centerX:c centerY:c radiusX:10 radiusY:10 startAngle:bind 30-o length:bind 300+2*o type:ArcType.ROUND fill:Color.LIGHTGREEN} class Ghost extends CustomNode { def body = SVGPath{content:"M20,20 L20,10 A10,10 0 0,0 0,10 L0,20 L5,15 L10,20 L15,15 L20,20"} public var fill:Color; var s=50.0; var o=0.0; public var x=0; public var y=0; var r=2*(Math.random()-0.5); var path:AnimationPath = pmpath; var t=Duration.valueOf(Math.random()*5000.0) on replace{if(t==pos*r)tl.play()}; public override function create():Node {return ShapeSubtract{a:ShapeSubtract{a:body b:Circle{centerX:6,centerY:8,radius:3}} b:Circle{centerX:14,centerY:8,radius:3} fill:fill, scaleX:bind s, scaleY:bind s, translateY:bind y, translateX: bind x, opacity:bind o}} def pt=PathTransition {duration: 12s, time: bind t with inverse, node: this, path: path, rate:r, repeatCount:10000, interpolator: Interpolator.LINEAR} def tl=Timeline {repeatCount:1, autoReverse:false, keyFrames:[at(1s){s=>50.0;o=>0.25} at(500ms){s=>1.0;o=>0.85}]} public function haunt(){pt.play();tl.play()} } var colors = [Color.FUCHSIA, Color.LIGHTCYAN, Color.LIGHTYELLOW, Color.AQUA, Color.CORAL, Color.GHOSTWHITE, Color.INDIGO, Color.LIGHTSTEELBLUE]; var ghosts:Ghost[]={for (i in [1..sizeof colors-1]) {Ghost{fill:colors[i]}}} var g=0;Timeline {repeatCount:sizeof ghosts keyFrames:[KeyFrame {time:250ms, action:function(){ghosts[g++].haunt()}}]}.play(); var dots = Group{transforms:Translate{x:c, y:c} content: for (i in [1..60]) Circle {transforms:Rotate{angle:6*i-90}, centerX:c, radius:2, fill:Color.WHITE, visible:bind i>sec}} var clock = Text{translateX:80, translateY:170, content: bind "{lz(hr)}:{lz(min)}:{lz(sec)}", fill:Color.WHITE, font:Font{size:42}} Stage {width:w, height:h, scene:Scene{content:[bg, Group{translateX:10, translateY:10, content:[clock,dots,pacman,ghosts]}]}} PathTransition {duration: 60s, time: bind pos with inverse, node: pacman, path: pmpath orientation: OrientationType.ORTHOGONAL_TO_TANGENT rate:1.0, repeatCount:1, interpolator: Interpolator.LINEAR}.play(); Timeline {repeatCount:forever,autoReverse:true,keyFrames : [ KeyFrame {time:250ms, values:[o=>30 tween Interpolator.EASEBOTH]}]}.play(); time();Timeline {repeatCount:forever,keyFrames:[KeyFrame{time:1s,action:time}]}.play();