Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Zaklady pocitacove grafiky
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- import java.math.*;
- public class BasicDraw {
- public static void main(String[] args) {
- new BasicDraw();
- }
- BasicDraw() {
- // Create a frame
- JFrame frame = new JFrame();
- // Add a component with a custom paint method
- frame.getContentPane().add(new MyComponent());
- // Display the frame
- int frameWidth = 300;
- int frameHeight = 300;
- frame.setSize(frameWidth, frameHeight);
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent evt) {
- // Exit the application
- System.exit(0);
- }
- });
- }
- class MyComponent extends JComponent {
- // This method is called whenever the contents needs to be painted
- public void paint(Graphics g) {
- // Draw an oval that fills the window
- double a=20;
- int Ax = 50, Ay = 50;
- int Bx = 150, By = 250;
- g.drawLine(Ax,Ay,Bx,By);
- //g.drawLine(-25,66,-167,2);
- double matice[][]=new double[3][3];
- matice[0][0]=Math.cos(a);
- matice[0][1]=-Math.sin(a);
- matice[0][2]=0;
- matice[1][0]=Math.sin(a);
- matice[1][1]=Math.cos(a);
- matice[1][2]=0;
- matice[2][0]=0;
- matice[2][1]=0;
- matice[2][2]=2;
- double poc[]=new double[3];
- poc[0]=50;
- poc[1]=50;
- poc[2]=1;
- double kon[]= new double[3];
- kon[0]=150;
- kon[1]=250;
- kon[2]=1;
- double newpoc[]=new double[3];
- double newkon[]=new double[3];
- for (int i=0;i<=2;i++){
- for(int j=0;j<=2;j++){
- newpoc[i] += matice[i][j]*poc[j];
- newkon[i] += matice[i][j]*kon[j];
- }
- }
- //g.drawLine((int)newpoc[0], (int)newpoc[1], (int)newkon[0], (int)newkon[1]);
- //System.out.println((int)newkon[2]);
- }
- }
- }
Add Comment
Please, Sign In to add comment