From 7a89edd1e523ea3f8ef7ea289d76e009f3b6f3f4 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 29 Dec 2018 21:55:53 +0100 Subject: [PATCH] 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. --- Python/draw_hilbertgenerator | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 Python/draw_hilbertgenerator diff --git a/Python/draw_hilbertgenerator b/Python/draw_hilbertgenerator new file mode 100755 index 0000000..2c453f5 --- /dev/null +++ b/Python/draw_hilbertgenerator @@ -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()