Sample Use of GenDraw


and the code to draw it

public class Sample {

    public static void draw(GenDraw canvas) {
	// label the corners
	canvas.text(0.03, .00, "(0, 0)");
	canvas.text(0.97, .97, "(1, 1)");

	// draw a blue square centered at (.25, .75)
	double x1 = .25;
	double y1 = .75;
	canvas.setPenColor(GenDraw.BLUE);
	canvas.filledSquare(x1, y1, .25);

	// write "Hello" in yellow the blue square at
	canvas.setPenColor(GenDraw.YELLOW);
	canvas.text(x1, y1, "Hello");


	// draw a red rectangle w/ lower left corner (.5, 0)
	// width .5 and height .4
	double[] xs = {0.5, 1.0, 1.0, 0.5};
	double[] ys = {0.0, 0.0, 0.4, 0.4};
	canvas.setPenColor(GenDraw.RED);
	canvas.filledPolygon(xs, ys);

	// write "World" in yellow the red rectangle at
	// 45 degrees
	double x2 = .75;
	double y2 = .25;
	canvas.setPenColor(GenDraw.YELLOW);
	canvas.rotText(x2, y2, 45, "World");

	// write the largest prefix of "abcde..." that is
	// no more than .25 in width
	double x3 = .25;
	double y3 = .25;
	canvas.setPenColor(GenDraw.BLACK);
	canvas.text(x3, y3, "abcdefghijklmnopqrstuvwxyz", .25);
    }


    public static void main(String[] args) {
	// set up a canvas with lower left corner of 0,0
	// and upper right corner of 1,1.
        GenDraw canvas = new GenDraw("Square Example");
        canvas.setXscale(0.0, 1.0);
	canvas.setYscale(0.0, 1.0);

	draw(canvas);
	canvas.show();
	canvas.save("sample.png");
   }
}