Java 2D 회전 행렬 그리기

1874 단어 2D회전 행렬Java
Java 2D로 회전 행렬을 그렸습니다.

코드


Matrix2.java
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.geom.Line2D;
import java.awt.Color;

class Matrix2 extends JPanel{
  public static void main(String[] args){
            JFrame frame = new JFrame();

            Matrix2 app = new Matrix2();
            frame.getContentPane().add(app);

            frame.setBackground(Color.black);   // windowの背景色設定
            frame.setResizable(false);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setBounds(0, 0, 400, 400);
            frame.setTitle("タイトル1");
            frame.setVisible(true);
            Insets insets = frame.getInsets();  // 設定すべき値を求めるためのインスタンス化
            frame.setSize(400 + insets.left + insets.right,
                          400 + insets.top + insets.bottom); // 画面サイズ設定
          }

  public void paintComponent(Graphics g){
      g.setColor(Color.green);
      drawLine(g);
      drawCercle(g);
    }

  public void drawPoint(Graphics g,double x, double y){
      Graphics2D g2 = (Graphics2D)g;
      g2.draw(new Line2D.Double(x, y, x, y));
  }

  public void drawLine(Graphics g){
      for(int i = 0; i < 1000; i++){
          drawPoint(g,i,200);
          drawPoint(g,200,i);
      }
  }

  public void drawCercle(Graphics g){
      for(int i = 0; i < 12; i++){
          double x = 100 * Math.cos(Math.toRadians(30 * i));
          double y = 100 * Math.sin(Math.toRadians(30 * i));
          drawPoint(g,x+200,y+200);
      }
  }
}

실행 화면



개발 환경
Mac OSX version 10.10.1
실행 방법
Eclipse를 사용하여 가져오고 실행하십시오.

좋은 웹페이지 즐겨찾기