Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Graphic {
- /**
- * Given two-dimensional coordinates, decide whether the
- * point(x,y) is to be painted in black.
- *
- * This Method is to be overridden in derived classes.
- */
- public boolean black(double x, double y) {
- return false;
- }
- /**
- * Draw the graphic.
- * The graphic is drawn as nx by ny Pixel portable bitmap (to
- * stdout), showing the area in the rectangular with lower left
- * corner (x0,y0) and upper right corner (x0+lengthx,y0+lengthy).
- */
- public void draw(double x0, double y0,
- double lengthx, double lengthy,
- int nx, int ny)
- {
- System.out.println("P1");
- System.out.println(nx + " " + ny);
- for (int j=ny-1; j>=0; j--) {
- double y = y0 + (j + 0.5)*lengthy/ny;
- for (int i=0; i<nx; i++) {
- double x = x0 + (i + 0.5)*lengthx/nx;
- if (this.black(x,y)) {
- System.out.print("1 ");
- } else {
- System.out.print("0 ");
- }
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment