All pastes #709953 Raw Edit

Something

public text v1 · immutable
#709953 ·published 2007-09-25 02:59 UTC
rendered paste body
public class Main extends GraphicsProgram {
    public void run() {
        int n;
        n=readInt("rows?");
        GRect bamf;
        int xtreme;
        int positionX=0;
        int positionY=0;
        int columns;
        int rows;
        columns=1;
        String rulebook=readLine("enter rulebook");
        for(int i=0; i<(2*n-1); i++){
            bamf = new GRect(i*8, 0, 8, 14);
            bamf.setFilled(true);

            if(i==(2*n-1)/2){
                bamf.setColor(Color.GREEN);
            } else {
                bamf.setColor(Color.GRAY);
            }
            add(bamf);
        }
        while(columns<(2*n-1)){ 
            rows=1;
                while(rows<n) {
                    xtreme=0;
                    bamf = new GRect(8*rows,14*columns,8,14);
                    bamf.setFilled(true);
                    GObject westside = getElementAt(positionX-8, positionY-14);
                    GObject northside = getElementAt(positionX, positionY-14);
                    GObject eastside = getElementAt(positionX+8, positionY-14);
                    if(westside == null) {
                        xtreme += 0;
                    } else if((westside.getColor()).equals(Color.GREEN)) {
                        xtreme += 4;
                    }
                    if((northside.getColor()).equals(Color.GREEN)) {
                        xtreme += 2;
                    }
                    if(eastside == null){
                        xtreme+=0;
                    }else if((eastside.getColor()).equals(Color.GREEN)) {
                        xtreme += 1;
                    }
                    if(rulebook.substring(xtreme, xtreme+1).equals("1")) {
                        bamf.setColor(Color.GREEN);
                    } else {
                        bamf.setColor(Color.GRAY);
                    }
                    this.add(bamf);                    
                    rows++;
                    positionX += 8;                
                }
              columns++;
              positionY += 14;  
    }            
    }
}