アットウィキロゴ

0812

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

class game0812 extends Frame implements MouseListener{
PixelGrabber pg;
Color col;
Image img;
int w=500;
int h=500;
int size;
int red,green,blue;
int pix[]=new int[w*h];
int memor[][]=new int[h][w];
int memog[][]=new int[h][w];
int memob[][]=new int[h][w];
int ash[][]=new int[h][w];
int body[][]=new int[h][w];
int chashx[][]=new int[h][w];  
int chashy[][]=new int[h][w];  
int mx,nx,m,n;
int m1,n1,m2,n2;    
int sx,sy;
int j;
String s1,s2,s3,s4;
Button bu1,bu2,bu3,bu4,bu5,bu6;

game0812(){  

s1="ash.JPG";
catchimg(s1);


for (mx=0;mx<500;mx++){
for (nx=0;nx<500;nx++){  
j=0;
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)ash[mx][nx]=100;
}
}


for (mx=0;mx<500;mx++){
for (nx=0;nx<500;nx++){  
if(ash[mx][nx]<50)body[mx][nx]=100;
}
}

for (mx=0;mx<500;mx++){
for (nx=0;nx<500;nx++){
chashx[mx][nx]=(int)rotx(30,nx-334,mx-291)+334;
chashy[mx][nx]=(int)roty(30,nx-334,mx-291)+291;
}
}

s2="girl.JPG";
catchimg(s2);  

this.addMouseListener(this);



}

public static void main(String[] args) {
game0812 f = new game0812();
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 ) {

g.setColor(Color.white);
g.fillRect(0,0,500,500);

g.setColor(new Color(memor[319][273],memog[319][273],memob[319][273]));  
g.fillOval(319,273,32,32);

mx=1;
nx=1;
for (mx=0;mx<500;mx++){
for (nx=0;nx<500;nx++){  
g.setColor(new Color(memor[mx][nx],memog[mx][nx],memob[mx][nx]));  
if(body[mx][nx]>50)g.fillRect(nx,mx,1,1);
}
}

for (mx=0;mx<500;mx++){
for (nx=0;nx<500;nx++){  
g.setColor(new Color(memor[mx][nx],memog[mx][nx],memob[mx][nx]));  
m1=chashy[mx][nx];
n1=chashx[mx][nx];
if(ash[mx][nx]>50)g.fillRect(n1,m1,1,1);
}
}
g.setColor(Color.red);
g.fillRect(sx,sy,5,5);


}

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;
}

}

public void mouseClicked(MouseEvent e) {
double mex,mey;
mey=e.getY() ;
mex=e.getX();  
sx=(int)mex;
sy=(int)mey;        
repaint();  
System.out.println(sx);
System.out.println(sy);    
}
    public void mousePressed(MouseEvent e) {
        
    }
    public void mouseReleased(MouseEvent e) {
        
    }
    public void mouseEntered(MouseEvent e) {
        
    }
    public void mouseExited(MouseEvent e) {
        
    }

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年03月01日 09:48