Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.application.Application;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Scene;
- import javafx.scene.chart.LineChart;
- import javafx.scene.chart.NumberAxis;
- import javafx.scene.chart.XYChart;
- import javafx.scene.layout.Border;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.FlowPane;
- import javafx.stage.Stage;
- import java.util.ArrayList;
- import java.util.LinkedList;
- public class Main extends Application
- {
- public float[] firstEquation(float fi, float fs, float n)
- {
- float x[] = new float[(int) n];
- for(int i=0; i<n; i++)
- {
- x[i] = (float)Math.sin(2*Math.PI*fi*i/fs);
- }
- return x;
- }
- public float[] secondEquation(float fi, float fs, float n, float x[])
- {
- float z[] = new float[(int)n];
- for(int i=0; i<n; i++)
- {
- z[i] = (float) (1.22 * Math.cos(12*Math.PI * i/fs) * x[i] - i/3);
- }
- return z;
- }
- public float[] thirdEquation(float fi, float fs, float n, float x[])
- {
- float v[] = new float[(int) n];
- for(int i=0; i<n; i++)
- {
- if((x[i] -(i/3)) < 0)
- v[i] = (float) Math.pow(-(x[i]-i/3), (float)2/3);
- }
- return v;
- }
- public float[] fourthEquation(float fs, float n)
- {
- float u[] = new float[(int) n];
- for(int t=0; t<n; t++)
- {
- if(t < 3400*0.3)
- {
- u[t] = (float) (-Math.pow(t,2) * Math.sin(8*Math.PI * t/fs + Math.PI/2));
- }
- else
- {
- u[t] = (float) (1.1 * (Math.cos(10*Math.PI * t/fs - Math.PI)/t+1));
- }
- }
- return u;
- }
- public float[] fifthEquation(float fs, float H, float t)
- {
- float g[] = new float[(int) ((int)t*fs)];
- for(int i=0; i<40000; i++)
- {
- for(int j=0; j<=H-1; j++)
- {
- g[i] += (float) (4/Math.PI * (Math.sin(20*Math.PI * i/fs * (2*j+1)))/(2*j+1));
- }
- }
- return g;
- }
- public LineChart<Number, Number> createLineChart(float values[], float n, int chartNumber )
- {
- final NumberAxis xAxis = new NumberAxis();
- final NumberAxis yAxis = new NumberAxis();
- xAxis.setLabel("Częstotliwość próbkowania");
- final LineChart<Number,Number> lineChart = new LineChart<Number,Number>(xAxis,yAxis);
- lineChart.setTitle("Przebieg sinusoidalny - wykres nr " + chartNumber);
- lineChart.setCreateSymbols(false);
- XYChart.Series series = new XYChart.Series();
- for(int i=0; i<n; i++)
- {
- series.getData().add(new XYChart.Data(i, values[i]));
- }
- lineChart.getData().add(series);
- return lineChart;
- }
- @Override
- public void start(Stage primaryStage) throws Exception
- {
- Stage anotherStage = new Stage();
- Main equation = new Main();
- LinkedList<float[]> resultsList = new LinkedList<float[]>();
- resultsList.add(equation.firstEquation(12, 600, (float) (1.5*600)));
- resultsList.add(equation.secondEquation(12, 600, (float) (1.5*600), resultsList.get(0)));
- resultsList.add(equation.thirdEquation(12, 600, (float) (1.5*600), resultsList.get(0)));
- resultsList.add(equation.fourthEquation(1700, (float)(2*1700)));
- resultsList.add(equation.fifthEquation(10000, 5, 4));
- resultsList.add(equation.fifthEquation(10000, 25, 4));
- resultsList.add(equation.fifthEquation(10000, 125, 4));
- ArrayList<LineChart> lineChartsList = new ArrayList<LineChart>();
- ArrayList<LineChart> lineChartsList2 = new ArrayList<LineChart>();
- for(int i=0; i<7; i++)
- {
- if(i<3)
- {
- lineChartsList.add(createLineChart(resultsList.get(i), 900, i+1));
- }
- else if(i==3)
- {
- lineChartsList2.add(createLineChart(resultsList.get(i), 3400, i+1));
- }
- // else
- // {
- // lineChartsList2.add(createLineChart(resultsList.get(i), 40000, i+1));
- // }
- }
- FlowPane root = new FlowPane();
- root.getChildren().addAll(lineChartsList);
- Scene scene = new Scene(root,1920, 1080);
- primaryStage.setScene(scene);
- primaryStage.show();
- FXMLLoader anotherLoader = new FXMLLoader();
- FlowPane root2 = new FlowPane();
- Scene anotherScene = new Scene(root2,1920, 1080);
- root2.getChildren().addAll(lineChartsList2);
- anotherStage.setScene(anotherScene);
- anotherStage.show();
- }
- public static void main(String[] args)
- {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement