Guest User

Untitled

a guest
Jun 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. // Zaklady pocitacove grafiky
  2.  
  3. import java.awt.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6. import java.math.*;
  7.  
  8. public class BasicDraw {
  9. public static void main(String[] args) {
  10. new BasicDraw();
  11. }
  12. BasicDraw() {
  13. // Create a frame
  14. JFrame frame = new JFrame();
  15.  
  16. // Add a component with a custom paint method
  17. frame.getContentPane().add(new MyComponent());
  18.  
  19. // Display the frame
  20. int frameWidth = 300;
  21. int frameHeight = 300;
  22. frame.setSize(frameWidth, frameHeight);
  23. frame.setVisible(true);
  24. frame.addWindowListener(new WindowAdapter() {
  25. public void windowClosing(WindowEvent evt) {
  26. // Exit the application
  27. System.exit(0);
  28. }
  29. });
  30. }
  31.  
  32. class MyComponent extends JComponent {
  33. // This method is called whenever the contents needs to be painted
  34. public void paint(Graphics g) {
  35. // Draw an oval that fills the window
  36. double a=20;
  37. int Ax = 50, Ay = 50;
  38. int Bx = 150, By = 250;
  39.  
  40. g.drawLine(Ax,Ay,Bx,By);
  41. //g.drawLine(-25,66,-167,2);
  42. double matice[][]=new double[3][3];
  43. matice[0][0]=Math.cos(a);
  44. matice[0][1]=-Math.sin(a);
  45. matice[0][2]=0;
  46. matice[1][0]=Math.sin(a);
  47. matice[1][1]=Math.cos(a);
  48. matice[1][2]=0;
  49. matice[2][0]=0;
  50. matice[2][1]=0;
  51. matice[2][2]=2;
  52.  
  53. double poc[]=new double[3];
  54. poc[0]=50;
  55. poc[1]=50;
  56. poc[2]=1;
  57.  
  58. double kon[]= new double[3];
  59. kon[0]=150;
  60. kon[1]=250;
  61. kon[2]=1;
  62.  
  63. double newpoc[]=new double[3];
  64. double newkon[]=new double[3];
  65.  
  66. for (int i=0;i<=2;i++){
  67. for(int j=0;j<=2;j++){
  68. newpoc[i] += matice[i][j]*poc[j];
  69. newkon[i] += matice[i][j]*kon[j];
  70. }
  71. }
  72.  
  73. //g.drawLine((int)newpoc[0], (int)newpoc[1], (int)newkon[0], (int)newkon[1]);
  74. //System.out.println((int)newkon[2]);
  75.  
  76.  
  77. }
  78. }
  79. }
Add Comment
Please, Sign In to add comment