import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
class game0426 extends Frame implements Runnable{
PixelGrabber pg;
Color col;
Image img;
int w=488;
int h=393;
int pix[]=new int[w*h];
int red,green,blue;
int memor[][]=new int[h][w];
int memog[][]=new int[h][w];
int memob[][]=new int[h][w];
int mr[][]=new int[h][w];
int mg[][]=new int[h][w];
int mb[][]=new int[h][w];
int face[][]=new int[h][w];
int mapm[][]=new int[h][w];
int mapn[][]=new int[h][w];
int m,n,mx,nx,mxs,nxs;
int m5,n5;
int num;
String s1,s2,s3,s4;
game0426(){
s1="maid.jpg";
catchimg(s1);
for (mx=0;mx<h;mx++){
for (nx=0;nx<w;nx++){
mr[mx][nx]=memor[mx][nx];
mg[mx][nx]=memog[mx][nx];
mb[mx][nx]=memob[mx][nx];
}
}
s2="face.jpg";
catchimg(s2);
checkface();
s3="point.jpg";
catchimg(s3);
check();
System.out.println(mxs);
System.out.println(nxs);
Thread th=new Thread(this);
th.start();
}
public void run(){
int t;
t=1;
while(t<36){
for (mx=0;mx<h;mx++){
for (nx=0;nx<w;nx++){
m5=mx-mxs;
n5=nx-nxs;
mapm[mx][nx]=(int)rotx(10*t,m5,n5)+mxs;
mapn[mx][nx]=(int)roty(10*t,m5,n5)+nxs;
}
}
repaint();
try{
Thread.sleep(1000);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}
public static void main(String[] args) {
game0426 f = new game0426();
f.setSize(700,700);
f.setBackground(Color.blue) ;
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){public void
windowClosing(WindowEvent e){System.exit(0);}});
}
public void paint( Graphics g ) {
int i,z,pp;
g.setColor(Color.blue);
g.fillRect(0,0,700,700);
mx=1;
nx=1;
for (mx=0;mx<h;mx++){
for (nx=0;nx<w;nx++){
g.setColor(Color.blue);
g.setColor(new Color(mr[mx][nx],mg[mx][nx],mb[mx][nx]));
m5=mapm[mx][nx];
n5=mapn[mx][nx];
if(face[mx][nx]>50)g.fillRect(100+n5,100+m5,1,1);
}
}
}
void catchimg(String s){
img = createImage(w,h);
img = Toolkit.getDefaultToolkit().getImage(s);
pg = new PixelGrabber(img,0,0,w,h,pix,0,w);
try{pg.grabPixels();}catch(InterruptedException ie){}
m=0;
n=0;
for(int i=0;i<w*h;i++){
int p = pix[i];
col=new Color(pix[i]);
red=col.getRed();
green=col.getGreen();
blue=col.getBlue();
memor[m][n]=red;
memog[m][n]=green;
memob[m][n]=blue;
n=n+1;
if (n==w)m=m+1;
if (n==w)n=0;
}
}
void checkface(){
int j;
mx=1;
nx=1;
for (mx=0;mx<h;mx++){
for (nx=0;nx<w;nx++){
j=0;
face[mx][nx]=100;
if(memor[mx][nx]>50)j=j+1;
if(memog[mx][nx]>50)j=j+1;
if(memob[mx][nx]>50)j=j+1;
if(j==3)face[mx][nx]=0;
}
}
}
void check(){
int j;
mxs=1;
nxs=1;
for (mx=0;mx<h;mx++){
for (nx=0;nx<w;nx++){
j=0;
if(memor[mx][nx]<20)j=j+1;
if(memog[mx][nx]<20)j=j+1;
if(memob[mx][nx]<20)j=j+1;
if(j==3)mxs=mx;
if(j==3)nxs=nx;
}
}
}
public static double rotx(double kakudo,double x,double y){
double kaku;
double a1,a2,a3,a4;
double x1,y1;
kaku = kakudo*Math.PI/180;
a1=Math.cos(kaku);
a2=-Math.sin(kaku);
a3=Math.sin(kaku);
a4=Math.cos(kaku);
x1=a1*x+a2*y;
y1=a3*x+a4*y;
return x1;
}
public static double roty(double kakudo,double x,double y){
double kaku;
double a1,a2,a3,a4;
double x1,y1;
kaku = kakudo*Math.PI/180;
a1=Math.cos(kaku);
a2=-Math.sin(kaku);
a3=Math.sin(kaku);
a4=Math.cos(kaku);
x1=a1*x+a2*y;
y1=a3*x+a4*y;
return y1;
}
}
最終更新:2011年02月22日 12:35