Draw generated hilbert curve
Get points from the generator one by one, drawing a line segment from the last point to the current point after each using curses.
This commit is contained in:
parent
4035ed4e2f
commit
7a89edd1e5
|
@ -0,0 +1,38 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
import curses
|
||||||
|
import time
|
||||||
|
|
||||||
|
from hilbertgenerator import Vector, hilbertgenerator
|
||||||
|
|
||||||
|
win = curses.initscr()
|
||||||
|
curses.curs_set(0)
|
||||||
|
n = 16
|
||||||
|
state = [ [0] * 2*n for x in range(2*n) ]
|
||||||
|
lastpos = None
|
||||||
|
# 0123456789abcdef
|
||||||
|
linechars = "·─│┌──┐┬│└│├┘┴┤┼"
|
||||||
|
for pos in hilbertgenerator(Vector(n, n), Vector(n, 0), Vector(0,n)):
|
||||||
|
if lastpos is not None:
|
||||||
|
dir = pos - lastpos
|
||||||
|
state[int(lastpos.y)][int(lastpos.x)] |= (
|
||||||
|
(dir.x > 0) * 1 |
|
||||||
|
(dir.y > 0) * 2 |
|
||||||
|
(dir.x < 0) * 4 |
|
||||||
|
(dir.y < 0) * 8
|
||||||
|
)
|
||||||
|
state[int(pos.y)][int(pos.x)] |= (
|
||||||
|
(dir.x < 0) * 1 |
|
||||||
|
(dir.y < 0) * 2 |
|
||||||
|
(dir.x > 0) * 4 |
|
||||||
|
(dir.y > 0) * 8
|
||||||
|
)
|
||||||
|
win.addch(int(lastpos.y), int(lastpos.x), linechars[state[int(lastpos.y)][int(lastpos.x)]])
|
||||||
|
win.refresh()
|
||||||
|
time.sleep(0.1)
|
||||||
|
win.addch(int(pos.y), int(pos.x),
|
||||||
|
linechars[state[int(pos.y)][int(pos.x)]])
|
||||||
|
win.refresh()
|
||||||
|
time.sleep(0.1)
|
||||||
|
lastpos = pos
|
||||||
|
time.sleep(5)
|
||||||
|
curses.endwin()
|
Loading…
Reference in New Issue