/* * Pendulum.fx * * Created on Nov 12, 2008, 3:19:09 PM */ package pendulum; import java.lang.Math; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.scene.CustomNode; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.paint.*; import javafx.scene.shape.*; /** * @author Vaibhav Choudhary */ public var length: Number = 10.0; public var gravity: Number = bind s.value; public var s = Slider { translateX: 50 translateY: 260 minimum: 1 maximum: 20 value: 9.8 }; public var omega: Number = bind Math.sqrt(gravity / length); public var t: Number = 0; public var x_initial: Number = 120; public var y_initial: Number = 50; public class Pendulum extends CustomNode { var x: Number = x_initial; var y: Number = y_initial; var thetha: Number; init { time.play(); } public function update(): Void { thetha = 0.5 * Math.cos(omega * t); x = length * Math.sin(thetha) * 10 + x_initial; y = length * Math.cos(thetha) * 10 + y_initial; } public var time = Timeline { repeatCount: Timeline.INDEFINITE keyFrames: [ KeyFrame { time: 15ms action: function() { t = t + 0.1; update(); } } ] }; public override function create(): Node { return Group { content: [ s, Path { stroke:Color.GRAY elements: [ MoveTo { x: x_initial y: y_initial }, LineTo { x: bind x y: bind y}, ] }, Line { startX: x_initial - 50, startY: y_initial endX: x_initial + 50, endY: y_initial strokeWidth: 3 stroke: Color.WHITE } Circle { centerX: bind x, centerY: bind y radius: 20 fill: bind RadialGradient { centerX: 0.25 centerY: 0.25 proportional: true stops: [ Stop { offset: 0.0 color: Color.RED }, Stop { offset: 1.0 color: Color.BLACK }, ] } } ] }; } }