Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.application.Application;
  4. import javafx.fxml.FXMLLoader;
  5. import javafx.scene.Scene;
  6. import javafx.scene.chart.LineChart;
  7. import javafx.scene.chart.NumberAxis;
  8. import javafx.scene.chart.XYChart;
  9. import javafx.scene.layout.Border;
  10. import javafx.scene.layout.BorderPane;
  11. import javafx.scene.layout.FlowPane;
  12. import javafx.stage.Stage;
  13.  
  14. import java.util.ArrayList;
  15. import java.util.LinkedList;
  16.  
  17. public class Main extends Application
  18. {
  19. public float[] firstEquation(float fi, float fs, float n)
  20. {
  21. float x[] = new float[(int) n];
  22. for(int i=0; i<n; i++)
  23. {
  24. x[i] = (float)Math.sin(2*Math.PI*fi*i/fs);
  25. }
  26. return x;
  27. }
  28.  
  29. public float[] secondEquation(float fi, float fs, float n, float x[])
  30. {
  31. float z[] = new float[(int)n];
  32. for(int i=0; i<n; i++)
  33. {
  34. z[i] = (float) (1.22 * Math.cos(12*Math.PI * i/fs) * x[i] - i/3);
  35. }
  36. return z;
  37. }
  38.  
  39. public float[] thirdEquation(float fi, float fs, float n, float x[])
  40. {
  41. float v[] = new float[(int) n];
  42. for(int i=0; i<n; i++)
  43. {
  44. if((x[i] -(i/3)) < 0)
  45. v[i] = (float) Math.pow(-(x[i]-i/3), (float)2/3);
  46. }
  47. return v;
  48. }
  49. public float[] fourthEquation(float fs, float n)
  50. {
  51. float u[] = new float[(int) n];
  52. for(int t=0; t<n; t++)
  53. {
  54. if(t < 3400*0.3)
  55. {
  56. u[t] = (float) (-Math.pow(t,2) * Math.sin(8*Math.PI * t/fs + Math.PI/2));
  57. }
  58. else
  59. {
  60. u[t] = (float) (1.1 * (Math.cos(10*Math.PI * t/fs - Math.PI)/t+1));
  61. }
  62. }
  63. return u;
  64. }
  65. public float[] fifthEquation(float fs, float H, float t)
  66. {
  67. float g[] = new float[(int) ((int)t*fs)];
  68. for(int i=0; i<40000; i++)
  69. {
  70. for(int j=0; j<=H-1; j++)
  71. {
  72. g[i] += (float) (4/Math.PI * (Math.sin(20*Math.PI * i/fs * (2*j+1)))/(2*j+1));
  73. }
  74. }
  75. return g;
  76. }
  77.  
  78. public LineChart<Number, Number> createLineChart(float values[], float n, int chartNumber )
  79. {
  80. final NumberAxis xAxis = new NumberAxis();
  81. final NumberAxis yAxis = new NumberAxis();
  82. xAxis.setLabel("Częstotliwość próbkowania");
  83. final LineChart<Number,Number> lineChart = new LineChart<Number,Number>(xAxis,yAxis);
  84. lineChart.setTitle("Przebieg sinusoidalny - wykres nr " + chartNumber);
  85. lineChart.setCreateSymbols(false);
  86. XYChart.Series series = new XYChart.Series();
  87. for(int i=0; i<n; i++)
  88. {
  89. series.getData().add(new XYChart.Data(i, values[i]));
  90. }
  91. lineChart.getData().add(series);
  92. return lineChart;
  93. }
  94.  
  95. @Override
  96. public void start(Stage primaryStage) throws Exception
  97. {
  98. Stage anotherStage = new Stage();
  99. Main equation = new Main();
  100. LinkedList<float[]> resultsList = new LinkedList<float[]>();
  101. resultsList.add(equation.firstEquation(12, 600, (float) (1.5*600)));
  102. resultsList.add(equation.secondEquation(12, 600, (float) (1.5*600), resultsList.get(0)));
  103. resultsList.add(equation.thirdEquation(12, 600, (float) (1.5*600), resultsList.get(0)));
  104. resultsList.add(equation.fourthEquation(1700, (float)(2*1700)));
  105. resultsList.add(equation.fifthEquation(10000, 5, 4));
  106. resultsList.add(equation.fifthEquation(10000, 25, 4));
  107. resultsList.add(equation.fifthEquation(10000, 125, 4));
  108. ArrayList<LineChart> lineChartsList = new ArrayList<LineChart>();
  109. ArrayList<LineChart> lineChartsList2 = new ArrayList<LineChart>();
  110. for(int i=0; i<7; i++)
  111. {
  112. if(i<3)
  113. {
  114. lineChartsList.add(createLineChart(resultsList.get(i), 900, i+1));
  115. }
  116. else if(i==3)
  117. {
  118. lineChartsList2.add(createLineChart(resultsList.get(i), 3400, i+1));
  119. }
  120. // else
  121. // {
  122. // lineChartsList2.add(createLineChart(resultsList.get(i), 40000, i+1));
  123. // }
  124. }
  125. FlowPane root = new FlowPane();
  126. root.getChildren().addAll(lineChartsList);
  127. Scene scene = new Scene(root,1920, 1080);
  128. primaryStage.setScene(scene);
  129. primaryStage.show();
  130. FXMLLoader anotherLoader = new FXMLLoader();
  131. FlowPane root2 = new FlowPane();
  132. Scene anotherScene = new Scene(root2,1920, 1080);
  133. root2.getChildren().addAll(lineChartsList2);
  134. anotherStage.setScene(anotherScene);
  135. anotherStage.show();
  136. }
  137.  
  138. public static void main(String[] args)
  139. {
  140. launch(args);
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement