Advertisement
Guest User

Untitled

a guest
May 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1.  
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.geom.Line2D;
  6. import java.io.FileNotFoundException;
  7. import java.io.PrintWriter;
  8.  
  9. import javax.swing.JFrame;
  10. import javax.swing.JPanel;
  11.  
  12. public class Wykres_C_DSBB extends JPanel {
  13. int ilosc = 999;
  14.  
  15. double f(double x) {
  16. double y = 0.022222222 * x;
  17. return (Math.cos(y) * Math.exp(-0.2 * y));
  18. }
  19.  
  20. double g(double x) {
  21. double y = 0.022222222 * x;
  22. return (0.25 * Math.cos(y));
  23. }
  24.  
  25. double x(int a) {
  26. double[] tab = new double[ilosc];
  27. for (int i = 0; i < ilosc; i++) {
  28. tab[i] = i * 0.025;
  29. }
  30. return tab[a];
  31. }
  32.  
  33. double fy(int a) {
  34. double[] tab = new double[ilosc];
  35. for (int i = 0; i < ilosc; i++) {
  36. double x = i * 0.025;
  37. tab[i] = Math.cos(x) * Math.exp(-0.2 * x);
  38. }
  39. return tab[a];
  40. }
  41.  
  42.  
  43.  
  44. public void paintComponent(Graphics g) {
  45. Graphics2D g2d = (Graphics2D) g;
  46. g2d.setColor(Color.BLACK);
  47. Line2D osx = new Line2D.Double(0, 300, 950, 300);
  48. Line2D osy = new Line2D.Double(25, 0, 25, 600);
  49. g2d.draw(osx);
  50. g2d.draw(osy);
  51.  
  52. char c = 0x25B2;
  53. char p = 0x03C0;
  54. char d = 0x25B6;
  55. g.drawString(String.valueOf(c), 19, 9);
  56. g.drawString(String.valueOf(d), 911, 305);
  57. g.drawString("2" + String.valueOf(p), 292, 315);
  58. g.drawString("4" + String.valueOf(p), 577, 315);
  59. g.drawString("6" + String.valueOf(p), 862, 315);
  60. g.drawString("0", 15, 315);
  61. g2d.setColor(Color.BLUE);
  62. for (int i = 0; i < 900; i++) {
  63. Line2D prostaf = new Line2D.Double(25 + i, 300 - 300 * f(i), 25 + i + 1, 300 - 300 * f(i + 1));
  64. g2d.draw(prostaf);
  65. }
  66. g2d.setColor(Color.RED);
  67. for (int i = 0; i < 900; i++) {
  68. Line2D prostag = new Line2D.Double(25 + i, 300 - 300 * g(i), 25 + i + 1, 300 - 300 * g(i + 1));
  69. g2d.draw(prostag);
  70. }
  71. }
  72.  
  73. public static void main(String[] args) throws FileNotFoundException {
  74. JFrame ramaOkna = new JFrame("Grafy funkcji f i g");
  75. ramaOkna.add(new Wykres_C_DSBB());
  76. ramaOkna.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  77. ramaOkna.setSize(900, 700);
  78. ramaOkna.setBackground(Color.WHITE);
  79. ramaOkna.setResizable(false);
  80. ramaOkna.setVisible(true);
  81. PrintWriter Save = new PrintWriter("data.csv");
  82. Wykres_C_DSBB dane = new Wykres_C_DSBB();
  83. for (int i = 0; i < 801; i++) {
  84. double x = dane.x(i);
  85. x *= 100000;
  86. x = Math.round(x);
  87. x /= 100000;
  88. double fy = dane.fy(i);
  89. fy *= 100000;
  90. fy = Math.round(fy);
  91. fy /= 100000;
  92.  
  93. }
  94. Save.close();
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement