import java.awt.*; public class ArrayImage { private Image img; private int width; private int height; private int base[]; private int before[]; private int rx,ry,rex,rey; public ArrayImage(Image img,int width,int height) { this.img = img; this.width = width; this.height = height; base = new int[width*height]; before = new int[width*height]; rx=width;ry=width;rex=0;rey=0; } public void clearImage() { for(int i = 0; i < width * height;i++) { base[i] = 0; // before[i] = 0; } Graphics gra = img.getGraphics(); gra.setColor(new Color(255,255,255)); gra.fillRect(0,0,width,height); gra.setColor(new Color(0,0,0)); } public int index(int x,int y) { if( 0 <= x && x= 0){return a;} else{return -a;} } private int susumuX(Point start,int x,int xx) { try { return (int)(start.getX()+(xx-x)/zetu(xx-x)); } catch(Exception e) { return (int)start.getX(); } } private int susumuY(Point start,int y,int yy) { try { return (int)(start.getY()+(yy-y)/zetu(yy-y)); } catch(Exception e) { return (int)start.getY(); } } public void drawLine(int x ,int y,int xx, int yy) { Point start = new Point(x,y); int time; if( zetu(xx-x) > zetu(yy-y)){time= zetu(xx-x);}else{time=zetu(yy-y);} Point vector = new Point();vector.setLocation((xx-x)/(double)time,(yy-y)/(double)time); for(int i=0; i < 100;i++){ try { if( start.getX()!=xx &&((double)(xx-x)/(double)time > 0) &&(int)start.getX() <= (x+ (xx-x)/(time/i))) { start.setLocation(susumuX(start,x,xx),start.getY()); } if(start.getX()!=xx&& ( (double)(xx-x)/(double)time < 0) &&(int)start.getX() >= (x+ (xx-x)/(time/i))) { start.setLocation(susumuX(start,x,xx),start.getY()); } } catch(Exception e) { ; } try { if(start.getY()!=yy &&( (double)(yy-y)/(double)time > 0) &&(int)start.getY() <= (y+ (yy-y)/(time/i))) { start.setLocation(start.getX(),susumuY(start,y,yy)); } if(start.getY()!=yy&& ( (double)(yy-y)/(double)time < 0) &&(int)start.getY() >= (y+ (yy-y)/(time/i))) { start.setLocation(start.getX(),susumuY(start,y,yy)); } }catch(Exception e){;} baseXY((int)start.getX(),(int)start.getY(),true); imageXY((int)start.getX(),(int)start.getY()); } } public void baseXY(int x,int y,boolean bo) { if(x > width &&y >height && x < 0 && y<0) {return ;} if(bo == true) { base[y*width+x] = 1; } else { base[y*width+x] = -1; } } public void imageXY(int x,int y) { if(x >= width &&y >=height && x <= 0 && y<=0) {return ;} if(before[y*width+x] != base[y*width+x]) { Graphics g = img.getGraphics(); g.fillRect(x,y,1,1); before[y*width+x] = base[y*width+x]; } } public Image createImage() { rx=width;ry=width;rex=0;rey=0; Graphics g = img.getGraphics(); for(int y=0; y < height;y++) { for(int x=0;x x){rx = x;} if(ry > x){ry = y;} if(rex < x){rex = x;} if(rey < y){rey = y;} } before[y*width+x] = base[y*width+x]; } } return img; } public int RX() { return rx; } public int RY() { return ry; } public int REX() { return rex; } public int REY() { return rey; } }