?? map45rotate.java
字號:
// 程序:立體坐標定位
// 范例文件:Map45Rotate.java
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Map45Rotate extends Applet
{
int AppletWidth, AppletHeight,floorW,floorH,key;
Image floor,OffScreen;
Graphics drawOffScreen;
MediaTracker MT;
public void init()
{
setBackground(Color.white); //設定背景顏色
AppletWidth = getSize().width; //取得Applet的高度
AppletHeight = getSize().height; //取得Applet的寬度
//取得圖像
MT = new MediaTracker(this);
floor = getImage(getDocumentBase(),"Images/floor.gif");
MT.addImage(floor,0);
try
{
showStatus("圖像加載中(Loading Images)...");
MT.waitForAll();
}
catch(InterruptedException E){ } //沒有進行異常處理
//建立次畫面
OffScreen = createImage(AppletWidth,AppletHeight);
drawOffScreen = OffScreen.getGraphics();
floorW = floor.getWidth(this);
floorH = floor.getHeight(this);
}
public void paint(Graphics g)
{
int X,Y;
// 繪制地板
for(int i=1; i <= 15; i++)
for(int j=1; j <= 15; j++)
{
X = rotateX(j,i); // X 坐標轉換
Y = rotateY(j,i); // Y 坐標轉換
drawOffScreen.drawImage(floor,X,Y,X+floorW,
Y+floorH,0,0,floorW,floorH,this);
}
//將次畫面貼到主畫面中
g.drawImage(OffScreen,0,0,this);
}
// X 坐標轉換
private int rotateX(int j, int i)
{
int x;
// 根據圖片大小先算出原來坐標
x = (j-i)*floorW + 450;
// 進行坐標轉換
x = (int) (x*Math.cos(60*Math.PI/180));
// 返回坐標值
return x;
}
// Y 坐標轉換
private int rotateY(int j, int i)
{
int x, y;
// 根據圖片大小先算出原來坐標
x = j*floorW + 150;
y = -i*floorH;
// 進行坐標轉換
y = (int ) -(y*Math.cos(-15*Math.PI/180) +
x*Math.sin(60*Math.PI/180)*Math.sin(-15*Math.PI/180));
y = y - i * floorH/2;
// 返回坐標值
return y ;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -