fork download
  1. public class Main {
  2. public static void main(String[] args) {
  3. VirtualScreen screen = new VirtualScreen(40, 10);
  4.  
  5. screen.box('+', 3, 0, 20, 9);
  6.  
  7. screen.line('#', 5, 2, 3, 9);
  8. screen.line('#', 7, 2, 10, 9);
  9.  
  10. screen.line('#', 9, 1, 9, 3);
  11. screen.line('#', 11, 1, 11, 3);
  12.  
  13. screen.line('#', 14, 2, 19, 2);
  14. screen.line('#', 18, 2, 19, 9);
  15. screen.line('#', 19, 8, 17, 8);
  16.  
  17. screen.line('#', 16, 1, 13, 9);
  18.  
  19. screen.circle('*', 28, 5, 4);
  20. screen.circle('*', 28, 5, 2);
  21.  
  22. screen.print();
  23. }
  24. }
  25.  
  26. class VirtualScreen {
  27. protected int width;
  28. protected int height;
  29. protected String[] lines;
  30.  
  31. VirtualScreen() {
  32. this(80, 25);
  33. }
  34. VirtualScreen(int width, int height) {
  35. this(' ', width, height);
  36. }
  37. VirtualScreen(char ch, int width, int height) {
  38. reset(ch, width, height);
  39. }
  40.  
  41. public void reset(char ch, int width, int height) {
  42. this.width = width;
  43. this.height = height;
  44. this.lines = new String[height];
  45. for (int i = 0; i < height; ++i) {
  46. lines[i] = "";
  47. for (int j = 0; j < width; ++j) {
  48. lines[i] = lines[i] + ch;
  49. }
  50. }
  51. }
  52.  
  53. public void print() {
  54. for (int y = 0; y < height; ++y) {
  55. System.out.println(lines[y]);
  56. }
  57. }
  58.  
  59. public void setPixel(char ch, int x, int y) {
  60. if (x < 0 || width <= x)
  61. return;
  62. if (y < 0 || height <= y)
  63. return;
  64. String str = lines[y];
  65. lines[y] = str.substring(0, x) + ch + str.substring(x + 1);
  66. }
  67.  
  68. public void fillBox(char ch, int left, int top, int right, int bottom) {
  69. for (int y = top; y <= bottom; ++y) {
  70. for (int x = left; x <= right; ++x) {
  71. setPixel(ch, x, y);
  72. }
  73. }
  74. }
  75.  
  76. public void line(char ch, int x0, int y0, int x1, int y1) {
  77. int dx = x1 - x0, dy = y1 - y0;
  78. if (Math.abs(dx) <= Math.abs(dy)) {
  79. if (dy < 0) {
  80. for (int y = y1; y <= y0; ++y) {
  81. int x = x1 + rdiv((y - y1) * dx , dy);
  82. setPixel(ch, x, y);
  83. }
  84. } else if (dy > 0) {
  85. for (int y = y0; y <= y1; ++y) {
  86. int x = x0 + rdiv((y - y0) * dx , dy);
  87. setPixel(ch, x, y);
  88. }
  89. } else { // dy == 0
  90. int y = y0;
  91. setPixel(ch, x, y);
  92. }
  93. } else {
  94. if (dx < 0) {
  95. for (int x = x1; x <= x0; ++x) {
  96. int y = y1 + rdiv((x - x1) * dy , dx);
  97. setPixel(ch, x, y);
  98. }
  99. } else if (dx > 0) {
  100. for (int x = x0; x <= x1; ++x) {
  101. int y = y0 + rdiv((x - x0) * dy , dx);
  102. setPixel(ch, x, y);
  103. }
  104. } else { // dx == 0
  105. int x = x0;
  106. setPixel(ch, x, y);
  107. }
  108. }
  109. }
  110.  
  111. public void box(char ch, int x0, int y0, int x1, int y1) {
  112. line(ch, x0, y0, x1, y0);
  113. line(ch, x1, y0, x1, y1);
  114. line(ch, x1, y1, x0, y1);
  115. line(ch, x0, y1, x0, y0);
  116. }
  117.  
  118. public void circle(char ch, int x, int y, double r) {
  119. if (r == 0) {
  120. return;
  121. }
  122. for(double t = 0; t < 2 * Math.PI; t += 1 / (2 * Math.PI * r)) {
  123. double px = x + r * Math.cos(t);
  124. double py = y + r * Math.sin(t);
  125. setPixel(ch, round(px), round(py));
  126. }
  127. }
  128.  
  129. protected int round(double d) {
  130. return (int)Math.round(d);
  131. }
  132.  
  133. protected int rdiv(double a, double b) {
  134. return round(a / b);
  135. }
  136. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:91: error: cannot find symbol
				setPixel(ch, x, y);
				             ^
  symbol:   variable x
  location: class VirtualScreen
Main.java:106: error: cannot find symbol
				setPixel(ch, x, y);
				                ^
  symbol:   variable y
  location: class VirtualScreen
2 errors
stdout
Standard output is empty