import math
import itertools

def digits(t, b): #assumes t < b
	mantissa = b
	while True:
		mantissa /= b
		digit = math.floor(t/mantissa)
		t -= digit * mantissa
		yield digit

template = "\draw[thick, {3}, {{[-)}}] ({0}, {2}) -- ({1}, {2});"
def pt(ints, y, colorfun):
    for ((a, b), d) in ints:
        print(template.format(a*10,b*10,y, colorfun(d)))

def intervals(t, b, depth):
    digs = list(itertools.islice(digits(t,b), depth))
    digs[-1] += 1
    x = 0
    for i, d in enumerate(digs):
        for k in range(d):
            yield ((x, x+b**(-i)), i)
            x += b**(-i)