StdDraw.java


This is the syntax highlighted version of StdDraw.java from 2.4 Input and Output of
Introduction to Computer Science by Robert Sedgewick and Kevin Wayne.

import java.awt.Color;
import java.awt.Font;

public class StdDraw {
    private static Draw draw;

    // can't instantiate new objects
    private StdDraw() { }

    // create a canvas with drawing area width-by-height
    static public void create(int width, int height) {

        // If we don't already have one, create a new one
        if (draw == null) draw = new Draw(width, height);
        else throw new RuntimeException("Attempted to call StdDraw.create twice");
    }

    static public void setScale(double xmin, double ymin, double xmax, double ymax) {
        draw.setScale(xmin, ymin, xmax, ymax);
    }

    public static int width()                   { return draw.width();       }
    public static int height()                  { return draw.height();      }
    public static double x()                    { return draw.x();           }
    public static double y()                    { return draw.y();           }
    public static double orientation()          { return draw.orientation(); }
    public static void penDown()                { draw.penDown();            }
    public static void penUp()                  { draw.penUp();              }
    public static void fillOn()                 { draw.fillOn();             }
    public static void fillOff()                { draw.fillOff();            }

    public static void clear()                  { draw.clear();        }
    public static void clear(Color bg)          { draw.clear(bg);      }
    public static void pause(int delay)         { draw.pause(delay);   }
    public static void setColor(Color c)        { draw.setColor(c);    }
    public static void setColorRGB(int r, int g, int b)           { draw.setColorRGB(r, g, b);    }
    public static void setColorHSB(int h, int s, int b)           { draw.setColorHSB(h, s, b);    }
    public static void setColorHSB(double h, double s, double b)  { draw.setColorHSB(h, s, b);    }
    public static void setColorRandom()                           { draw.setColorRandom();        }
    public static void setFont(Font font)       { draw.setFont(font);  }
    public static void go(double x, double y)   { draw.go(x, y);       }
    public static void goForward(double d)      { draw.goForward(d);   }
    public static void spot()                   { draw.spot();         }
    public static void spot(double w, double h) { draw.spot(w, h);     }
    public static void spot(double d)           { draw.spot(d);        }         
    public static void spot(String s)           { draw.spot(s);        }
    public static void spot(String s, double w, double h) { draw.spot(s, w, h); }
    public static void rotate(double angle)     { draw.rotate(angle);  }
    public static void play(String s)           { draw.play(s);        } 
    public static void write(String s)          { draw.write(s);       } 
    public static void show()                   { draw.show();         } 
    public static void save(String s)           { draw.save(s);        } 

    public static void main(String args[]) {
        StdDraw.create(600, 600);
        StdDraw.clear(Color.gray);
        StdDraw.go(200, 300);
        StdDraw.spot(50);
        StdDraw.setColor(Color.blue);
        StdDraw.write("Hi");
        StdDraw.go(500, 300);
        StdDraw.spot("joker.gif");
        StdDraw.show();
    }
 

   
}


Last updated: Thu Sep 16 11:36:57 EDT 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.