Esempio n. 1
0
def gridspanningtree(length, height, d=2, r=0, color=Color(255, 0, 0), g="grid", filename=None, treefunc="dfs", gif=False,
                     save=True):
    images = []
    if not isinstance(g, Graph):
        (x, y) = (randint(0, length - 1), randint(0, height - 1))
        g = getattr(Graph, g)(length, height).treefunc(treefunc, (x, y))
    else:
        (x, y) = list(g.dict.keys)[0]
    vw = ViewWindow(dimx=d * length + d - 1, dimy=d * height + d - 1)
    data = PlotData(vw)
    color2 = 0.8 * color
    for v1 in g.dict:
        for i in range(-r, r + 1):
            for j in range(-r, r + 1):
                data.putpixel((d * (v1[0] + 1) - 1 + i, d * (v1[1] + 1) - 1 + j), color)
    s = {(x, y)}
    q = [(x, y)]
    while q:
        v1 = q.pop(0)
        for v2 in g.dict[v1]:
            if v2 not in s:
                for i in range(1 + r, d - r):
                    data.putpixel(
                        (d * (v1[0] + 1) - 1 + (v2[0] - v1[0]) * i, d * (v1[1] + 1) - 1 + (v2[1] - v1[1]) * i), color2)
                q.append(v2)
                s.add(v2)
                if gif:
                    images.append(data.save("", False))
    if filename is None:
        filename = "gst " + str((length, height)) + " " + str(int(time()))
    ret = data.save(filename, save)
    if gif:
        writegif(filename, images, 0.01)
    return ret
Esempio n. 2
0
def basin2(f,
           rootlist,
           colorlist=None,
           vw=ViewWindow(),
           df=None,
           n=10,
           dots=True,
           filename="basin2" + str(int(time())),
           dist=0.3,
           save=True):
    if df is None:
        df = diffquo(f, .0001)
    if colorlist is None:
        colorlist = Color.colors(len(rootlist))
    data = PlotData(vw)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            z = vw.xpxcart(i) + vw.ypxcart(j) * 1j
            for k in range(n):
                z = newton(f, z, df, 1)
                index = closest(rootlist, z)
                d = abs(z - rootlist[index])
                if d < dist or k == n - 1:
                    data.putpixel((i, j),
                                  max(.2, 1 - float(k) / n) * colorlist[index])
                    break
    if dots:
        for r in rootlist:
            data.putpoint((r.real, r.imag), 0)
    return data.save(filename, save)
Esempio n. 3
0
def basin3(f,
           rootlist,
           colorlist=None,
           vw=ViewWindow(),
           df=None,
           n=10,
           dots=True,
           filename="basin" + str(int(time())),
           save=True):
    if df is None:
        df = diffquo(f, .0001)
    if colorlist is None:
        colorlist = Color.colors(len(rootlist))
    data = PlotData(vw)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            z = vw.xpxcart(i) + vw.ypxcart(j) * 1j
            for k in range(n + 1):
                data.putpixel((i, j),
                              colorlist[closest(rootlist, z)],
                              add=True,
                              avg=True)
                if k != n:
                    z = newton(f, z, df, 1)
    if dots:
        for r in rootlist:
            data.putpoint((r.real, r.imag), 0)
    return data.save(filename, save)
Esempio n. 4
0
def polarshade(r1,
               r2,
               vw=ViewWindow(),
               color=None,
               auto=False,
               filename="polarshade" + str(int(time())),
               save=True):
    if auto:
        vw.autoparam(
            [lambda t0: r1(t0) * cos(t0), lambda t0: r2(t0) * cos(t0)],
            [lambda t0: r1(t0) * sin(t0), lambda t0: r2(t0) * sin(t0)])
    data = PlotData(vw)
    th = vw.thick * (vw.xmax - vw.xmin) / vw.dimx
    if color is None:
        c = Color(255, 0, 0)
    else:
        c = color
    for i in range(vw.dimx):
        x = vw.xpxcart(i)
        for j in range(vw.dimy):
            y = vw.ypxcart(j)
            t = atan2(y, x)
            r = sqrt(x**2 + y**2)
            if color == 'rainbow':
                c = Color.rbow(t)
            if r1(t) - th <= r <= r2(t) + th or r2(t) - th <= r <= r1(t) + th:
                data.putpixel((i, j), c)
    return data.save(filename, save)
Esempio n. 5
0
def voronoi(rootlist, colorlist=None, vw=ViewWindow(), dots=True, metric=lp(2), select=1,
            filename="voronoi" + str(int(time())), save=True):
    if colorlist is None:
        colorlist = Color.colors(len(rootlist))
    data = PlotData(vw)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            data.putpixel((i, j), colorlist[closest(rootlist, vw.xpxcart(i) + vw.ypxcart(j) * 1j, metric, select)])
    if dots:
        for r in rootlist:
            data.putpoint((r.real, r.imag), 0)
    return data.save(filename, save)
Esempio n. 6
0
def basin(f, rootlist, colorlist=None, vw=ViewWindow(), df=None, n=10, dots=True,
          filename="basin" + str(int(time())), save=True):
    if df is None:
        df = diffquo(f, .0001)
    if colorlist is None:
        colorlist = Color.colors(len(rootlist))
    data = PlotData(vw)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            data.putpixel((i, j), colorlist[closest(rootlist, newton(f, vw.xpxcart(i) + vw.ypxcart(j) * 1j, df, n))])
    if dots:
        for r in rootlist:
            data.putpoint((r.real, r.imag), 0)
    return data.save(filename, save)
Esempio n. 7
0
def color3d(f, vw=ViewWindow(), base=1.0, pos=Color(255, 0, 0), neg=Color(0, 0, 255),
            filename="color3d" + str(int(time())), save=True):
    data = PlotData(vw)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            (x, y) = vw.px2cart((i, j))
            color = Color()
            val = f((x, y))
            if val > 0:
                color = abs(val / base) * pos
            if val < 0:
                color = abs(val / base) * neg
            data.putpixel((i, j), color)
    return data.save(filename, save)
Esempio n. 8
0
def mandelbrot(vw=ViewWindow(xmin=-2.3, xmax=0.7, ymin=-1.5, ymax=1.5, dimx=700, dimy=701), n=50, reflect=True,
               color=Color(255, 0, 0), filename=None, save=True):
    data = PlotData(vw)
    color0 = color
    if callable(color):
        colorfunc = color
    else:
        colorfunc = lambda t: t * color0
    for p in vw.pxiterator():
        c = vw.xpxcart(p[0]) + vw.ypxcart(p[1]) * 1j
        if c.imag > -0.1 or not reflect:
            i, z0 = 0, 0
            q = (c.real - 0.25) ** 2 + c.imag ** 2
            if q * (q + (c.real - 0.25)) < c.imag ** 2 / 4 or 16 * ((c.real + 1) ** 2 + c.imag ** 2) < 1:
                data.putpixel(p, colorfunc(1.0), flip=False)
                if reflect:
                    data.putpixel((p[0], vw.ycartpx(-c.imag)), colorfunc(1.0), flip=False)
            else:
                while abs(z0) < 2 and i < n:
                    z0 = z0 * z0 + c
                    i += 1
                data.putpixel(p, colorfunc(float(i) / n), flip=False)
                if reflect:
                    data.putpixel((p[0], vw.ycartpx(-c.imag)), colorfunc(float(i) / n), flip=False)
        else:
            break
        if PYGAME_PIXEL and p[0] == 0:
            pygame.display.flip()
    if filename is None:
        filename = "mandelbrot " + str(n) + " " + str(int(time()))
    return data.save(filename, save)
Esempio n. 9
0
def graphpict(length, height, graphtype="grid", treefunc="dfs", func="bfs", colorfunc="hilbert", gif=False, gifres=None, v0=None, v1=None,
              rand=True, save=True, scales=None):
    images = []
    clist = []
    if isinstance(graphtype, Graph):
        area = len(graphtype.dict)
    else:
        area = length * height
    if not colorfunc.startswith("rbow"):
        clist = colorcube(colorfunc)
    if func == "hilbert":
        l = hilbert(int(ceil(log(max(length, height), 2))))
        gstr = "None"
    else:
        if not isinstance(graphtype, Graph):
            gstr = graphtype
            graphtype = getattr(Graph, graphtype)(length, height)
        else:
            gstr = "Graph"
        if v0 is None:
            v0 = choice(graphtype.dict.keys())
        if treefunc is not None:
            if v1 is None:
                v1 = choice(graphtype.dict.keys())
            graphtype = graphtype.treefunc(treefunc, v1, rand)
            print "Computed spanning tree"
        l = graphtype.func(func, v0, rand)
    if gif and gifres is None:
        gifres = ceil(area / 150.0)
    vw = ViewWindow(dimx=length, dimy=height)
    data = PlotData(vw, scales=scales)
    i = 0
    for p in l:
        if colorfunc.startswith("rbow"):
            data.putpixel(p, getattr(Color, colorfunc)(2 * pi * i / area, 1))
        else:
            data.putpixel(p, Color(*[c * 4 for c in clist[min(64 ** 3 * i / area, 64 ** 3 - 1)]]))
        if gif and (i + 1) % gifres == 0:
            images.append(data.save("", False))
        i += 1
    filename = str((length, height)) + " " + gstr + " spanningtree" + str(treefunc) + " " + func + " " + colorfunc + " " + str(
        rand) + " " + str((v0, v1)) + " " + str(int(time()))
    ret = data.save(filename, save)
    if gif:
        writegif(filename, images, 0.001)
    return ret
Esempio n. 10
0
def newtondiff(f, vw=ViewWindow(), df=None, n=1, pxdist=1, filename="newtondiff" + str(int(time())), save=True):
    if df is None:
        df = diffquo(f, .0001)
    data = PlotData(vw)
    color1 = Color(0, 255, 0)
    color2 = Color(255, 0, 0)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            if i % pxdist == 0 and j % pxdist == 0:
                z0 = vw.xpxcart(i) + vw.ypxcart(j) * 1j
                z = newton(f, z0, df, n, 1e-1)
                if abs(z) < abs(z0):
                    color = color1
                else:
                    color = color2
                data.putpixel((i, j), color)
    return data.save(filename, save)
Esempio n. 11
0
def implicit(flist, vw=ViewWindow(), decay=100, colorlist=None, filename="implicit" + str(int(time())), save=True):
    data = PlotData(vw)
    color = 0
    if colorlist is None:
        colorlist = Color.colors(len(flist))
    for k in range(len(flist)):
        f = flist[k]
        if colorlist != "rainbow":
            color = colorlist[k]
        for i in range(vw.dimx):
            for j in range(vw.dimy):
                if colorlist == "rainbow":
                    color = Color.rbow(vw.xpxcart(i) + vw.ypxcart(j), 2)
                color0 = e ** (-decay * abs(f(*vw.px2cart((i, j))))) * color
                color0 += data[(i, j)]
                data.putpixel((i, j), color0)
    return data.save(filename, save)
Esempio n. 12
0
def julia(f, vw, n=50, zmax=2, color=Color(255, 0, 0), filename=None, save=True):
    data = PlotData(vw)
    if callable(color):
        colorfunc = color
    else:
        colorfunc = lambda t: t * color
    for p in vw.pxiterator():
        z = vw.xpxcart(p[0]) + vw.ypxcart(p[1]) * 1j
        i = 0
        while abs(z) < zmax and i < n:
            z = f(z)
            i += 1
        data.putpixel(p, colorfunc(float(i) / n), flip=False)
        if PYGAME_PIXEL and p[0] == 0:
            pygame.display.flip()
    if filename is None:
        filename = "julia " + str(n) + " " + str(zmax) + " " + str(int(time()))
    return data.save(filename, save)
Esempio n. 13
0
def gridspanningtree(length,
                     height,
                     d=2,
                     r=0,
                     color=Color(255, 0, 0),
                     g="grid",
                     filename=None,
                     treefunc="dfs",
                     gif=False,
                     save=True):
    images = []
    if not isinstance(g, Graph):
        (x, y) = (randint(0, length - 1), randint(0, height - 1))
        g = getattr(Graph, g)(length, height).treefunc(treefunc, (x, y))
    else:
        (x, y) = list(g.dict.keys)[0]
    vw = ViewWindow(dimx=d * length + d - 1, dimy=d * height + d - 1)
    data = PlotData(vw)
    color2 = 0.8 * color
    for v1 in g.dict:
        for i in range(-r, r + 1):
            for j in range(-r, r + 1):
                data.putpixel(
                    (d * (v1[0] + 1) - 1 + i, d * (v1[1] + 1) - 1 + j), color)
    s = {(x, y)}
    q = [(x, y)]
    while q:
        v1 = q.pop(0)
        for v2 in g.dict[v1]:
            if v2 not in s:
                for i in range(1 + r, d - r):
                    data.putpixel(
                        (d * (v1[0] + 1) - 1 + (v2[0] - v1[0]) * i, d *
                         (v1[1] + 1) - 1 + (v2[1] - v1[1]) * i), color2)
                q.append(v2)
                s.add(v2)
                if gif:
                    images.append(data.save("", False))
    if filename is None:
        filename = "gst " + str((length, height)) + " " + str(int(time()))
    ret = data.save(filename, save)
    if gif:
        writegif(filename, images, 0.01)
    return ret
Esempio n. 14
0
def color3d(f,
            vw=ViewWindow(),
            base=1.0,
            pos=Color(255, 0, 0),
            neg=Color(0, 0, 255),
            filename="color3d" + str(int(time())),
            save=True):
    data = PlotData(vw)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            (x, y) = vw.px2cart((i, j))
            color = Color()
            val = f((x, y))
            if val > 0:
                color = abs(val / base) * pos
            if val < 0:
                color = abs(val / base) * neg
            data.putpixel((i, j), color)
    return data.save(filename, save)
Esempio n. 15
0
def polarshade(r1, r2, vw=ViewWindow(), color=None, auto=False, filename="polarshade" + str(int(time())), save=True):
    if auto:
        vw.autoparam([lambda t0: r1(t0) * cos(t0), lambda t0: r2(t0) * cos(t0)],
                     [lambda t0: r1(t0) * sin(t0), lambda t0: r2(t0) * sin(t0)])
    data = PlotData(vw)
    th = vw.thick * (vw.xmax - vw.xmin) / vw.dimx
    if color is None:
        c = Color(255, 0, 0)
    else:
        c = color
    for i in range(vw.dimx):
        x = vw.xpxcart(i)
        for j in range(vw.dimy):
            y = vw.ypxcart(j)
            t = atan2(y, x)
            r = sqrt(x ** 2 + y ** 2)
            if color == 'rainbow':
                c = Color.rbow(t)
            if r1(t) - th <= r <= r2(t) + th or r2(t) - th <= r <= r1(t) + th:
                data.putpixel((i, j), c)
    return data.save(filename, save)
Esempio n. 16
0
def voronoi(rootlist,
            colorlist=None,
            vw=ViewWindow(),
            dots=True,
            metric=lp(2),
            select=1,
            filename="voronoi" + str(int(time())),
            save=True):
    if colorlist is None:
        colorlist = Color.colors(len(rootlist))
    data = PlotData(vw)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            data.putpixel((i, j),
                          colorlist[closest(rootlist,
                                            vw.xpxcart(i) + vw.ypxcart(j) * 1j,
                                            metric, select)])
    if dots:
        for r in rootlist:
            data.putpoint((r.real, r.imag), 0)
    return data.save(filename, save)
Esempio n. 17
0
def basin2(f, rootlist, colorlist=None, vw=ViewWindow(), df=None, n=10, dots=True,
           filename="basin2" + str(int(time())), dist=0.3, save=True):
    if df is None:
        df = diffquo(f, .0001)
    if colorlist is None:
        colorlist = Color.colors(len(rootlist))
    data = PlotData(vw)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            z = vw.xpxcart(i) + vw.ypxcart(j) * 1j
            for k in range(n):
                z = newton(f, z, df, 1)
                index = closest(rootlist, z)
                d = abs(z - rootlist[index])
                if d < dist or k == n - 1:
                    data.putpixel((i, j), max(.2, 1 - float(k) / n) * colorlist[index])
                    break
    if dots:
        for r in rootlist:
            data.putpoint((r.real, r.imag), 0)
    return data.save(filename, save)
Esempio n. 18
0
def gridspanningtree2(length, height, d=2, r=0, g="grid", color=Color(255, 0, 0), filename=None, treefunc=None, func="dfs",
                      gif=False,
                      save=True):
    images = []
    if not isinstance(g, Graph):
        g = getattr(Graph, g)(length, height)
    if treefunc is not None:
        (x, y) = (randint(0, length - 1), randint(0, height - 1))
        g = g.treefunc(treefunc, (x, y))
    (x, y) = (randint(0, length - 1), randint(0, height - 1))
    g = g.func(func, (x, y))
    vw = ViewWindow(dimx=d * length + d - 1, dimy=d * height + d - 1)
    data = PlotData(vw)
    color2 = 0.8 * color
    for p in g:
        try:
            for i in range(-r, r + 1):
                for j in range(-r, r + 1):
                    data.putpixel((d * (p[0] + 1) - 1 + i, d * (p[1] + 1) - 1 + j), color)
        except TypeError:
            for i in range(-r, r + 1):
                for j in range(-r, r + 1):
                    data.putpixel((d * (p[1][0] + 1) - 1 + i, d * (p[1][1] + 1) - 1 + j), color)
            for i in range(1 + r, d - r):
                data.putpixel(
                    (d * (p[0][0] + 1) - 1 + (p[1][0] - p[0][0]) * i, d * (p[0][1] + 1) - 1 + (p[1][1] - p[0][1]) * i),
                    color2)
        if gif:
            images.append(data.save("", False))
    if filename is None:
        filename = "gst2 " + str((length, height)) + " " + str(time())
    ret = data.save(filename, save)
    if gif:
        writegif(filename, images, 0.01)
    return ret
Esempio n. 19
0
def implicit(flist,
             vw=ViewWindow(),
             decay=100,
             colorlist=None,
             filename="implicit" + str(int(time())),
             save=True):
    data = PlotData(vw)
    color = 0
    if colorlist is None:
        colorlist = Color.colors(len(flist))
    for k in range(len(flist)):
        f = flist[k]
        if colorlist != "rainbow":
            color = colorlist[k]
        for i in range(vw.dimx):
            for j in range(vw.dimy):
                if colorlist == "rainbow":
                    color = Color.rbow(vw.xpxcart(i) + vw.ypxcart(j), 2)
                color0 = e**(-decay * abs(f(*vw.px2cart((i, j))))) * color
                color0 += data[(i, j)]
                data.putpixel((i, j), color0)
    return data.save(filename, save)
Esempio n. 20
0
def newtondiff(f,
               vw=ViewWindow(),
               df=None,
               n=1,
               pxdist=1,
               filename="newtondiff" + str(int(time())),
               save=True):
    if df is None:
        df = diffquo(f, .0001)
    data = PlotData(vw)
    color1 = Color(0, 255, 0)
    color2 = Color(255, 0, 0)
    for i in range(vw.dimx):
        for j in range(vw.dimy):
            if i % pxdist == 0 and j % pxdist == 0:
                z0 = vw.xpxcart(i) + vw.ypxcart(j) * 1j
                z = newton(f, z0, df, n, 1e-1)
                if abs(z) < abs(z0):
                    color = color1
                else:
                    color = color2
                data.putpixel((i, j), color)
    return data.save(filename, save)
Esempio n. 21
0
def julia(f,
          vw,
          n=50,
          zmax=2,
          color=Color(255, 0, 0),
          filename=None,
          save=True):
    data = PlotData(vw)
    if callable(color):
        colorfunc = color
    else:
        colorfunc = lambda t: t * color
    for p in vw.pxiterator():
        z = vw.xpxcart(p[0]) + vw.ypxcart(p[1]) * 1j
        i = 0
        while abs(z) < zmax and i < n:
            z = f(z)
            i += 1
        data.putpixel(p, colorfunc(float(i) / n), flip=False)
        if PYGAME_PIXEL and p[0] == 0:
            pygame.display.flip()
    if filename is None:
        filename = "julia " + str(n) + " " + str(zmax) + " " + str(int(time()))
    return data.save(filename, save)
Esempio n. 22
0
def mandelbrot(vw=ViewWindow(xmin=-2.3,
                             xmax=0.7,
                             ymin=-1.5,
                             ymax=1.5,
                             dimx=700,
                             dimy=701),
               n=50,
               reflect=True,
               color=Color(255, 0, 0),
               filename=None,
               save=True):
    data = PlotData(vw)
    color0 = color
    if callable(color):
        colorfunc = color
    else:
        colorfunc = lambda t: t * color0
    for p in vw.pxiterator():
        c = vw.xpxcart(p[0]) + vw.ypxcart(p[1]) * 1j
        if c.imag > -0.1 or not reflect:
            i, z0 = 0, 0
            q = (c.real - 0.25)**2 + c.imag**2
            if q * (q + (c.real - 0.25)) < c.imag**2 / 4 or 16 * (
                (c.real + 1)**2 + c.imag**2) < 1:
                data.putpixel(p, colorfunc(1.0), flip=False)
                if reflect:
                    data.putpixel((p[0], vw.ycartpx(-c.imag)),
                                  colorfunc(1.0),
                                  flip=False)
            else:
                while abs(z0) < 2 and i < n:
                    z0 = z0 * z0 + c
                    i += 1
                data.putpixel(p, colorfunc(float(i) / n), flip=False)
                if reflect:
                    data.putpixel((p[0], vw.ycartpx(-c.imag)),
                                  colorfunc(float(i) / n),
                                  flip=False)
        else:
            break
        if PYGAME_PIXEL and p[0] == 0:
            pygame.display.flip()
    if filename is None:
        filename = "mandelbrot " + str(n) + " " + str(int(time()))
    return data.save(filename, save)
Esempio n. 23
0
def gridspanningtree2(length,
                      height,
                      d=2,
                      r=0,
                      g="grid",
                      color=Color(255, 0, 0),
                      filename=None,
                      treefunc=None,
                      func="dfs",
                      gif=False,
                      save=True):
    images = []
    if not isinstance(g, Graph):
        g = getattr(Graph, g)(length, height)
    if treefunc is not None:
        (x, y) = (randint(0, length - 1), randint(0, height - 1))
        g = g.treefunc(treefunc, (x, y))
    (x, y) = (randint(0, length - 1), randint(0, height - 1))
    g = g.func(func, (x, y))
    vw = ViewWindow(dimx=d * length + d - 1, dimy=d * height + d - 1)
    data = PlotData(vw)
    color2 = 0.8 * color
    for p in g:
        try:
            for i in range(-r, r + 1):
                for j in range(-r, r + 1):
                    data.putpixel(
                        (d * (p[0] + 1) - 1 + i, d * (p[1] + 1) - 1 + j),
                        color)
        except TypeError:
            for i in range(-r, r + 1):
                for j in range(-r, r + 1):
                    data.putpixel(
                        (d * (p[1][0] + 1) - 1 + i, d * (p[1][1] + 1) - 1 + j),
                        color)
            for i in range(1 + r, d - r):
                data.putpixel(
                    (d * (p[0][0] + 1) - 1 + (p[1][0] - p[0][0]) * i, d *
                     (p[0][1] + 1) - 1 + (p[1][1] - p[0][1]) * i), color2)
        if gif:
            images.append(data.save("", False))
    if filename is None:
        filename = "gst2 " + str((length, height)) + " " + str(time())
    ret = data.save(filename, save)
    if gif:
        writegif(filename, images, 0.01)
    return ret
Esempio n. 24
0
def graphpict(length,
              height,
              graphtype="grid",
              treefunc="dfs",
              func="bfs",
              colorfunc="hilbert",
              gif=False,
              gifres=None,
              v0=None,
              v1=None,
              rand=True,
              save=True,
              scales=None):
    images = []
    clist = []
    if isinstance(graphtype, Graph):
        area = len(graphtype.dict)
    else:
        area = length * height
    if not colorfunc.startswith("rbow"):
        clist = colorcube(colorfunc)
    if func == "hilbert":
        l = hilbert(int(ceil(log(max(length, height), 2))))
        gstr = "None"
    else:
        if not isinstance(graphtype, Graph):
            gstr = graphtype
            graphtype = getattr(Graph, graphtype)(length, height)
        else:
            gstr = "Graph"
        if v0 is None:
            v0 = choice(graphtype.dict.keys())
        if treefunc is not None:
            if v1 is None:
                v1 = choice(graphtype.dict.keys())
            graphtype = graphtype.treefunc(treefunc, v1, rand)
            print "Computed spanning tree"
        l = graphtype.func(func, v0, rand)
    if gif and gifres is None:
        gifres = ceil(area / 150.0)
    vw = ViewWindow(dimx=length, dimy=height)
    data = PlotData(vw, scales=scales)
    i = 0
    for p in l:
        if colorfunc.startswith("rbow"):
            data.putpixel(p, getattr(Color, colorfunc)(2 * pi * i / area, 1))
        else:
            data.putpixel(
                p,
                Color(
                    *[c * 4 for c in clist[min(64**3 * i / area, 64**3 - 1)]]))
        if gif and (i + 1) % gifres == 0:
            images.append(data.save("", False))
        i += 1
    filename = str((length, height)) + " " + gstr + " spanningtree" + str(
        treefunc) + " " + func + " " + colorfunc + " " + str(rand) + " " + str(
            (v0, v1)) + " " + str(int(time()))
    ret = data.save(filename, save)
    if gif:
        writegif(filename, images, 0.001)
    return ret