Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 7th, 2012  |  syntax: Java  |  size: 1.35 KB  |  views: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data