java graphics旋转_关于java Graphics2D 的旋转函数

/**Shapes2.java**Createdon2007年8月2日,上午9:39**Tochangethistemplate,chooseTools|TemplateManager*andopenthetemplateintheeditor.*//****@authoruser*/importjava.awt.*;impor...

/*

* Shapes2.java

*

* Created on 2007年8月2日, 上午9:39

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

/**

*

* @author user

*/

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import javax.swing.*;

public class Shapes2 extends JFrame{

/** Creates a new instance of Shapes2 */

public Shapes2() {

super("Drawing 2D shapes");

getContentPane().setBackground(Color.yellow);

setSize(400,400);

setVisible(true);

}

public void paint(Graphics g)

{

super.paint(g);

int xPoints[]={55,67,109,73,83,55,27,37,1,43};

int yPoints[]={0,36,36,54,96,72,96,54,36,36};

Graphics2D g2d=(Graphics2D)g;

GeneralPath star=new GeneralPath();

star.moveTo(xPoints[0],yPoints[0]);

for(int count=1;count

star.lineTo(xPoints[count],yPoints[count]);

star.closePath();

g2d.translate(200,200);

for(int count=1;count<=20;count++)

{

g2d.rotate(Math.PI/10.0);

g2d.setColor(new Color((int)(Math.random()*256),

(int)(Math.random()*256),

(int)(Math.random()*256)));

g2d.fill(star);

}

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

Shapes2 application=new Shapes2();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

我想问两个问题:(1) rotate()函数是否是以坐标原点为中心旋转的

(2) 对于上面那个star.closePath()这一句,删去以后效果好像是一样的.那为什么原程序要加这一句呢?

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值