Ejemplo n.º 1
0
def feigenbaum():
    y_range = input(
        "Zadej y rozsah oddelene - od nuly do 1. Napriklad 0.25-0.75: ").split(
            "-")
    x_range = input(
        "Zadej x rozsah oddelene - od nuly do 1. Napriklad 0.25-0.75: ").split(
            "-")
    y_range[0] = float(y_range[0])
    y_range[1] = float(y_range[1])
    x_range[0] = float(x_range[0])
    x_range[1] = float(x_range[1])
    points = int(200 * abs(1 / abs(y_range[0] - y_range[1])))
    start = 0.5
    min = 2
    max = 4
    y = start
    diference = int(200 * abs(1 / abs(y_range[0] - y_range[1])))
    zofka = SvgTurtle(0, 0)
    for x in range(min * diference, max * diference):
        x = x / diference
        for point in range(points):
            y = x * y * (1.0 - y)
            if y_range[0] < y < y_range[1] and x_range[0] < (
                    x - 2) / 2 < x_range[1]:
                zofka.set_pos(((x - 2) * 500 - x_range[0] * 1000) *
                              (1 / abs(x_range[0] - x_range[1])),
                              (y * 1000 - y_range[0] * 1000) *
                              (1 / abs(y_range[0] - y_range[1])))
                zofka.self_point()
    zofka.save("feigenbaum.svg")
def chaos_game(n, iterations, r, name, random=False):
    zofka = SvgTurtle(500, 800)
    points = n_square_points(n)
    if random:
        numbers = [x-100 for x in range(200)]
        for point in points:
            point[0] += choice(numbers)
            point[1] += choice(numbers)
    for point in range(len(points)):
        zofka.line(points[point][0], points[point][1], points[point-1][0], points[point-1][1])
    for x in range(iterations):
        point = choice(points)
        t = SvgTurtle(point[0], point[1])
        position = zofka.position()
        if position[0] > point[0]:
            posx = point[0] + abs(position[0] - point[0]) * r
        else:
            posx = position[0] + abs(position[0] - point[0]) * (1-r)
        if position[1] > point[1]:
            posy = point[1] + abs(position[1] - point[1]) * r
        else:
            posy = position[1] + abs(position[1] - point[1]) * (1-r)

        zofka.set_pos(posx, posy)
        zofka.self_point()
    zofka.save(name+".svg")
Ejemplo n.º 3
0
def MRCM(points, transformations, iterations, name):
    points = [points]
    for x in range(iterations):
        new_points = []
        for point in points:
            for tr in transformations:
                new_points.append(affine_transformation(point, **tr))
        points = new_points
    set_of_points = points
    x = 500
    y = 500
    turtle = SvgTurtle(x, y)
    for points in set_of_points:
        turtle.set_pos(points[0][0] + x, points[0][1] + y)
        for point in points + [points[0]]:
            turtle.set_pos(point[0] + x, point[1] + y, write=True)
    turtle.save(name)
Ejemplo n.º 4
0
def svg_star(lines, tops, radius, name):  # save svg file with star
    turtle = SvgTurtle(400, 400)
    angle = 180 - (1 - (2 / (lines * tops))) * 180
    distance = radius * 2 * sin(pi /
                                (lines * tops))  # needed calculations for star
    for top in range(tops):
        for x in [-1, 1]:
            turtle.set_pos(400, 400)
            turtle.left(360 / tops * top)
            turtle.forward(radius)
            turtle.left(x * 180 - x * angle / 2)
            end_of_line = SvgTurtle(400, 400)
            end_of_line.right(360 / tops * (x - top))
            for line in range(lines):
                turtle.left(x * angle)
                turtle.forward(distance)
                end_of_line.forward(radius / lines)
                turtle.connector(end_of_line)
    turtle.save(name)
Ejemplo n.º 5
0
def affine_transformation(points, iteration=1, translation=False, rotation=False, scaling=False, write=False, own=False):
    set_of_points = [points]
    for x in range(iteration):
        transformed_points = set_of_points[-1]
        if translation:
            transformed_points = ATr(transformed_points).translation(translation[0], translation[1])
        if rotation:
            transformed_points = ATr(transformed_points).rotation(rotation)
        if scaling:
            transformed_points = ATr(transformed_points).scaling(scaling[0], scaling[1])
        if own:
            transformed_points = ATr(transformed_points).own(own[0], own[1], own[2], own[3], own[4], own[5])
        set_of_points.append(transformed_points)
    if write:
        x = 500
        y = 500
        turtle = SvgTurtle(x, y)
        for points in set_of_points:
            turtle.set_pos(points[0][0] + x, points[0][1] + y)
            for point in points + [points[0]]:
                turtle.set_pos(point[0] + x, point[1] + y, write=True)
        turtle.save("picture.svg")
    else:
        return transformed_points