Example #1
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)
Example #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)
Example #3
0
def complexroots(deg, vw, color=Color(5, 0, 0), coeffs=(-1, 1), filename=None, save=True):
    if np is None:
        raise Exception()
    data = PlotData(vw)
    for i, l in enumerate(product(coeffs, repeat=deg + 1)):
        if i % len(coeffs) ** (deg - 4) == 0:
            print float(i) / 2 ** (deg + 1)
        for root in np.roots(l):
            data.putpoint((root.real, root.imag), color, True)
    if filename is None:
        filename = "complexroots " + str(deg) + " " + str(int(time()))
    return data.save(filename, save)
Example #4
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)
Example #5
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)
Example #6
0
def complexroots(deg,
                 vw,
                 color=Color(5, 0, 0),
                 coeffs=(-1, 1),
                 filename=None,
                 save=True):
    if np is None:
        raise Exception()
    data = PlotData(vw)
    for i, l in enumerate(product(coeffs, repeat=deg + 1)):
        if i % len(coeffs)**(deg - 4) == 0:
            print float(i) / 2**(deg + 1)
        for root in np.roots(l):
            data.putpoint((root.real, root.imag), color, True)
    if filename is None:
        filename = "complexroots " + str(deg) + " " + str(int(time()))
    return data.save(filename, save)
Example #7
0
def newtondist(f, vw=ViewWindow(), df=None, n=1, pxdist=1, filename="newtondist" + str(int(time()))):
    images = []
    if df is None:
        df = diffquo(f, .0001)
    col = Color.colors(vw.dimx * vw.dimy)
    for k in range(6):
        data = PlotData(vw)
        for i in range(vw.dimx):
            for j in range(vw.dimy):
                if i % pxdist == 0 and j % pxdist == 0:
                    z0 = vw.xpxcart(i) + 1j * vw.ypxcart(j)
                    z = newton(f, z0, df, n, 1e-1)
                    z0 = newton(f, z0, df, n - 1, 1e-1)
                    data.putpoint(((k * z.real + (5 - k) * z0.real) / 5, (k * z.imag + (5 - k) * z0.imag) / 5),
                                  col[i + j * vw.dimx])
        images.append(data.save("", False))
    writegif(filename, images, 1)
    return images[-1]
Example #8
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)
Example #9
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)
Example #10
0
def newtondist(f,
               vw=ViewWindow(),
               df=None,
               n=1,
               pxdist=1,
               filename="newtondist" + str(int(time()))):
    images = []
    if df is None:
        df = diffquo(f, .0001)
    col = Color.colors(vw.dimx * vw.dimy)
    for k in range(6):
        data = PlotData(vw)
        for i in range(vw.dimx):
            for j in range(vw.dimy):
                if i % pxdist == 0 and j % pxdist == 0:
                    z0 = vw.xpxcart(i) + 1j * vw.ypxcart(j)
                    z = newton(f, z0, df, n, 1e-1)
                    z0 = newton(f, z0, df, n - 1, 1e-1)
                    data.putpoint(((k * z.real + (5 - k) * z0.real) / 5,
                                   (k * z.imag + (5 - k) * z0.imag) / 5),
                                  col[i + j * vw.dimx])
        images.append(data.save("", False))
    writegif(filename, images, 1)
    return images[-1]