ФЭНДОМ


Главная | Описание языка | FXD | API | Примеры | Инструменты Разработки | Новости | Ресурсы | Форум

Mirror2 Mirror


import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.text.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;

import java.lang.Math;

var v: Double = 3e8;
var w: Double = 700e12;
var lambda: Double = 450e-9;

var a: Double = -10 * lambda;
var b: Double = 10 * lambda;

var N = 300;

var x1: Double = -1.8;
var y1: Double = 1.7;
var x2: Double = 1.9;
var y2: Double = 1.3;

var dx: Double = (b - a) / N;
var l: Double = 2;

function getAngle(x: Double): Double {
    var dx1 = x1 - x;
    var dx2 = x2 - x;
    var L = Math.sqrt(dx1 * dx1 + y1 * y1) + Math.sqrt(dx2 * dx2 + y2 * y2);
    var angle = (L * w) / v;
    return angle;
}

class Arrays extends CustomNode {

    public override function create(): Node {
        var elements: Line[];

        var sx = 0.0;
        var sy = 0.0;

        for (x in [a..b step dx]) {
            def angle = getAngle(x);
            def ex = sx + l * Math.cos(angle);
            def ey = sy + l * Math.sin(angle);
            insert Line { startX: sx startY: sy endX: ex endY: ey stroke: Color.DARKRED } into elements;
            sx = ex;
            sy = ey;
        }

        Group {
            content: [
                elements,
                Line { endX: sx endY: sy stroke: Color.ORANGE }
            ]
        }
    }

}

Stage {
    title: "Mirror"
    scene: Scene {
        width: 800
        height: 600
        content: [
            Text { x: 10 y: 50 font: Font { size: 16 } content: "Light velocity: {v}" }
            Text { x: 10 y: 75 font: Font { size: 16 } content: "Light frequency: {w}" }
            Text { x: 10 y: 100 font: Font { size: 16 } content: "Light wave length: {lambda}" }
            Text { x: 10 y: 125 font: Font { size: 16 } content: "Mirror length: {b - a}" }
            Text { x: 10 y: 150 font: Font { size: 16 } content: "N: {N}" }
            Group {
                scaleY: -1
                translateX: 200
                translateY: 300
                var scale = 100;
                content: [
                    Line { startX: scale * a endX: scale * b stroke: Color.BLUE strokeWidth: 2 }
                    for (x in [a..b step dx]) Group {
                            content: [
                                Line {
                                    startX: scale * x1
                                    startY: scale * y1
                                    endX: scale * x
                                    stroke: Color.DARKORANGE
                                    strokeWidth: 0.5
                                }
                                Line {
                                    startX: scale * x
                                    endX: scale * x2
                                    endY: scale * y2
                                    stroke: Color.DARKORANGE
                                    strokeWidth: 0.5
                                }
                            ]
                        }
                    Circle {
                        centerX: scale * x1, centerY: scale * y1 radius: 3 fill: Color.BLUE
                    }
                    Circle {
                        centerX: scale * x2, centerY: scale * y2 radius: 3 fill: Color.GREEN
                    }
                ]
            }
            Arrays {
                translateX: 800
                translateY: 300
            }
        ]
    }
}