Example #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")