def drawPoints(points, title, clr='green'):

    draw = Turtle(title, background=True)
    if isinstance(points[0], PointGroup):
        for pointGroup in points:
            draw.connectPoints(pointGroup.points)
    else:
        for point in points:
            draw.addPoint((500*point[0] + 200, 500*point[1] + 200), clr)
    draw.dumpImage()
Example #2
0
def drawPoints(points, title, clr='green'):

    draw = Turtle(title, background=True)
    if isinstance(points[0], PointGroup):
        for pointGroup in points:
            draw.connectPoints(pointGroup.points)
    else:
        for point in points:
            draw.addPoint((500 * point[0] + 200, 500 * point[1] + 200), clr)
    draw.dumpImage()
Example #3
0
def plotMaze(grid, d=20, name="SquareMaze"):

    dirs = ((1, 1+1j), (1j, 1+1j), (0, 1j), (0, 1))
    draw = Turtle(name, background=True)
    for square in grid:
        walls = grid[square]
        for i, dir_ in enumerate(dirs):
            if walls[1j**i]:
                draw.addLine((square + dir_[0])*d, (square + dir_[1])*d)

    draw.dumpImage()
def applyTransformDraw(points, transform, rec):

    draw = Turtle("Square", start_coord=[100,100])
    l    = len(points)
    draw.connectPoints(points)

    for _ in xrange(rec):
        for i in xrange(l):
            points[i] = dot(transform, points[i])
        draw.connectPoints(points)
    draw.dumpImage()
Example #5
0
def applyTransformDraw(points, transform, rec):

    draw = Turtle("Square", start_coord=[100, 100])
    l = len(points)
    draw.connectPoints(points)

    for _ in xrange(rec):
        for i in xrange(l):
            points[i] = dot(transform, points[i])
        draw.connectPoints(points)
    draw.dumpImage()
Example #6
0
def triangulateRandom(n, uniform=True):

    if uniform:
        points = np.random.uniform(0,500,[n,2])
        draw   = Turtle("triangulation_uniform_points")
    else:
        mean, sigma = 200, 70
        points = np.random.normal(mean,sigma,[n,2])
        draw   = Turtle("triangulation_normal_points")

    for edge in triangulation(points):
        draw.addLineNumpy(edge.array[0,:], edge.array[1,:])
    draw.dumpImage()
def triangulateRandom(n, uniform=True):

    if uniform:
        points = np.random.uniform(0, 500, [n, 2])
        draw = Turtle("triangulation_uniform_points")
    else:
        mean, sigma = 200, 70
        points = np.random.normal(mean, sigma, [n, 2])
        draw = Turtle("triangulation_normal_points")

    for edge in triangulation(points):
        draw.addLineNumpy(edge.array[0, :], edge.array[1, :])
    draw.dumpImage()
Example #8
0
def star():

    step  = 20
    side  = 250
    shift = side + 1j*side
    draw  = Turtle("star")

    for x, y in product([1, -1], [1, -1]):
        for i in xrange(0, side + 1, step):
            a = x*i             + shift
            b = y*1j*(side - i) + shift
            draw.addLine(a, b)

    draw.dumpImage()
def wrapRandomGift(n, uniform=True):

    if uniform:
        draw   = Turtle("Gift_Wrapping_uniform")
        points = list(np.random.uniform(0,500,[n,2]))
    else:
        draw   = Turtle("Gift_Wrapping_normal")
        mean, sigma = 200, 70
        points = list(np.random.normal(mean,sigma,[n,2]))

    for point in points:
        draw.addPoint(point)

    while len(points) >= 3:
        wraping = wrapGift(points)
        wr_len  = len(wraping)
        for i in xrange(wr_len):
            draw.addLineNumpy(wraping[i], wraping[(i+1) % wr_len])

    draw.dumpImage()
Example #10
0
def randomSegments(n, l=150):

    points = np.random.uniform(0, 300, [n, 2])
    vector = np.array([[l, 0]])
    pairs = []
    for i in xrange(n):
        A = points[i, :]
        while True:
            B = A + randomVector(l)
            if B[0, 0] >= 0 and B[0, 1] >= 0:  # is it within first quadrant?
                pairs.append(np.row_stack((A, B)))
                break
    return pairs


if __name__ == '__main__':

    draw = Turtle("Intersection")
    segments = randomSegments(15)

    for i, seg1 in enumerate(segments):
        for seg2 in segments[i + 1:]:
            intersect = segmentIntersect(seg1, seg2)
            if intersect != None:
                draw.addPoint(intersect)

    for seg in segments:
        draw.addLineNumpy(seg[0], seg[1])

    draw.dumpImage()
Example #11
0
            V = V - norm

            if V_tmp == vortex:
                vortex_new = V
            e_tmp.append(V)

        new_edges.append(e_tmp)
    return new_edges, vortex_new


if __name__ == "__main__":


    draw = Turtle("Tree", [5, 80])
    tree(draw, 10, 100.)
    draw.dumpImage()

    draw = Turtle("Koch_Flake", [15, 80])
    kochFlake(draw, 5, 100)
    draw.dumpImage()

    draw = Turtle("Sierpinski_Triangle")
    sierpinskiTriangle(draw, 7, 200)
    draw.dumpImage()

    draw = Turtle("Hilbert_Curve",[5, 5])
    hilbertCurve(draw, 7, 300)
    draw.dumpImage()

    draw = Turtle("Krishna_Anklet", [150, 5])
    krishnaAnklet(draw, 5, 200)