Example #1
0
def make_one(shift=[0., 0.]):
    """    original   """
    # startPoints = list(range(3))
    # for i in startPoints:
    #     x = 2.5*cos(2.0 * pi * i / 3)
    #     y = 2.5*sin(2.0 * pi * i / 3)
    #     startPoints[i] = [x, y]
    """    anomalus    """
    # startPoints = [[-2, 2], [0, 0], [2, 2]]
    """    earhoops    """
    # startPoints = [[-1, -2], [0, 1], [1, -2]]
    """    random    """
    # startPoints = (np.random.rand(3, 2) * 4. - 2.).tolist()
    """    random angles    """

    # startPoints = [[np.cos(2. * np.pi * t), np.sin(2. * np.pi * t)] for t in np.random.rand(3)]

    # all circles are defined as c = [r, px, py] with
    # radius = c[0] and x, y coordinates of the center
    # c[1] and c[2] (latter adding c[3] to make a 3d
    # gasket with spheres)

    def rand_init():
        points = np.random.rand(3, 2) - .5
        return points.tolist()

    def circulate(c0, c1, c2, c3, depth):
        cList = [c0, c1, c2]

        if depth == 0:
            return [c3]
        else:
            new = []
            for indxs in itertools.combinations(range(3), 2):
                i0, i1 = indxs
                cI, cO = circit(cList[i0], cList[i1], c3)

                if cList[i0][0] * cList[i1][0] * c3[0] > 0:
                    cNew = cI
                else:
                    cNew = cO

                new += circulate(cList[i0], cList[i1], c3, cNew, depth - 1)
            return [c3] + new

    def sign(p1, p2, p3):
        return (p1[1] - p3[1]) * (p2[2] - p3[2]) - (p2[1] - p3[1]) * (p1[2] -
                                                                      p3[2])

    def PointInTriangle(pt, v1, v2, v3):
        b1 = sign(pt, v1, v2) < 0.
        b2 = sign(pt, v2, v3) < 0.
        b3 = sign(pt, v3, v1) < 0.
        return ((b1 == b2) and (b2 == b3))

    loops = 4

    good3 = False
    while not good3:
        startPoints = rand_init()
        [c0, c1, c2] = radii(*startPoints)
        c3, c4 = circit(c0, c1, c2)
        if c4[0] > 0: continue
        if not PointInTriangle(c4, c1, c2, c3): continue
        good3 = True

    clot = [c0, c1, c2] + circulate(c0, c1, c2, c4, loops) + circulate(
        c0, c1, c2, c3, loops)

    biggestR = max(abs(np.array(clot)[:, 0]))
    scale = 1.4 / biggestR
    annuli = []
    for c in clot:
        r, x, y = c
        if abs(r) < 0.05: continue
        annuli.append(
            makeShapelyCircle(scale * (x - c4[1]) + (shift[0] - 1) * 3,
                              scale * (y - c4[2]) + (shift[1] - 1) * 3,
                              scale * abs(r),
                              thickness=0.05))

    testUnion = cascaded_union(annuli)
    return testUnion
Example #2
0
            i0, i1 = indxs
            cI, cO = circit(cList[i0], cList[i1], c3)

            if cList[i0][0] * cList[i1][0] * c3[0] > 0:
                cNew = cI
            else:
                cNew = cO

            result = circulate(cList[i0], cList[i1], c3, cNew, depth - 1)
            new += result
        return [c3] + new


loops = 8

[c0, c1, c2] = radii(*startPoints)
c3, c4 = circit(c0, c1, c2)

clot = [c0, c1, c2] + circulate(c0, c1, c2, c4, loops) + circulate(c0, c1, c2, c3, loops)

w = 512
h = 512

# Make a pdf surface
surf = cairo.PDFSurface(open("test.pdf", "w"), w, h)
# Make a svg surface
# surf =  cairo.SVGSurface(open("test.svg", "w"), w, h)

# Get a context object
ctx = cairo.Context(surf)
Example #3
0
for i in range(3):
    x = 2.5*cos(2.0 * pi * i / 3)
    y = 2.5*sin(2.0 * pi * i / 3)
    startPointList.append((x,y))

# """
# anomalus
# """
# startPointList = [(-2, 2), (0, 0), (2, 2)]

# """
# earhoops
# """
# startPointList = [(-1, 12), (0, 7), (1, 12)]

startRadiiList = list(radii(*tuple(startPointList)))

def circulate(p0, r0, p1, r1, p2, r2, p3, r3, depth):
    pointList = [p0, p1, p2]
    radiiList = [r0, r1, r2]  

    if depth == 0:
        return [p3], [r3]
    else:
        newPL = []
        newRL = []
        for indxs in itertools.combinations(range(3), 2):
            i0, i1 = indxs
            pI, rI, pO, rO = circit(pointList[i0], radiiList[i0], 
                                    pointList[i1], radiiList[i1],
                                    p3, r3)
Example #4
0
# """
# startPointList = []
# for i in range(3):
#     x = 2.5*cos(2.0 * pi * i / 3)
#     y = 2.5*sin(2.0 * pi * i / 3)

#     startPointList.append((x,y))

# """
# anomalus
# """
# startPointList = [(-2, 2), (0, 0), (2, 2)]

startPointList = [[-1, -2], [0, 1], [1, -2]]
 
c0, c1, c2 = list(radii(*tuple(startPointList)))

# next: rewrite all with circles def as c = [r, px, py]
# rad = c[0] and coordinates of the center c[1] and c[2]
# latter adding c[3] to make a 3d gasket with spheres

def circulate(c0, c1, c2, depth):
    cList = [c0, c1, c2]

    if depth == 0:
        return c3

    new = []
    for circleA, circleB in itertools.combinations(cList, 2):
        cInner, cOuter = circit(circleA, circleB, c2)