package myspring; import javafx.scene.CustomNode; import javafx.scene.Group; import javafx.scene.Node; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.animation.Timeline; import javafx.scene.shape.Circle; import javafx.scene.paint.Color; import javafx.scene.input.MouseEvent; import javafx.scene.text.Text; import javafx.scene.paint.*; import javafx.scene.Group; import javafx.scene.Node; import java.lang.Math; import javafx.animation.Timeline; import javafx.animation.KeyFrame; import javafx.scene.shape.Circle; import javafx.scene.paint.Color; import javafx.scene.shape.*; import javafx.scene.paint.*; import javafx.scene.text.Font; public class Spring extends CustomNode { def spring = SpringEquation {}; var springAnimY = 50; public var color: Color = Color.RED; public var tx: Integer = 100; public var ty: Integer = 15; public var springAnim = Timeline { keyFrames: [ at(3.5s) { springAnimY => 130 tween spring}, ] }; public function setColor(c:Color): Void { color = c; } public function setInitialPos(transX: Integer, transY: Integer) { tx = transX; ty = transY; } public override function create(): Node { return Group { translateX: bind tx translateY: bind ty content: [ Line { startX: 50, startY: 0 endX: 150, endY: 0 strokeWidth: 3 stroke: Color.GRAY }, Path { stroke:Color.GRAY strokeWidth: 3 elements: [ MoveTo { x: 100 y: bind 0 }, LineTo { x: 100 y: bind 1 * (springAnimY + 50) / 12}, LineTo { x: 125 y: bind 2 * (springAnimY + 50) / 12 }, LineTo { x: 75 y: bind 3 * (springAnimY + 50) / 12 }, LineTo { x: 125 y: bind 4 * (springAnimY + 50) / 12 }, LineTo { x: 75 y: bind 5 * (springAnimY + 50) / 12 }, LineTo { x: 125 y: bind 6 * (springAnimY + 50) / 12 }, LineTo { x: 75 y: bind 7 * (springAnimY + 50) / 12 }, LineTo { x: 125 y: bind 8 * (springAnimY + 50) / 12 }, LineTo { x: 75 y: bind 9 * (springAnimY + 50) / 12 }, LineTo { x: 125 y: bind 10 * (springAnimY + 50) / 12 }, LineTo { x: 100 y: bind 11 * (springAnimY + 50) / 12 }, LineTo { x: 100 y: bind 12 * (springAnimY + 50) / 12 }, ] }, Circle { centerX: 100, centerY: 100 radius: 50 translateY: bind springAnimY; fill: bind RadialGradient { centerX: 0.25 centerY: 0.25 proportional: true stops: [ Stop { offset: 0.0 color: color }, Stop { offset: 1.0 color: Color.BLACK } ] } onMousePressed:function(e:MouseEvent) { springAnim.time = 0s; springAnim.play(); } }, Text { fill: Color.WHITE font: Font { name: "Arial" size: 24 } x: 65, y: bind springAnimY + 105 content: "Hit me" } ] } }; }