import java.awt.*; /* CS111 Lab 2: Writing Java Methods - Task 3: BigChecksboard NAME: Stella based on older version of it. WHEN: Aug 24, 2007 COMMENTS: */ public class BigChecksboard extends BuggleWorld { //set up the dimensions of the grid to draw on public void setup() { setDimensions(15,15); } public void run () { CheckerBuggle cheek = new CheckerBuggle(); //cheek.drawOneTriangle(); //test it, then comment it out cheek.drawOneRow(); //draw the first row of triangles cheek.positionForNewRow(); cheek.drawOneRow(); ////draw the second row of triangles cheek.positionForNewRow(); cheek.drawOneRow(); ////draw the third row of triangles cheek.positionFinal(); } // run() //------------------------------------------ // The following main method is needed to run the applet as an application public static void main (String[] args) { runAsApplication(new BigChecksboard(), "BigChecksboard"); } } // class BigChecksboard //************************************************************** class CheckerBuggle extends Buggle { // Defines CheckerBuggle to be able to accomplish more sub-tasks, by defining more methods. //Position the drawing buggle at the center of the final Bigboard public void positionFinal(){ setColor(Color.black); brushUp(); backward(3); left(); backward(3); } //Position the drawing buggle at the right place to start drawing the next //row: 5th row above and 10th column back public void positionForNewRow() { brushUp(); backward(10); left(); forward(5); right(); setColor(Color.red); } public void drawOneRow() { //one row contains 3 patterns, each made of 4-triangles (one of each color). draw4Triangles(); brushUp(); forward(5); brushDown(); setColor(Color.red); draw4Triangles(); brushUp(); forward(5); brushDown(); setColor(Color.red); draw4Triangles(); setColor(Color.red); } //Draws 4 basic little triangles, to fill up completely a 5x5 grid, as asked in task 2 //Uses the previuosly defined drawOneTriangle () method public void draw4Triangles() { drawTriangle(); setColor(Color.blue); drawTriangle(); setColor(Color.yellow); drawTriangle(); setColor(Color.black); drawTriangle(); } //Draw one little triangle public void drawOneTriangle () { //debugging statement below prints to console //System.out.println("Just inside drawOneTriangle method"); brushUp(); forward(); brushDown(); forward(); brushUp(); left(); forward(); brushDown(); backward(); right(); brushUp(); forward(); brushDown(); forward(); left(); //debugging statement below prints to console window //System.out.println("About to leave drawOneTriangle method"); } // drawOneTriangle() }