アットウィキロゴ

java0502

import java.awt.*;
import java.awt.event.*;

class game0502 extends Frame implements Runnable{

double x,y,z;
double rx,ry;
double x1,x2,x3,y1,y2,y3;
int modelx[]=new int[1001];
int modely[]=new int[1001];
int modelz[]=new int[1001];
int sx,sy,sz;
int n;

public static void main(String [] args) {
        Frame f=new game0502();
        f.setTitle("game0502");
        f.setSize(700,700);
        f.setBackground(Color.blue);
        f.setVisible(true);
    }

game0502(){

n=0;
for (sx=1;sx<11;sx++){
for (sy=1;sy<11;sy++){
for (sz=1;sz<11;sz++){
n=n+1;
modelx[n]=10*sx+100;
modely[n]=10*sy+100;
modelz[n]=10*sz+100;
}
}
}


x=500;
y=0;
z=0;
rot(x,y,z);
x1=rx;
y1=ry;
x=0;
y=500;
z=0;
rot(x,y,z);
x2=rx;
y2=ry;
x=0;
y=0;
z=500;
rot(x,y,z);
x3=rx;
y3=ry;



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(){
int t;
t=1;  
while(t<100){


repaint();
try{
Thread.sleep(1000);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}


public void paint(Graphics g){
int gx,gy;
gx=seekgx(x1);
gy=seekgy(y1);
g.drawLine(100,400,gx,gy);
gx=seekgx(x2);
gy=seekgy(y2);
g.drawLine(100,400,gx,gy);
gx=seekgx(x3);
gy=seekgy(y3);
g.drawLine(100,400,gx,gy);

g.setColor(Color.red);
for (n=1;n<1001;n++){
rot(modelx[n],modely[n],modelz[n]);
gx=seekgx(rx);
gy=seekgy(ry);
g.fillRect(gx,gy,1,1);
}





}


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月23日 09:58