Главная | Описание языка | FXD | API | Примеры | Инструменты Разработки | Новости | Ресурсы | Форум
Pendulum.fx[]
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import java.lang.Math;
def g = 9.8;
def dt = 0.1;
public class Pendulum extends CustomNode {
public var length: Number;
public var mass: Number;
public var amplitute: Number;
public var velocity:Number;
public var acceleration:Number;
public function run(){
acceleration = - g / length * Math.sin(amplitute);
velocity += acceleration * dt;
amplitute += velocity * dt;
}
public override function create(){
Group{
content: [
Line {
endX: bind length * Math.sin(amplitute)
endY: bind length * Math.cos(amplitute)
stroke: Color.ORANGE
},
Circle {
radius: 5
fill: Color.GRAY
},
Circle {
centerX: bind length * Math.sin(amplitute)
centerY: bind length * Math.cos(amplitute)
radius: 20
fill: Color.YELLOW
stroke: Color.ORANGE
}
]
}
}
}
Main.fx[]
import javafx.stage.*;
import javafx.scene.*;
import javafx.animation.*;
import java.lang.Math;
var pendulum = Pendulum{
mass: 10
length: 150
amplitute: Math.PI / 4
};
Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames : [
KeyFrame {
time : 10ms
canSkip : true
action: function(){
pendulum.run();
}
}
]
}.play();
Stage {
title: "Pendulum"
width: 300
height: 300
scene: Scene {
content: [
Group{
translateX: 150 translateY: 30
content: pendulum
}
]
}
}