Back to index

wims  3.65+svn20090927
Public Member Functions | Package Attributes | Static Private Attributes
rooster Class Reference
Inheritance diagram for rooster:
Inheritance graph
[legend]
Collaboration diagram for rooster:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void init ()
void paint (Graphics g)
void start ()
void stop ()
void run ()
void update (Graphics g)
String ReadApplet ()

Package Attributes

int max_x = 20
int max_y = 20
int rooster [][]
int dx
int dy
Thread thread = null
Image plaatje
Graphics tekening
int hokje_x = 20
int hokje_y = 20
int xsize = hokje_x*max_x
int ysize = hokje_y*max_y
int R1 = 111
int G1 = 222
int B1 = 040
int R2 = 040
int G2 = 222
int B2 = 111
int interactive = 1
int percentage = 0
int level = 3

Static Private Attributes

static final int serialVersionUID = 1

Detailed Description

Definition at line 63 of file rooster.java.


Member Function Documentation

void rooster.init ( ) [inline]

Definition at line 77 of file rooster.java.

                      {
       String c;
       c=getParameter("color1");
       if(c!=null && c.length()>0){
           // don't know how to do this in 1 regexp
           if(c.indexOf(',')== -1 && c.indexOf(':')== -1 && c.indexOf(';')== -1 ){
              if(c.equalsIgnoreCase("red")){R1=255;G1=0;B1=0;}
              else
              if(c.equalsIgnoreCase("green")){R1=0;G1=255;B1=0;}
              else
              if(c.equalsIgnoreCase("blue")){R1=0;G1=0;B1=255;}
              else
              if(c.equalsIgnoreCase("orange")){R1=238;G1=154;B1=0;}
              else
              if(c.equalsIgnoreCase("yellow")){R1=255;G1=255;B1=0;}
              else
              if(c.equalsIgnoreCase("purple")){R1=160;G1=32;B1=240;}
              else
              if(c.equalsIgnoreCase("lightgreen")){R1=144;G1=238;B1=144;}
              else
              if(c.equalsIgnoreCase("lightblue")){R1=173;G1=216;B1=230;}
              else
              if(c.equalsIgnoreCase("cyan")){R1=0;G1=255;B1=255;}
              else
              if(c.equalsIgnoreCase("brown")){R1=165;G1=24;B1=24;}
              else
              if(c.equalsIgnoreCase("salmon")){R1=250;G1=128;B1=114;}
              else
              if(c.equalsIgnoreCase("pink")){R1=255;G1=192;B1=203;}
              else{R1=255;G1=0;B1=0;}
           }
           else
           {
              c=c.replace(':',',');c=c.replace(';',',');
              StringTokenizer q = new StringTokenizer(c, ",");
              String k;int rgb;
              for( int a=0; a<3 ; a++){
                  k=q.nextToken();
                  rgb=Integer.parseInt(k, 10);
                  if(rgb<0){rgb=0;}
                  if(rgb>255){rgb=255;}
                  if(a==0){R1=rgb;}
                  if(a==1){G1=rgb;}
                  if(a==2){B1=rgb;}
              }
           }
       }

       c=getParameter("color2");
       if(c!=null && c.length()>0){
           if(c.indexOf(',')== -1 && c.indexOf(':')== -1 && c.indexOf(';')== -1 ){
              if(c.equalsIgnoreCase("red")){R2=255;G2=0;B2=0;}
              else
              if(c.equalsIgnoreCase("green")){R2=0;G2=255;B2=0;}
              else
              if(c.equalsIgnoreCase("blue")){R2=0;G2=0;B2=255;}
              else
              if(c.equalsIgnoreCase("orange")){R2=238;G2=154;B2=0;}
              else
              if(c.equalsIgnoreCase("yellow")){R2=255;G2=255;B2=0;}
              else
              if(c.equalsIgnoreCase("purple")){R2=160;G2=32;B2=240;}
              else
              if(c.equalsIgnoreCase("lightgreen")){R2=144;G2=238;B2=144;}
              else
              if(c.equalsIgnoreCase("lightblue")){R2=173;G2=216;B2=230;}
              else
              if(c.equalsIgnoreCase("cyan")){R2=0;G2=255;B2=255;}
              else
              if(c.equalsIgnoreCase("brown")){R2=165;G2=24;B2=24;}
              else
              if(c.equalsIgnoreCase("salmon")){R2=250;G2=128;B2=114;}
              else
              if(c.equalsIgnoreCase("pink")){R2=255;G2=192;B2=203;}
              else{R2=0;G2=0;B1=255;}
           }
           else
           {
              c=c.replace(':',',');c=c.replace(';',',');
              StringTokenizer q = new StringTokenizer(c, ",");
              String k;int rgb;
              for( int a=0; a<3 ; a++){
                  k=q.nextToken();
                  rgb=Integer.parseInt(k, 10);
                  if(rgb<0){rgb=0;}
                  if(rgb>255){rgb=255;}
                  if(a==0){R2=rgb;}
                  if(a==1){G2=rgb;}
                  if(a==2){B2=rgb;}
              }
           }
       }

       c=getParameter("max_x");
       if(c!=null && c.length()>0){
           max_x = Integer.parseInt(c, 10);
           if(max_x>20){max_x=20;}
           if(max_x<1){max_x=1;}                                                                                                              
        }
       c=getParameter("max_y");
       if(c!=null && c.length()>0){
           max_y = Integer.parseInt(c, 10);
           if(max_y>20){max_y=20;}
           if(max_y<1){max_y=1;}                                                                                                              
        }                                                                                                                              
       c=getParameter("size_x");
       if(c!=null && c.length()>0){
           hokje_x = Integer.parseInt(c, 10);
           if(hokje_x>60){hokje_x=60;}
           if(hokje_x<20){hokje_x=20;}
        }
       c=getParameter("size_y");
       if(c!=null && c.length()>0){
           hokje_y = Integer.parseInt(c, 10);
           if(hokje_y>60){hokje_y=60;}
           if(hokje_y<20){hokje_y=20;}
        }

// 21-3-2008 
       c=getParameter("level");
       if(c!=null && c.length()>0){
           level = Integer.parseInt(c, 10);
           if(level>3){level=3;}
           if(level<0){level=0;}
        }
       c=getParameter("percentage");
       if(c!=null && c.length()>0){
           percentage = Integer.parseInt(c, 10);
           if(percentage>0){percentage=1;}else{percentage=0;}
        }
// eind
       xsize=hokje_x*(max_x+2);
       ysize=hokje_y*(max_y+2);
       rooster=new int[max_y+2][max_x+2];
       plaatje = createImage(xsize,ysize);
       tekening = plaatje.getGraphics();
       // hele veld met 0 == wit    
       for(int x=0;x<max_x+2;x++){;
           for(int y=0;y<max_y+2;y++){
              rooster[y][x]=0;
           }
       }

       c=getParameter("interactive");
       if(c.equals("0")){
           interactive=0;
           double p;
           int hit1=0;int hit2=0;
           if(percentage==0){
              for(int x=1;x<max_x+1;x++){
                  for(int y=1;y<max_y+1;y++){
                     if(level==3){p=Math.random();if(p<0.5){rooster[y][x] = -1;hit1++;}else{rooster[y][x] = 1;hit2++;}}
                     else
                     if(level==2){p=Math.random();if(p<0.7){rooster[y][x] = -1;hit1++;}else{rooster[y][x] = 1;hit2++;}}
                      else
                      if(level==1){p=Math.random();if(p<0.8){rooster[y][x] = -1;hit1++;}else{rooster[y][x] = 1;hit2++;}}
                      else 
                      if(level==0){p=Math.random();if(p<0.9){rooster[y][x] = -1;hit1++;}else{rooster[y][x] = 1;hit2++;}}
                  }
              }
           }
           else
           {
              p=Math.random();
              int chk=0;double perc=p*max_x*max_y;int alt=0;
              for(int x=1;x<max_x+1;x++){
                  for(int y=1;y<max_y+1;y++){
                     if(level<2){chk++; if(chk<perc){rooster[y][x] = -1;hit1++;}else{rooster[y][x] = 1;hit2++;}}
                     else
                     {
                         chk++; if(chk<perc && alt==0){rooster[y][x] = -1;hit1++;alt=1;}else{rooster[y][x] = 1;hit2++;alt=0;}
                     }
                  }
              }          
           }
           if(hit1==0){rooster[1][1]=-1;}
           if(hit2==0){rooster[1][1]=1;}
       }
       // plaatje tussen x=1 ...max_x+1 x=0/x=max_x+2===0
       if(interactive==1){
           for(int x=1;x<max_x+1;x++){;
              for(int y=1;y<max_y+1;y++){
                  rooster[y][x]=1;
              }
           }
           addMouseListener(
              new MouseAdapter(){
                  public void mousePressed(MouseEvent e){
                     dx = e.getX() / hokje_x;
                     dy = e.getY() / hokje_y;
                     if(dx<max_x+1 && dy<max_y+1 && dx>0 && dy>0){
                         rooster[dy][dx] = -1 * rooster[dy][dx];
                         //System.out.println("rooster[dy][dx]="+rooster[dy][dx]+" dx="+dx+" dy="+dy);
                         repaint();
                     }
                  }
              }
           );
       }
    }
void rooster.paint ( Graphics  g) [inline]

Definition at line 278 of file rooster.java.

                                {
      tekening.setColor(Color.white);
      tekening.fillRect(0,0,xsize,ysize);

      for(int t1 = 0;t1 < max_x+2;t1 ++){
         for(int t2 = 0;t2 < max_y+2;t2 ++){
           if(rooster[t2][t1]!=0){
              if(rooster[t2][t1] == 1){tekening.setColor(new Color(R1,G1,B1));}else{tekening.setColor(new Color(R2,G2,B2));}
              tekening.fill3DRect(hokje_x*t1,hokje_y*t2,hokje_x,hokje_y,true);
            }
        }
      }
      g.drawImage(plaatje,0,0,this);
   }

Here is the caller graph for this function:

String rooster.ReadApplet ( ) [inline]

Definition at line 318 of file rooster.java.

                             {
       // x==1
       double hy=1.000*hokje_y;
       double hx=1.000*hokje_x;
       double factor=hy/hx;
       //double hy=Double.valueOf(hokje_y);
       //double hx=Double.valueOf(hokje_x);
       //double factor=hy/hx;
        int changed=0;int original=0;int total=0;
        // rooster[y][x]=0 white border
        // rooster[y][x]=-1 clicked
        // rooster[y][x]=1  unchanged
        for(int t1 = 0;t1 < max_x+2;t1 ++){
           for(int t2 = 0;t2 < max_y+2;t2 ++){
              if(rooster[t2][t1] == -1){ changed++; total++;  }
              if(rooster[t2][t1] ==  1){ original++; total++; }
           }
        }

        double border[][]=new double[max_y+4][2*max_x+4];
        int c1;int c2;double t=0;
        for( c1 = 1; c1 < max_x+1 ;c1++){
           for( c2 =1; c2 < max_y+1 ;c2++){
              if(rooster[c2][c1] == -1 ){t=0;
                  if((rooster[c2][c1-1] != -1) && (rooster[c2][c1+1] != -1) ){t=t+factor*2;}else{if( (rooster[c2][c1-1] != -1) || (rooster[c2][c1+1] != -1) ){t=t+factor;}}
                  if( (rooster[c2-1][c1] != -1) && (rooster[c2+1][c1] != -1) ){t=t+2;}else{if( (rooster[c2-1][c1] != -1) || (rooster[c2+1][c1] != -1) ){t=t+1;}}
                  border[c2][c1]=t;
              }
           }
       }
       double cnt=0;
       for( c1=1 ; c1<max_x+1 ; c1++ ){
           for( c2=1 ; c2<max_y+1 ; c2++ ){
              cnt=cnt+border[c2][c1];
           }
       }
        String S=total+","+original+","+changed+","+cnt;
        return S;
    }
void rooster.run ( ) [inline]

Definition at line 304 of file rooster.java.

                    {
      while(thread != null){
         try{
            Thread.sleep(100);
         }
         catch (InterruptedException e){
         }
      }
   }
void rooster.start ( ) [inline]

Definition at line 293 of file rooster.java.

                      {
      if(thread == null){
         thread = new Thread(this);
         thread.start();
      }
   }
void rooster.stop ( ) [inline]

Definition at line 300 of file rooster.java.

                     {
      thread =  null;
   }
void rooster.update ( Graphics  g) [inline]

Definition at line 314 of file rooster.java.

                                   {
      paint( g ) ;
   }

Here is the call graph for this function:


Member Data Documentation

int rooster.B1 = 040 [package]

Definition at line 73 of file rooster.java.

int rooster.B2 = 111 [package]

Definition at line 74 of file rooster.java.

int rooster.dx [package]

Definition at line 68 of file rooster.java.

int rooster.dy [package]

Definition at line 68 of file rooster.java.

int rooster.G1 = 222 [package]

Definition at line 73 of file rooster.java.

int rooster.G2 = 222 [package]

Definition at line 74 of file rooster.java.

int rooster.hokje_x = 20 [package]

Definition at line 70 of file rooster.java.

int rooster.hokje_y = 20 [package]

Definition at line 70 of file rooster.java.

int rooster.interactive = 1 [package]

Definition at line 75 of file rooster.java.

int rooster.level = 3 [package]

Definition at line 75 of file rooster.java.

int rooster.max_x = 20 [package]

Definition at line 65 of file rooster.java.

int rooster.max_y = 20 [package]

Definition at line 65 of file rooster.java.

int rooster.percentage = 0 [package]

Definition at line 75 of file rooster.java.

Image rooster.plaatje [package]

Definition at line 69 of file rooster.java.

int rooster.R1 = 111 [package]

Definition at line 73 of file rooster.java.

int rooster.R2 = 040 [package]

Definition at line 74 of file rooster.java.

int rooster.rooster[][] [package]

Definition at line 66 of file rooster.java.

final int rooster.serialVersionUID = 1 [static, private]

Definition at line 64 of file rooster.java.

Graphics rooster.tekening [package]

Definition at line 69 of file rooster.java.

Thread rooster.thread = null [package]

Definition at line 68 of file rooster.java.

int rooster.xsize = hokje_x*max_x [package]

Definition at line 71 of file rooster.java.

int rooster.ysize = hokje_y*max_y [package]

Definition at line 72 of file rooster.java.


The documentation for this class was generated from the following file: