LoginSignup
0
1

More than 5 years have passed since last update.

Java2D 回転行列 描画

Last updated at Posted at 2015-11-27

Java2Dで回転行列の描画を行いました。

コード

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);
      }
  }
}

実行画面

スクリーンショット 2015-11-27 12.09.24.png

開発環境
Mac OSX version 10.10.1

実行方法
Eclipseでインポートさせて実行してください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1