import java.awt.*;
import java.awt.event.*;
class game0423 extends Frame implements Runnable{
double x,y,z;
double rx,ry;
double x1,x2,x3,y1,y2,y3;
double px[][][]=new double[2][2][2];
double py[][][]=new double[2][2][2];
int m1,m2,m3;
int t;
public static void main(String [] args) {
Frame f=new game0423();
f.setTitle("game0423");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game0423(){
Thread th=new Thread(this);
th.start();
addWindowListener(new stopwin());
}
class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
public void run(){
t=0;
while(t<10){
for (m1=0;m1<2;m1++){
for (m2=0;m2<2;m2++){
for (m3=0;m3<2;m3++){
x=10*t+100+m1*100;
y=10*t+100+m2*100;
z=10*t+100+m3*100;
rot(x,y,z);
px[m1][m2][m3]=rx;
py[m1][m2][m3]=ry;
}
}
}
repaint();
try{
Thread.sleep(1000);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}
public void paint(Graphics g){
int gx1,gy1,gx2,gy2,gx3,gy3,gx4,gy4;
int xx[]=new int[4];
int yy[]=new int[4];
xx[0]=seekgx(px[0][0][0]);
yy[0]=seekgy(py[0][0][0]);
xx[1]=seekgx(px[1][0][0]);
yy[1]=seekgy(py[1][0][0]);
xx[2]=seekgx(px[1][1][0]);
yy[2]=seekgy(py[1][1][0]);
xx[3]=seekgx(px[0][1][0]);
yy[3]=seekgy(py[0][1][0]);
g.drawPolygon(xx,yy,4);
xx[0]=seekgx(px[0][0][1]);
yy[0]=seekgy(py[0][0][1]);
xx[1]=seekgx(px[1][0][1]);
yy[1]=seekgy(py[1][0][1]);
xx[2]=seekgx(px[1][1][1]);
yy[2]=seekgy(py[1][1][1]);
xx[3]=seekgx(px[0][1][1]);
yy[3]=seekgy(py[0][1][1]);
g.drawPolygon(xx,yy,4);
}
public int seekgx(double x){
return (int)(100+x);
}
public int seekgy(double y){
return (int)(400-y);
}
public void rot(double x,double y,double z){
double theta,phi;
double a1,a2,a3,a4;
theta = -40*Math.PI/180;
phi=60*Math.PI/180;
a1=Math.cos(theta);
a2=Math.sin(theta);
a3=Math.cos(phi);
a4=Math.sin(phi);
rx=-a2*x+a1*y;
ry=-a1*a4*x-a2*a3*y+a4*z;
}
}
最終更新:2011年02月22日 10:01