Example #1
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Smile")
    t = turtle_helper.make_turtle("black", 1, 150, 0)

    # лицо
    t.color('black', 'yellow')
    t.begin_fill()
    turtle_helper.draw_circle(t, 150, 90)
    t.end_fill()

    # глаза
    t.color('black', 'blue')
    turtle_helper.move(t, 85, 75)
    t.begin_fill()
    turtle_helper.draw_circle(t, 20, 90)
    t.end_fill()
    turtle_helper.move(t, -45, 75)
    t.begin_fill()
    turtle_helper.draw_circle(t, 20, 90)
    t.end_fill()

    # нос
    t.pensize(10)
    turtle_helper.move(t, 0, -20)
    t.color('black')
    t.forward(40)

    # рот
    turtle_helper.move(t, 80, -35)
    t.color('red')
    turtle_helper.draw_arc(t, 80, 270, 180, False)

    wn.mainloop()
Example #2
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Letter S")
    t = turtle_helper.make_turtle("red", 2, shape="classic")
    turtle_helper.move(t, -350, 0)
    print_index_style(t, "02123475297516589", 30)

    wn.mainloop()
Example #3
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Spider")
    t = turtle_helper.make_turtle("red", 2)

    x_start, y_start = 200, 0
    radius = 100
    n = 3
    side = polygon_side_by_radius(radius, 3)
    start_angle = 90 - 180 / n

    turtle_helper.move(t, x_start, y_start)
    draw_polygon(t, n, side, start_angle)

    old_radius = radius

    while n <= 10:
        n += 1
        radius = old_radius / math.cos(math.pi / n)
        dist = radius - old_radius
        turtle_helper.move(t, t.xcor() + dist, t.ycor())
        start_angle = 90 - 180 / n
        side = polygon_side_by_radius(radius, n)
        draw_polygon(t, n, side, start_angle)

        old_radius = radius

    wn.mainloop()
Example #4
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Square")
    t = turtle_helper.make_turtle("red", 2)
    size = 100

    for i in range(4):
        t.forward(size)
        t.left(90)

    wn.mainloop()
Example #5
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Letter S")
    t = turtle_helper.make_turtle("red", 2, shape="classic")
    turtle_helper.move(t, -350, 0)

    font_file = "index_like_font.csv"
    font = read_font.read_font(font_file)
    # print_with_font(t, font, "02123475297516589", 30)
    print_with_font(t, font, "0123456789", 30)

    wn.mainloop()
Example #6
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Spring")
    t = turtle_helper.make_turtle("red", 2, -350, 0)

    for i in range(4):
        turtle_helper.draw_arc(t, 80, 90, 180, False)
        turtle_helper.draw_arc(t, 15, 270, 180, False)

    turtle_helper.draw_arc(t, 80, 90, 180, False)

    wn.mainloop()
Example #7
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Flower")
    t = turtle_helper.make_turtle("red", 2)

    radius = 100

    # Используем собственную функцию draw_circle
    for angle in range(0, 360, 45):
        turtle_helper.draw_circle(t, radius, angle)

    wn.mainloop()
Example #8
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Stars")

    t = turtle_helper.make_turtle("red", 2, -250, 250)
    draw_star(t, 5, 2, 230, 18 - 90)

    turtle_helper.move(t, 120, -120)
    t.color("blue")

    draw_star(t, 11, 4, 230, 0)

    wn.mainloop()
Example #9
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Quadratic spiral")
    t = turtle_helper.make_turtle("red", 2)

    segment = 10
    step = 5

    for i in range(60):
        t.forward(segment)
        t.left(90)
        segment += step

    wn.mainloop()
Example #10
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Letter S")
    t = turtle_helper.make_turtle("red", 2)

    max_step_len = 25
    steps_qty = 100

    for i in range(steps_qty):
        t.forward(int(max_step_len * random.random()))
        to_left = 1 if random.random() < 0.5 else -1
        t.left(to_left * int(180 * random.random()))


    wn.mainloop()
Example #11
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Butterfly")
    t = turtle_helper.make_turtle("red", 2)

    radius = 60
    step = 10

    # Используем собственную функцию draw_circle
    for i in range(10):
        radius += step
        turtle_helper.draw_circle(t, radius, 90)
        turtle_helper.draw_circle(t, radius, 90, counterclockwise=False)

    wn.mainloop()
Example #12
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Letter S")
    t = turtle_helper.make_turtle("red", 2)
    size = 100

    for i in range(2):
        t.forward(size)
        t.left(90)

    for i in range(3):
        t.forward(size)
        t.right(90)

    wn.mainloop()
Example #13
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Circle")
    t = turtle_helper.make_turtle("red", 2, -70, -130)

    SIDES_QTY = 35
    DIAM = 300

    side = round(math.pi * DIAM / SIDES_QTY)
    angle = 360 / SIDES_QTY

    for i in range(SIDES_QTY):
        t.forward(side)
        t.left(angle)

    wn.mainloop()
Example #14
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Archimedean spiral")
    t = turtle_helper.make_turtle("red", 2)

    max_angle = 15 * 360
    step = 5
    k = 3

    for phi in range(0, max_angle, step):
        angle = degree_to_rad(phi)
        x = k * angle * math.cos(angle)
        y = k * angle * math.sin(angle)
        t.goto(x, y)

    wn.mainloop()
Example #15
0
def main():
    wn = turtle_helper.make_window("lightgreen", "More squares")
    t = turtle_helper.make_turtle("red", 2, -50, -100)

    SQUARES_QTY = 10

    side = 40
    side_shift = 15

    x, y = -100, -50
    for i in range(SQUARES_QTY):
        paint_square(t, side, x, y)
        side += 2 * side_shift
        x -= side_shift
        y -= side_shift

    wn.mainloop()
Example #16
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Flower")
    t = turtle_helper.make_turtle("red", 2)

    # Используем стандартный метод circle
    side = 100
    t.circle(100)
    t.circle(-100)
    t.left(90)
    t.circle(100)
    t.circle(-100)
    t.left(45)
    t.circle(100)
    t.circle(-100)
    t.right(90)
    t.circle(100)
    t.circle(-100)

    wn.mainloop()
Example #17
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Spider")
    t = turtle_helper.make_turtle("red", 2)

    ARMS_QTY = 13

    length = 200
    angle = 360 / ARMS_QTY

    x, y = -100, -50
    for i in range(ARMS_QTY):
        t.forward(length)
        t.stamp()
        t.left(180)
        t.forward(length)
        t.left(180)
        t.left(angle)

    wn.mainloop()
Example #18
0
def main():
    wn = turtle_helper.make_window("lightgreen", "Many turtles")

    # Исходные данные
    x_min, x_max = -wn.window_width() // 2, wn.window_width() // 2
    y_min, y_max = -wn.window_height() // 2, wn.window_height() // 2
    number_of_turtles = 10
    steps_of_time_number = 100

    # Создаем частицы
    pool = [
        turtle_helper.make_turtle("blue", 3, random.randint(x_min, x_max),
                                  random.randint(y_min, y_max), "circle")
        for i in range(number_of_turtles)
    ]

    for i in range(steps_of_time_number):
        for unit in pool:
            unit.forward(2)

    wn.mainloop()
Example #19
0
def main():
    # Инициализация графики
    BACKGROUND_COLOR = "lightblue"
    WIDTH, HEIGHT = 1200, 900
    wn = turtle_helper.make_window(BACKGROUND_COLOR, "Cannon shooting", WIDTH,
                                   HEIGHT)
    turtle = turtle_helper.make_turtle("blue", 0, 0, shape="circle")
    turtle.speed(9)
    turtle_helper.draw_line(0, 0, 1000, 0, "brown", 2, "arrow")

    text_output_pos = (3 / 5) * WIDTH, (4 / 5) * HEIGHT  # не пригодилось

    # Инициализация механики
    v0, alpha = 100, 80  # Эталон: v0, alpha = 100, 80
    p = vector.Vector(0, 0)
    v = vector.Vector(v0 * math.cos(math.radians(alpha)),
                      v0 * math.sin(math.radians(alpha)))
    a = vector.Vector(0, -10)
    floor_vector = vector.Vector(1, 0)
    dissipation_quot = 0.4

    def is_collision(ball):
        _, y = ball.get_pos().coords()
        _, vy = ball.get_vel().coords()
        return y <= 0.1 and vy < 0

    def correct_pos(ball):
        ball.set_pos(vector.Vector(x, 0.000))

    def potential_energy(ball):
        x, y = ball.get_pos().coords()
        return 10 * y * ball.get_mass()

    ball = particle.Particle(p, v, a, potential_energy)

    t, moves, fps = 0, 0, 10
    dt = 1 / fps

    while (True):
        x, y = ball.get_pos().coords()
        # нужно задать некие разумные условия для остановки
        # они (первая часть - energy) зависят от fps, вернее от dt:
        # ниже fps - тем грубее расчеты - тем выше пороговое значение energy
        # и связаны с особенностями моделирования - с дискретностью расчетов
        if (energy := ball.get_energy()) < 20 and y <= 0:
            break

        # Выводим информацию о движении на косноль
        print("time:{:.1f}   (pos, vel, acc) = ".format(t), end="")
        ball.print_сinematics_info()
        ball.print_energy_info()
        print()

        # Выводим информацию о движении на экран
        ##        if moves % fps == 0:
        ##            print(moves)
        ##            textlines = ["Time: {:.1f}".format(t)]
        ##            turtle_helper.print_text(*text_output_pos, textlines)
        ##        Честно пытался сделать вывод о текущем информации о движении на экран
        ##        но здесь, в Turtle Graphics, это оказывается крайне неудобным -
        ##        вывод текстовой информации занимает слишком много времени и это
        ##        нарушает отрисовку основного движения, - в общем fail

        ball.move(dt)
        moves += 1
        turtle.goto(x, y)
        if is_collision(ball):
            print("COLLISION")
            ball.collide_surface(floor_vector, correct_pos, dissipation_quot)

        t += dt
Example #20
0
def main():
    # Инициализация графики
    BACKGROUND_COLOR = "lightblue"
    WIDTH, HEIGHT = 1000, 850
    wn = turtle_helper.make_window(BACKGROUND_COLOR, "Chaos", WIDTH, HEIGHT)
    margin = 8
    width, height = WIDTH - margin, HEIGHT - margin

    # границы объема
    turtle_helper.draw_rectangle(0, 0, width, height, "brown", 2)

    # turtle_helper.move(particle, 100, 105)

    # Инициализация
    import random
    N = 25  # количество частиц
    radius = 11
    possible_vel_range = -100, 100  # диапазон (составляющих) скоростей
    molecules = []
    turtles = dict()
    for _ in range(N):  # начальная расстановка 'молекул'

        while True:  # обеспечиваем, чтобы они не липли к краям и друг к другу
            x = random.randrange(int(radius * 1.5), int(width - radius * 1.5))
            y = random.randrange(int(radius * 1.5), int(height - radius * 1.5))
            pos = vector.Vector(x, y)
            if not molecules: break  # первая молекла - без проверок
            if all(
                    map(lambda m: m.get_pos().dist(pos) > radius * 2.5,
                        molecules)):
                break

        v_min, v_max = possible_vel_range
        vx, vy = random.randrange(v_min, v_max), random.randrange(v_min, v_max)
        vel = vector.Vector(vx, vy)
        acc = vector.Vector(0, 0)
        molecule = sized_particle.SizedParticle(pos, vel, acc, radius)
        molecules.append(molecule)
        turtle = turtle_helper.make_turtle("blue", 1, x, y, "circle")
        turtle.penup()
        turtle.speed(50)
        turtles[molecule] = turtle

    t, moves = 0, 0
    dt = 0.025
    G = -100000

    while (True):  # начинаем движение
        moves += 1
        t += dt
        for molecule in molecules:

            F = vector.Vector.summa(
                list(
                    map(lambda mol: inverse_square_force(molecule, mol, G),
                        molecules)))

            molecule.move(dt, F)
            x, y = molecule.get_pos().coords()

            # проверка на столкновения с границами
            if (v := walls_collision(molecule, width, height)):
                molecule.collide_surface(v)

            turtles[molecule].goto(x, y)