Guest User

Untitled

a guest
Aug 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class Graphic {
  2.  
  3. /**
  4. * Given two-dimensional coordinates, decide whether the
  5. * point(x,y) is to be painted in black.
  6. *
  7. * This Method is to be overridden in derived classes.
  8. */
  9. public boolean black(double x, double y) {
  10. return false;
  11. }
  12.  
  13. /**
  14. * Draw the graphic.
  15. * The graphic is drawn as nx by ny Pixel portable bitmap (to
  16. * stdout), showing the area in the rectangular with lower left
  17. * corner (x0,y0) and upper right corner (x0+lengthx,y0+lengthy).
  18. */
  19. public void draw(double x0, double y0,
  20. double lengthx, double lengthy,
  21. int nx, int ny)
  22. {
  23. System.out.println("P1");
  24. System.out.println(nx + " " + ny);
  25.  
  26. for (int j=ny-1; j>=0; j--) {
  27. double y = y0 + (j + 0.5)*lengthy/ny;
  28.  
  29. for (int i=0; i<nx; i++) {
  30. double x = x0 + (i + 0.5)*lengthx/nx;
  31.  
  32. if (this.black(x,y)) {
  33. System.out.print("1 ");
  34. } else {
  35. System.out.print("0 ");
  36. }
  37. }
  38.  
  39. System.out.println();
  40. }
  41. }
  42.  
  43. }
Add Comment
Please, Sign In to add comment