package graphics; import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.chart.*; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class Graphics extends Application { @Override public void start(Stage stage)// Заголовок вінка програми { stage.setTitle("Побудова графіків функцій: лінійної, квадратичної, раціональної, фігури Ліссажу"); double x0 = -1, // найменше значення абсциси x1 = 1, // найбільше значення абсциси dx = 0.5,// приріст абсциси між поділками на осі y0 = -1, // найменше значення ординати y1 = 1, // найбільше значення ординати dy = 0.5;// приріст ординати між поділками на осі int n12 = 100; // кількість точок ламаної int n34 =10000; // кількість символів double h12 = (x1-x0)/n12, h34 = (x1-x0)/n34; NumberAxis xAxis_1 = new NumberAxis(x0,x1,dx); NumberAxis yAxis_1 = new NumberAxis(y0,y1,dy); NumberAxis xAxis_2 = new NumberAxis(x0,x1,dx); NumberAxis yAxis_2 = new NumberAxis(y0,y1,dy); NumberAxis xAxis_3 = new NumberAxis(x0,x1,dx); NumberAxis yAxis_3 = new NumberAxis(y0,y1,dy); NumberAxis xAxis_4 = new NumberAxis(x0,x1,dx); NumberAxis yAxis_4 = new NumberAxis(y0,y1,dy); LineChart line1 = new LineChart<>(xAxis_1, yAxis_1); LineChart line2 = new LineChart<>(xAxis_2, yAxis_2); ScatterChart s3 = new ScatterChart<>(xAxis_3, yAxis_3); ScatterChart s4 = new ScatterChart<>(xAxis_4, yAxis_4); line1.setTitle("y = x/2 + 0.75"); line2.setTitle("x^2/4 + x/3 – 0.25"); s3.setTitle("y = (x/8 + 0.0625)/(2x – 1)"); s4.setTitle("x = cos 5t, y = sin 7t"); line1.setCreateSymbols(false); line2.setCreateSymbols(false); XYChart.Series f1 = new XYChart.Series<>(); XYChart.Series f2 = new XYChart.Series<>(); XYChart.Series f3 = new XYChart.Series<>(); XYChart.Series f4 = new XYChart.Series<>(); for (double x = x0; x <= x1; x += h12) { f1.getData().add(new XYChart.Data<>(x, x/2 + 0.75)); f2.getData().add(new XYChart.Data<>(x, x*x/4 + x/3 - 0.25)); } for (double x = x0; x <= x1; x += h34) { if (Math.abs((x/8 + 0.0625)/(2*x-1))<1) { f3.getData().add(new XYChart.Data<>(x, (x/8 + 0.0625)/(2*x-1) ));} } h34=2*Math.PI/n34; for (double t = 0; t <= 2*Math.PI; t += 2*Math.PI/n34) { f4.getData().add(new XYChart.Data<>(Math.cos(5*t), Math.sin(7*t))); } line1.getData().addAll(f1); line2.getData().addAll(f2); s3.getData().addAll(f3); s4.getData().addAll(f4); line1.setLegendVisible(false); line2.setLegendVisible(false); s3.setLegendVisible(false); s4.setLegendVisible(false); HBox hBox1 = new HBox(); HBox hBox2 = new HBox(); VBox vBox = new VBox(); hBox1.getChildren().addAll(line1,line2); hBox2.getChildren().addAll(s3,s4); vBox .getChildren().addAll(hBox1,hBox2); hBox1.setSpacing(5); hBox2.setSpacing(5); vBox .setSpacing(5); hBox1.setPadding(new Insets(5,5,5,5)); hBox2.setPadding(new Insets(5,5,5,5)); vBox .setPadding(new Insets(5,5,5,5)); Scene scene = new Scene(vBox, 700, 720); // Зміна стилю - задання послідовності власних кольорів - // можна не застосовувати, якщо влаштовують кольори як усталено scene.getStylesheets().add("/graphics/Graphics.css"); stage.setScene(scene); stage.show(); } public static void main(String[] args) {launch(args);} }