import java.awt.*; /* CS111 Fall 2000 Lab 2 September 20, 2000 Drawing a multicolored checkerboard using methods Wendy Wellesley CS111 */ public class BigChecksboard extends BuggleWorld { int n=15; public void setup() { setDimensions(n,n); } public void run () { // create dude who draws the multicolored checkerboard CheckerBuggle dude = new CheckerBuggle(); dude.drawBoard(); } } class CheckerBuggle extends Buggle { // drawBoard draws the entire board and sets the buggle back to the center of the board public void drawBoard(){ this.drawRow(); this.moveToNewRow(); this.drawRow(); this.moveToNewRow(); this.drawRow(); this.moveToCenter(); } // moveToCenter moves the buggle from the end of a row to the center of the board public void moveToCenter() { this.brushUp(); this.backward(3); this.left(); this.backward(3); } // drawRow draws one row of the board, which consists of 3 blocks public void drawRow() { drawBlock(); scoot(); drawBlock(); scoot(); drawBlock(); } // scoot moves the buggle to the starting position to draw a block public void scoot() { this.brushUp(); this.forward(5); this.brushDown(); } // moveToNewRow moves the buggle from the end of one row to the start of the next one public void moveToNewRow() { this.brushUp(); this.left(); this.forward(5); this.left(); this.forward(10); this.right(); this.right(); this.brushDown(); } // drawBlock draws one block of the board public void drawBlock() { this.setColor(Color.red); this.drawPattern(); this.setColor(Color.blue); this.drawPattern(); this.setColor(Color.yellow); this.drawPattern(); this.setColor(Color.black); this.drawPattern(); } // drawPattern draws one step pattern public void drawPattern () { this.brushUp(); this.forward(); this.brushDown(); this.forward(); this.brushUp(); this.left(); this.forward(); this.brushDown(); this.backward(); this.right(); this.brushUp(); this.forward(); this.brushDown(); this.forward(); this.left(); } }