public void paint () {
    int window_size = Math.min (window.width, window.height);

    for (int i=0; i<square_count; i++) {
      int random_size = window_size <= min_size ? window_size
        : min_size + random.nextInt (window_size-min_size);

      /* Size of square must be a power of two, or filling will not be
       * completed.
       */
      int size = 1 << (int) (Math.log (random_size) / Math.log (2));


      // square always fully inside the window
      int origin_x = random_int (window.width - size);
      int origin_y = random_int (window.height - size);

      gc.set_foreground (random_color ());

      // shift factors
      int t0 = 0, x0 = 0, y0 = 0;
      if (shift) {
        t0 = random.nextInt (size);
        x0 = random.nextInt (size);
        y0 = random.nextInt (size);
      }      

      for (int t=0; t<size; t++) {
        for (int x=0; x<size; x++) {
          int y = x ^ ((t + t0) % size);

          int point_x = origin_x + (x + x0) % size;
          int point_y = origin_y + (y + y0) % size;
          
          window.point (gc, point_x, point_y);          
        }
        if (sleep (draw_delay)) return;
      }
    }
  }