示例#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)
示例#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)
示例#3
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]
示例#4
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)
示例#5
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]
示例#6
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)
示例#7
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)
示例#8
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)