Advertisement
Guest User

Untitled

a guest
Mar 7th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. public class Difficult {
  2.     protected static int[] buffer;
  3.     protected static int width = 40;
  4.     protected static int height = 40;
  5.  
  6.   private static void draw_line(int x, int y, int xx, int yy) {
  7.     for(int sy = y; sy <= yy; sy++) {
  8.       for(int sx = x; sx <= xx; sx++) {
  9.         buffer[sy * height + sx] = 1;
  10.       }
  11.     }
  12.   }
  13.  
  14.   public static void main(String [] args) {
  15.     int speed = 1;
  16.     int x = width / 2;
  17.     int y = height / 2;
  18.     buffer = new int[width*height];
  19.     for(int i = 0; i < height - 4; i++) {
  20.       int dir = i % 4;
  21.       switch(dir) {
  22.         // up
  23.         case 0:
  24.           draw_line(x, y-speed, x, y);
  25.           y -= speed;
  26.           break;
  27.         // left
  28.         case 1:
  29.           speed += 2;
  30.           draw_line(x-speed, y, x, y);
  31.           x -= speed;
  32.           break;
  33.         // down
  34.         case 2:
  35.           draw_line(x, y, x, y+speed);
  36.           y += speed;
  37.           break;
  38.         // right
  39.         case 3:
  40.           speed += 2;
  41.           draw_line(x, y, x+speed, y);
  42.           x += speed;
  43.           break;
  44.       }
  45.     }
  46.     // draw
  47.     for(int sy = 0; sy < height; sy++) {
  48.       for(int sx = 0; sx < width; sx++) {
  49.         if (buffer[sy*height+sx] == 1)
  50.           System.out.print("█");
  51.         else
  52.           System.out.print(" ");
  53.       }
  54.       System.out.print("\n");
  55.     }
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement