import java.awt.*; /* CS111 Lab 2: Writing Java Methods - Task 2: Checksboard NAME: Stella BAsed on an older version used in CS111 previously WHEN: Aug 24, 2007 COMMENTS: */ public class Checksboard extends BuggleWorld { public void setup() { setDimensions(5,5); } /*The checkerboard we are asked to draw can be seen as consisted of 4 individual triangles. So, the method drawOneTriangle() is called 4 times in order to create the final pattern. */ //Notice how the position and facing of the Buggle after it has drawn //a triangle, is critical to successfully drawing the next one! public void run () { CheckerBuggle cheek = new CheckerBuggle(); //create a new instance of a CheckerBuggle cheek.draw4Triangles(); } // run() //------------------------------------------------------------------------------ // The following main method is needed to run the applet as an application public static void main (String[] args) { runAsApplication(new Checksboard(), "Checksboard"); } } // class Checksboard //************************************************************** class CheckerBuggle extends Buggle { // draws one basic triangle, made of three basic squares. //Leaves the buggle to the right of the right basis, facing NORTH 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() //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() { drawOneTriangle(); //ends next to the right basis, facing NORTH setColor(Color.blue); drawOneTriangle(); //draw the second triangle setColor(Color.yellow); drawOneTriangle(); setColor(Color.black); drawOneTriangle(); //draw the fourth triangle } } // class CheckerBuggle