首页 > 代码库 > 画家算法的简单的例子

画家算法的简单的例子

public class Paintmenger extends JPanel {    PaintDraw ps = new PaintDraw();    int[] ti1 = new int[4];    int[] ai1 = new int[4];    int[] ti2 = new int[4];    int[] ai2 = new int[4];    int[] ti3 = new int[4];    int[] ai3 = new int[4];//    int[] ti4 = new int[4];//    int[] ai4 = new int[4];//    int[] ti5 = new int[4];//    int[] ai5 = new int[4];//    int[] ti6 = new int[4];//    int[] ai6 = new int[4];//    int[] ti7 = new int[4];//    int[] ai7 = new int[4];//    int[] ti8 = new int[4];//    int[] ai8 = new int[4];//    int[] ti9 = new int[4];//    int[] ai9 = new int[4];//    int[] ti10 = new int[4];//    int[] ai10 = new int[4];        int x1=220,y1=320;    int x2=320,y2=320;    int x3=420,y3=320;    int x4=170,y4=370;    int x5=370,y5=370;    int x6=120,y6=420;    int x7=220,y7=420;    int x8=320,y8=420;    int x9=220,y9=220;    int x10=420,y10=220;    int x11=120,y11=320;    int x12=320,y12=320;    int x13=220,y13=120;    int x14=320,y14=120;    int x15=420,y15=120;    int x16=170,y16=170;    int x17=370,y17=170;    int x18=120,y18=220;    int x19=220,y19=220;    int x20=320,y20=220;//    int[][] ti=new int[7][7];    public static void main(String[] args) {        Paintmenger pm = new Paintmenger();        pm.StringSquare();       }    public void StringSquare(){           JFrame jf = new JFrame();           jf.setSize(800, 800);           jf.setDefaultCloseOperation(3);           jf.setTitle("海绵体");           jf.setLocationRelativeTo(null);                      this.setPreferredSize(new Dimension(700, 700));           this.setBackground(Color.WHITE);           jf.add(this);           jf.setVisible(true);           Graphics gr = this.getGraphics();           ps.Paint(gr);     }    public void paint(Graphics g)     {        super.paint(g);        for(int j=0;j<1;j++){        g.setColor(Color.LIGHT_GRAY);        int[] ti1 = {x1,x1-100,x1-100,x1};        int[] ai1 = {y1,y1,y1+100,y1+100};        g.fillPolygon(ti1, ai1, 4);        g.setColor(Color.GRAY);        int[] ti2 = {x1,x1+50,x1-50,x1-100};        int[] ai2 = {y1,y1-50,y1-50,y1};        g.fillPolygon(ti2, ai2, 4);        g.setColor(Color.DARK_GRAY);        int[] ti3 = {x1,x1+50,x1+50,x1};        int[] ai3 = {y1,y1-50,y1+50,y1+100};        g.fillPolygon(ti3, ai3, 4);        }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x2,x2-100,x2-100,x2};            int[] ai1 = {y2,y2,y2+100,y2+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x2,x2+50,x2-50,x2-100};            int[] ai2 = {y2,y2-50,y2-50,y2};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x2,x2+50,x2+50,x2};            int[] ai3 = {y2,y2-50,y2+50,y2+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x3,x3-100,x3-100,x3};            int[] ai1 = {y3,y3,y3+100,y3+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x3,x3+50,x3-50,x3-100};            int[] ai2 = {y3,y3-50,y3-50,y3};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x3,x3+50,x3+50,x3};            int[] ai3 = {y3,y3-50,y3+50,y3+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x4,x4-100,x4-100,x4};            int[] ai1 = {y4,y4,y4+100,y4+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x4,x4+50,x4-50,x4-100};            int[] ai2 = {y4,y4-50,y4-50,y4};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x4,x4+50,x4+50,x4};            int[] ai3 = {y4,y4-50,y4+50,y4+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x5,x5-100,x5-100,x5};            int[] ai1 = {y5,y5,y5+100,y5+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x5,x5+50,x5-50,x5-100};            int[] ai2 = {y5,y5-50,y5-50,y5};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x5,x5+50,x5+50,x5};            int[] ai3 = {y5,y5-50,y5+50,y5+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x6,x6-100,x6-100,x6};            int[] ai1 = {y6,y6,y6+100,y6+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x6,x6+50,x6-50,x6-100};            int[] ai2 = {y6,y6-50,y6-50,y6};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x6,x6+50,x6+50,x6};            int[] ai3 = {y6,y6-50,y6+50,y6+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x7,x7-100,x7-100,x7};            int[] ai1 = {y7,y7,y7+100,y7+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x7,x7+50,x7-50,x7-100};            int[] ai2 = {y7,y7-50,y7-50,y7};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x7,x7+50,x7+50,x7};            int[] ai3 = {y7,y7-50,y7+50,y7+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x8,x8-100,x8-100,x8};            int[] ai1 = {y8,y8,y8+100,y8+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x8,x8+50,x8-50,x8-100};            int[] ai2 = {y8,y8-50,y8-50,y8};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x8,x8+50,x8+50,x8};            int[] ai3 = {y8,y8-50,y8+50,y8+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x9,x9-100,x9-100,x9};            int[] ai1 = {y9,y9,y9+100,y9+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x9,x9+50,x9-50,x9-100};            int[] ai2 = {y9,y9-50,y9-50,y9};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x9,x9+50,x9+50,x9};            int[] ai3 = {y9,y9-50,y9+50,y9+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x10,x10-100,x10-100,x10};            int[] ai1 = {y10,y10,y10+100,y10+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x10,x10+50,x10-50,x10-100};            int[] ai2 = {y10,y10-50,y10-50,y10};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x10,x10+50,x10+50,x10};            int[] ai3 = {y10,y10-50,y10+50,y10+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x11,x11-100,x11-100,x11};            int[] ai1 = {y11,y11,y11+100,y11+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x11,x11+50,x11-50,x11-100};            int[] ai2 = {y11,y11-50,y11-50,y11};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x11,x11+50,x11+50,x11};            int[] ai3 = {y11,y11-50,y11+50,y11+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x12,x12-100,x12-100,x12};            int[] ai1 = {y12,y12,y12+100,y12+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x12,x12+50,x12-50,x12-100};            int[] ai2 = {y12,y12-50,y12-50,y12};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x12,x12+50,x12+50,x12};            int[] ai3 = {y12,y12-50,y12+50,y12+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x13,x13-100,x13-100,x13};            int[] ai1 = {y13,y13,y13+100,y13+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x13,x13+50,x13-50,x13-100};            int[] ai2 = {y13,y13-50,y13-50,y13};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x13,x13+50,x13+50,x13};            int[] ai3 = {y13,y13-50,y13+50,y13+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x14,x14-100,x14-100,x14};            int[] ai1 = {y14,y14,y14+100,y14+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x14,x14+50,x14-50,x14-100};            int[] ai2 = {y14,y14-50,y14-50,y14};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x14,x14+50,x14+50,x14};            int[] ai3 = {y14,y14-50,y14+50,y14+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x15,x15-100,x15-100,x15};            int[] ai1 = {y15,y15,y15+100,y15+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x15,x15+50,x15-50,x15-100};            int[] ai2 = {y15,y15-50,y15-50,y15};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x15,x15+50,x15+50,x15};            int[] ai3 = {y15,y15-50,y15+50,y15+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x16,x16-100,x16-100,x16};            int[] ai1 = {y16,y16,y16+100,y16+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x16,x16+50,x16-50,x16-100};            int[] ai2 = {y16,y16-50,y16-50,y16};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x16,x16+50,x16+50,x16};            int[] ai3 = {y16,y16-50,y16+50,y16+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x17,x17-100,x17-100,x17};            int[] ai1 = {y17,y17,y17+100,y17+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x17,x17+50,x17-50,x17-100};            int[] ai2 = {y17,y17-50,y17-50,y17};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x17,x17+50,x17+50,x17};            int[] ai3 = {y17,y17-50,y17+50,y17+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x18,x18-100,x18-100,x18};            int[] ai1 = {y18,y18,y18+100,y18+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x18,x18+50,x18-50,x18-100};            int[] ai2 = {y18,y18-50,y18-50,y18};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x18,x18+50,x18+50,x18};            int[] ai3 = {y18,y18-50,y18+50,y18+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x19,x19-100,x19-100,x19};            int[] ai1 = {y19,y19,y19+100,y19+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x19,x19+50,x19-50,x19-100};            int[] ai2 = {y19,y19-50,y19-50,y19};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x19,x19+50,x19+50,x19};            int[] ai3 = {y19,y19-50,y19+50,y19+100};            g.fillPolygon(ti3, ai3, 4);            }        for(int j=0;j<1;j++){            g.setColor(Color.LIGHT_GRAY);            int[] ti1 = {x20,x20-100,x20-100,x20};            int[] ai1 = {y20,y20,y20+100,y20+100};            g.fillPolygon(ti1, ai1, 4);            g.setColor(Color.GRAY);            int[] ti2 = {x20,x20+50,x20-50,x20-100};            int[] ai2 = {y20,y20-50,y20-50,y20};            g.fillPolygon(ti2, ai2, 4);            g.setColor(Color.DARK_GRAY);            int[] ti3 = {x20,x20+50,x20+50,x20};            int[] ai3 = {y20,y20-50,y20+50,y20+100};            g.fillPolygon(ti3, ai3, 4);            }//        for(int k=0;k<2;k++){//            g.setColor(Color.LIGHT_GRAY);//            int[] ti1 = {x1,x1-100,x1-100,x1};//            int[] ai1 = {y1,y1,y1+100,y1+100};//            g.fillPolygon(ti1, ai1, 4);//            g.setColor(Color.GRAY);//            int[] ti2 = {x1,x1+50,x1-50,x1-100};//            int[] ai2 = {y1,y1-50,y1-50,y1};//            g.fillPolygon(ti2, ai2, 4);//            g.setColor(Color.DARK_GRAY);//            int[] ti3 = {x1,x1+50,x1+50,x1};//            int[] ai3 = {y1,y1-50,y1+50,y1+100};//            g.fillPolygon(ti3, ai3, 4);//        }//        for(int h=0;h<1;h++)//        {//            g.setColor(Color.LIGHT_GRAY);//            int[] ti1 = {x1,x1-100,x1-100,x1};//            int[] ai1 = {y1,y1,y1+100,y1+100};//            g.fillPolygon(ti1, ai1, 4);//            g.setColor(Color.GRAY);//            int[] ti2 = {x1,x1+50,x1-50,x1-100};//            int[] ai2 = {y1,y1-50,y1-50,y1};//            g.fillPolygon(ti2, ai2, 4);//            g.setColor(Color.DARK_GRAY);//            int[] ti3 = {x1,x1+50,x1+50,x1};//            int[] ai3 = {y1,y1-50,y1+50,y1+100};//            g.fillPolygon(ti3, ai3, 4);//        }//        for(int j=0;j<3;j++){//            g.setColor(Color.LIGHT_GRAY);//            int[] ti1 = {x1,x1-100,x1-100,x1};//            int[] ai1 = {y1,y1,y1+100,y1+100};//            g.fillPolygon(ti1, ai1, 4);//            g.setColor(Color.GRAY);//            int[] ti2 = {x1,x1+50,x1-50,x1-100};//            int[] ai2 = {y1,y1-50,y1-50,y1};//            g.fillPolygon(ti2, ai2, 4);//            g.setColor(Color.DARK_GRAY);//            int[] ti3 = {x1,x1+50,x1+50,x1};//            int[] ai3 = {y1,y1-50,y1+50,y1+100};//            g.fillPolygon(ti3, ai3, 4);//           }//        for(int j=0;j<3;j++){//            g.setColor(Color.LIGHT_GRAY);//            int[] ti1 = {x1,x1-100,x1-100,x1};//            int[] ai1 = {y1,y1,y1+100,y1+100};//            g.fillPolygon(ti1, ai1, 4);//            g.setColor(Color.GRAY);//            int[] ti2 = {x1,x1+50,x1-50,x1-100};//            int[] ai2 = {y1,y1-50,y1-50,y1};//            g.fillPolygon(ti2, ai2, 4);//            g.setColor(Color.DARK_GRAY);//            int[] ti3 = {x1,x1+50,x1+50,x1};//            int[] ai3 = {y1,y1-50,y1+50,y1+100};//            g.fillPolygon(ti3, ai3, 4);//            }//    }    }}

技术分享

画家算法的简单的例子