Advertisement
Guest User

A window made from Box Drawing and Block Elements characters

a guest
Apr 2nd, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. import PyBearLibTerminal as T
  2.  
  3. def draw_window(x, y, w, h):
  4.     # Transflucent background
  5.     T.color('#C0A0A0A0')
  6.     T.put(x,     y,     0x2597) # Corners
  7.     T.put(x+w-1, y,     0x2596)
  8.     T.put(x+w-1, y+h-1, 0x2598)
  9.     T.put(x,     y+h-1, 0x259D)
  10.     for i in range(x+1, x+w-1): # Horisontal borders
  11.         T.put(i, y,     0x2584)
  12.         T.put(i, y+h-1, 0x2580)
  13.     for i in range(y+1, y+h-1): # Vertical borders
  14.         T.put(x,     i, 0x2590)
  15.         T.put(x+w-1, i, 0x258C)
  16.     for i in range(x+1, x+w-1): # Fill
  17.         for j in range(y+1, y+h-1):
  18.             T.put(i, j, 0x2588)
  19.     # Thin, solid border
  20.     T.color('white')
  21.     T.put(x,     y,     0x250C) # Corners
  22.     T.put(x+w-1, y,     0x2510)
  23.     T.put(x+w-1, y+h-1, 0x2518)
  24.     T.put(x,     y+h-1, 0x2514)
  25.     for i in range(x+1, x+w-1): # Horisontal borders
  26.         T.put(i, y,     0x2500)
  27.         T.put(i, y+h-1, 0x2500)
  28.     for i in range(y+1, y+h-1): # Vertical borders
  29.         T.put(x,     i, 0x2502)
  30.         T.put(x+w-1, i, 0x2502)
  31.  
  32. T.open()
  33. T.set('font: ../ttf-fonts/consola.ttf, size=16')
  34. T.set('input.filter=[keyboard, system]') # Disable mouse to make read() behave like getch()
  35. T.set('window.size=28x10')
  36. T.set('terminal.encoding=utf8')
  37. T.composition(True) # Simpler than layers
  38.  
  39. # Checkered background
  40. for x in range(0, 12):
  41.     for y in range(0, 8):
  42.         T.color('darkest green' if ((x+y) % 2 == 0) else 'darkest red')
  43.         T.put(x*2 + 2, y + 1, 0x2588)
  44.         T.put(x*2 + 3, y + 1, 0x2588)
  45.  
  46. draw_window(5, 2, 18, 6)
  47. T.printf(5+2, 2+1, '[color=white]Hello, window!')
  48.  
  49. T.refresh()
  50. T.read()
  51. T.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement