Esempio n. 1
0
def draw_branches_randomized(start_point, angle, length):
    if length < 3:
        return

    angle_range_left = int(0.6 * 30)
    angle_range_right = int(1.4 * 30)
    angle_random_change_left = sd.randint(angle_range_left, angle_range_right)
    angle_random_change_right = sd.randint(angle_range_left, angle_range_right)
    next_angle_left_branch = angle + angle_random_change_left
    next_angle_right_branch = angle - angle_random_change_right

    length_range_left = int(0.8 * 0.75 * length)
    length_range_right = int(1.2 * 0.75 * length)
    length_left_rand_factor = sd.randint(length_range_left, length_range_right)
    length_right_rand_factor = sd.randint(length_range_left,
                                          length_range_right)

    left_branch = sd.get_vector(start_point=start_point,
                                angle=next_angle_left_branch,
                                length=length_left_rand_factor)
    left_branch.draw()

    right_branch = sd.get_vector(start_point=start_point,
                                 angle=next_angle_right_branch,
                                 length=length_right_rand_factor)
    right_branch.draw()

    draw_branches_randomized(start_point=left_branch.end_point,
                             angle=next_angle_left_branch,
                             length=length_left_rand_factor)
    draw_branches_randomized(start_point=right_branch.end_point,
                             angle=next_angle_right_branch,
                             length=length_right_rand_factor)
Esempio n. 2
0
def snowflake_gen():
    return {
        'length': sd.random_number(8, 24),
        'x': sd.randint(10, width - 10),
        'y': height + sd.randint(100, 150),
        'factor_a': sd.random_number(4, 7) / 10,
        'factor_b': sd.random_number(4, 7) / 10,
        'factor_c': sd.random_number(45, 60)
    }
Esempio n. 3
0
def change_point(step):
    global list_snowflakes
    list_out = []
    for item in list_snowflakes:
        local = [
            int(item[0]) - sd.randint(-2, step),
            int(item[1]) + sd.randint(-2, step), item[2]
        ]
        list_out.append(local)
    list_snowflakes = list_out
Esempio n. 4
0
def draw_branches(point, angle, length):
    if length > 10:
        for angle in [
                angle - 30 * sd.randint(6, 14) / 10,
                angle + 30 * sd.randint(6, 14) / 10
        ]:
            v1 = sd.get_vector(start_point=point,
                               angle=angle,
                               length=length,
                               width=3)
            v1.draw()
            draw_branches(point=v1.end_point,
                          angle=angle,
                          length=length * 0.75 * sd.randint(8, 12) / 10)
Esempio n. 5
0
def smile(x=sd.randint(0, 1200), y=sd.randint(0, 600),
          color=sd.random_color()):
    smile_cencer = sd.get_point(x, y)
    left_bottom = sd.get_point(x - 100, y - 75)
    right_top = sd.get_point(x + 100, y + 75)
    sd.ellipse(left_bottom, right_top, width=1, color=color)
    left_eye_center = sd.get_point(x - 40, y + 25)
    sd.circle(left_eye_center, 20, color=color)
    right_eye_center = sd.get_point(x + 40, y + 25)
    sd.circle(right_eye_center, 25, color=color)
    point_1 = sd.get_point(x - 50, y - 25)
    point_2 = sd.get_point(x - 25, y - 35)
    point_3 = sd.get_point(x + 25, y - 35)
    point_4 = sd.get_point(x + 50, y - 25)
    point_list = [point_1, point_2, point_3, point_4]
    sd.lines(point_list, color=color)
Esempio n. 6
0
 def __init__(self):
     self.length = sd.random_number(10, 101)
     self.x = sd.random_number(0, sd.resolution[0])
     self.y = sd.randint(sd.resolution[1] - 100, sd.resolution[1] + 100)
     self.factor_a = sd.random_number(10, 100) / 100
     self.factor_b = sd.random_number(10, 100) / 100
     self.factor_c = sd.random_number(10, 100)
Esempio n. 7
0
 def __init__(self, x=sd.randint(0, sd.resolution[0]), y=sd.resolution[1],
              length=100, factor_a=0.6, factor_b=0.35, factor_c=60):
     self.x = x
     self.y = y
     self.length = length
     self.factor_a = factor_a
     self.factor_b = factor_b
     self.factor_c = factor_c
Esempio n. 8
0
def snowflake(x, y):
    a = 1
    while True:
        sd.clear_screen()
        for i in range(len(x)):
            point = sd.get_point(x[i],y[i])
            sd.snowflake(center=point, length=50, color='white')
            h = sd.randint(0, 20)
            y[i] -= h
            if y[i] < 50:
                break
            a = sd.randint(-1,1)

            x[i] = x[i] + h*a
        sd.sleep(0.05)
        if sd.user_want_exit():
            break
 def __init__(self):
     self.length = sd.random_number(Snowflake.size['min'],
                                    Snowflake.size['max'])
     self.x = sd.random_number(0, sd.resolution[0])
     self.y = sd.randint(sd.resolution[1] - 100, sd.resolution[1] + 100)
     self.factor_a = sd.random_number(1, 10) / 10
     self.factor_b = sd.random_number(1, 10) / 10
     self.factor_c = sd.random_number(1, 120)
Esempio n. 10
0
 def __init__(self, resolution):
     self.x = sd.randint(0, resolution[0])
     self.y = resolution[1]
     self.length = sd.randint(5, 50)
     self.delta_y = sd.randint(10, 20)
     self.delta_x = self.length // 5
     self.factor_a = sd.randint(4, 7) / 10
     self.factor_b = sd.randint(2, 5) / 10
     self.factor_c = sd.randint(40, 70)
     self.color = sd.COLOR_WHITE
     self.skip = False  # чтобы не учитывалась каждый раз как только что упавшая
Esempio n. 11
0
def draw_branches(start_point, angle, lenght, width):
    lenght *= 0.8
    if width > 1:
        width -= 1
    if lenght > 10:
        sd.vector(start_point, angle - 30, lenght, color='black', width=width)
        sd.vector(start_point, angle + 30, lenght, color='black', width=width)
        new_point_1 = sd.get_point(start_point.x + sd.cos(angle - 30) * lenght,
                                   start_point.y + sd.sin(angle - 30) * lenght)
        new_point_2 = sd.get_point(start_point.x + sd.cos(angle + 30) * lenght,
                                   start_point.y + sd.sin(angle + 30) * lenght)
        draw_branches(new_point_1, angle - sd.randint(15, 45),
                      lenght * sd.randint(90, 110) / 100, width)
        draw_branches(new_point_2, angle + sd.randint(15, 45),
                      lenght * sd.randint(90, 110) / 100, width)
    else:
        new_point_1 = sd.get_point(start_point.x + sd.cos(angle - 30) * lenght,
                                   start_point.y + sd.sin(angle - 30) * lenght)
        new_point_2 = sd.get_point(start_point.x + sd.cos(angle + 30) * lenght,
                                   start_point.y + sd.sin(angle + 30) * lenght)
        color = (sd.randint(0, 100), sd.randint(140, 250), sd.randint(10, 40))
        sd.circle(new_point_1, 5, color=color, width=0)
        sd.circle(new_point_2, 5, color=color, width=0)
Esempio n. 12
0
#  - сдвинуть снежинку
#  - отрисовать её цветом sd.COLOR_WHITE на новом месте
#  - после отрисовки всех снежинок, перед sleep(), вызвать sd.finish_drawing()

# 4) Усложненное задание (делать по желанию)
# - сделать рандомные отклонения вправо/влево при каждом шаге
# - сделать сугроб внизу экрана - если снежинка долетает до низа, оставлять её там,
#   и добавлять новую снежинку
# Результат решения см https://youtu.be/XBx0JtxHiLg


x = 0
y = 950
q = 5

all_x = [sd.randint(0, 1200) for z in range(q)]
all_y = [sd.randint(50, 500) for k in range(q)]
all_length = [sd.randint(10, 35) for n in range(q)]

y2 = 950


def snow_make(x1, y1, color):
    for i in range(q):
        sd.snowflake(center=sd.get_point(x1 + all_x[i], y1 + all_y[i]), length=all_length[i], color=color)


while True:
    sd.clear_screen()
    snow_make(x, y, color=sd.COLOR_CYAN)
    y -= 50
Esempio n. 13
0
def start_point():
    x = height + 100
    y = sd.randint(10, width - 10)
    return sd.get_point(x, y)
Esempio n. 14
0
# sd.user_want_exit()

i = 0

sd.start_drawing()
while True:
    # sd.clear_screen()
    # sd.draw_background()

    for snowflake in snowflakes:
        point = sd.get_point(snowflake['x'], snowflake['y'])
        sd.snowflake(point, snowflake['length'], sd.background_color,
                     snowflake['factor_a'], snowflake['factor_b'],
                     snowflake['factor_c'])

        snowflake['x'] -= sd.randint(-10, 10)
        snowflake['y'] -= sd.randint(10, 25)

        point = sd.get_point(snowflake['x'], snowflake['y'])
        sd.snowflake(point, snowflake['length'], sd.COLOR_WHITE,
                     snowflake['factor_a'], snowflake['factor_b'],
                     snowflake['factor_c'])
        if snowflake['y'] < sd.randint(0, 40):
            snowflakes.remove(snowflake)
    i += 1
    if i % 2 == 0:
        new_snowflake = snowflake_gen()
        snowflakes.append(snowflake_gen())

    sd.finish_drawing()
    sd.sleep(0.1)
Esempio n. 15
0
def move_snowflakes():
    for i, x in enumerate(blizzard['x']):
        draw_snowflake(sd.background_color, i)
        x += sd.randint(-100, 100)
        blizzard['y'][i] -= blizzard['delta'][i]
        draw_snowflake(sd.COLOR_WHITE, i)
Esempio n. 16
0
    points = [
        sd.get_point(x - 85, y - 65),
        sd.get_point(x - 80, y - 70),
        sd.get_point(x - 75, y - 72),
        sd.get_point(x - 65, y - 74),
        sd.get_point(x - 61, y - 74),
        sd.get_point(x - 57, y - 74),
        sd.get_point(x - 47, y - 72),
        sd.get_point(x - 42, y - 70),
        sd.get_point(x - 37, y - 65),
        sd.get_point(x - 42, y - 75),
        sd.get_point(x - 47, y - 79),
        sd.get_point(x - 50, y - 81),
        sd.get_point(x - 57, y - 82),
        sd.get_point(x - 61, y - 82),
        sd.get_point(x - 65, y - 82),
        sd.get_point(x - 72, y - 80),
        sd.get_point(x - 75, y - 78),
        sd.get_point(x - 80, y - 75),
        sd.get_point(x - 85, y - 65),
    ]

    sd.lines(points, sd.invert_color(color))


for _ in range(10):
    draw_smile(sd.randint(100, 600), sd.randint(100, 600), sd.random_color())

sd.pause()
Esempio n. 17
0
# сделать модуль snowfall.py в котором реализовать следующие функции
#  создать_снежинки(N) - создает N снежинок
#  нарисовать_снежинки_цветом(color) - отрисовывает все снежинки цветом color
#  сдвинуть_снежинки() - сдвигает снежинки на один шаг
#  номера_достигших_низа_экрана() - выдает список номеров снежинок, которые вышли за границу экрана
#  удалить_снежинки(номера) - удаляет снежинки с номерами из списка
#
# В текущем модуле реализовать главный цикл падения снежинок,
# обращаясь ТОЛЬКО к функциям модуля snowfall

# создать_снежинки(N)
sf.create_snow(20)
while True:
    sd.start_drawing()
    sf.draw_snow(sd.background_color)
    sf.change_point(sd.randint(2, 20))
    sf.draw_snow(sd.COLOR_WHITE)
    final_flake = sf.check_snow()
    if final_flake:
        sf.delete(final_flake)
        sf.create_snow(len(final_flake))
    #  нарисовать_снежинки_цветом(color=sd.background_color)
    #  сдвинуть_снежинки()
    #  нарисовать_снежинки_цветом(color)
    #  если есть номера_достигших_низа_экрана() то
    #       удалить_снежинки(номера)
    #       создать_снежинки(count)
    sd.finish_drawing()
    sd.sleep(0.1)

    if sd.user_want_exit():
Esempio n. 18
0
#     bubble(point, radius)
#     x += sd.randint(30, 200)
#     point = sd.get_point(x, y)

# Нарисовать три ряда по 10 пузырьков

# radius = sd.randint(25, 100)
# lists_of_x = []
# for i in range(10):
#     lists_of_x.append(sd.randint(30, 175))
# lists_of_y = []
# for i in range(3):
#     lists_of_y.append(sd.randint(30, 175))
# x_copy = x = sd.randint(1, 120)
# y = sd.randint(1, 200)
# for j in range(3):
#     x = x_copy
#     y += lists_of_y[j]
#     for i in range(10):
#         x += lists_of_x[i]
#         point = sd.get_point(x, y)
#         bubble(point, radius)

# Нарисовать 100 пузырьков в произвольных местах экрана случайными цветами
for i in range(101):
    point = sd.get_point(sd.randint(1, 1200), sd.randint(1, 600))
    radius = sd.randint(25, 250)
    bubble(point, radius)
    #print(i)
sd.pause()
Esempio n. 19
0
def draw_smile(x, y, color):
    sd.ellipse(left_bottom=sd.get_point(x, y),
               right_top=sd.get_point(x + 150, y + 100),
               color=color,
               width=2)
    sd.circle(center_position=sd.get_point(x + 40, y + 70),
              radius=8,
              color=color,
              width=1)
    sd.circle(center_position=sd.get_point(x + 110, y + 70),
              radius=8,
              color=color,
              width=1)
    sd.lines(point_list=[
        sd.get_point(x + 20, y + 50),
        sd.get_point(x + 50, y + 25),
        sd.get_point(x + 100, y + 25),
        sd.get_point(x + 130, y + 50)
    ],
             color=color,
             width=1)


for _ in range(110):
    draw_smile(x=sd.randint(0, 450),
               y=sd.randint(0, 450),
               color=sd.random_color())

sd.pause()
Esempio n. 20
0
import simple_draw as sd

sd.resolution = (1200,800)

xlist, ylist = [], []

for _ in range(50):
    xlist.append(sd.randint(100,1100))
    ylist.append(sd.randint(500,800))

def snowflake(x, y):
    a = 1
    while True:
        sd.clear_screen()
        for i in range(len(x)):
            point = sd.get_point(x[i],y[i])
            sd.snowflake(center=point, length=50, color='white')
            h = sd.randint(0, 20)
            y[i] -= h
            if y[i] < 50:
                break
            a = sd.randint(-1,1)

            x[i] = x[i] + h*a
        sd.sleep(0.05)
        if sd.user_want_exit():
            break
snowflake(xlist,ylist)

sd.pause()
Esempio n. 21
0
sd.clear_screen()
radius = 50
for x in range(100, 900, 80):
    point = sd.get_point(x, 300)
    draw_buble(point=point, radius=radius, step=3, amt=4)

# Нарисовать три ряда по 10 пузырьков
sd.clear_screen()
radius = 30
for y in range(450, 551, 50):
    for x in range(100, 600, 50):
        point = sd.get_point(x, y)
        draw_buble(point=point,
                   radius=radius,
                   step=3,
                   amt=4,
                   color=sd.COLOR_GREEN)

# Нарисовать 100 пузырьков в произвольных местах экрана случайными цветами
sd.clear_screen()
for _ in range(100):
    radius = sd.randint(50, 100)
    step = sd.randint(1, 5)
    point = sd.random_point()
    color = sd.random_color()
    draw_buble(point=point, radius=radius, step=step, color=color)

sd.pause()

# зачёт! 🚀
Esempio n. 22
0
sd.resolution = (1200, 600)

# Написать функцию отрисовки смайлика в произвольной точке экрана
# Форма рожицы-смайлика на ваше усмотрение
# Параметры функции: кордината X, координата Y, цвет.
# Вывести 10 смайликов в произвольных точках экрана.


def smile(x=sd.randint(0, 1200), y=sd.randint(0, 600),
          color=sd.random_color()):
    smile_cencer = sd.get_point(x, y)
    left_bottom = sd.get_point(x - 100, y - 75)
    right_top = sd.get_point(x + 100, y + 75)
    sd.ellipse(left_bottom, right_top, width=1, color=color)
    left_eye_center = sd.get_point(x - 40, y + 25)
    sd.circle(left_eye_center, 20, color=color)
    right_eye_center = sd.get_point(x + 40, y + 25)
    sd.circle(right_eye_center, 25, color=color)
    point_1 = sd.get_point(x - 50, y - 25)
    point_2 = sd.get_point(x - 25, y - 35)
    point_3 = sd.get_point(x + 25, y - 35)
    point_4 = sd.get_point(x + 50, y - 25)
    point_list = [point_1, point_2, point_3, point_4]
    sd.lines(point_list, color=color)


for _ in range(61):
    smile(x=sd.randint(0, 1200), y=sd.randint(0, 600), color=sd.random_color())
sd.pause()
Esempio n. 23
0
# -*- coding: utf-8 -*-

# (определение функций)
import simple_draw as s


# Написать функцию отрисовки смайлика в произвольной точке экрана
# Форма рожицы-смайлика на ваше усмотрение
# Параметры функции: кордината X, координата Y, цвет.
# Вывести 10 смайликов в произвольных точках экрана.


def smile(x, y, color):
    radius = 50
    s.circle(center_position=s.Point(x, y), radius=radius, color=color, width=0)
    s.circle(center_position=s.Point(x + 15, y + 20), radius=7, color=s.COLOR_CYAN, width=0)
    s.circle(center_position=s.Point(x - 15, y + 20), radius=7, color=s.COLOR_CYAN, width=0)
    s.line(start_point=s.Point(x - 20, y - 10), end_point=s.Point(x + 20, y - 10), color=s.COLOR_RED, width=4)
    s.line(start_point=s.Point(x - 20, y - 12), end_point=s.Point(x + -30, y + 5), color=s.COLOR_RED, width=4)
    s.line(start_point=s.Point(x + 20, y - 12), end_point=s.Point(x + 30, y + 5), color=s.COLOR_RED, width=4)


for _ in range(10):

    smile(s.randint(0, 600), s.randint(0, 600), s.COLOR_YELLOW)
s.pause()
Esempio n. 24
0
sd.resolution = (x_screen_res, y_screen_res)
y_top_half = int(y_screen_res / 2) + 200
# нарисовать снежинку в точке center с длинной лучей length цветом color
#         factor_a - место ответвления лучиков factor_a=0.6
#         factor_b - длина лучиков factor_b=0.35
#         factor_c - угол отклонения лучиков factor_c=60
snowflakes_starting_points = []
snowflakes_lengths = []
snowflakes_factors_a_b_c = []
snowflakes_fallen_coordinates = []
snowflakes_fallen_lengths = []
snowflakes_fallen_factors_a_b_c = []

for i in range(N):
    snowflakes_starting_points.append([
        sd.randint(0, x_screen_res),
        sd.randint(y_top_half, y_screen_res + 450)
    ])
    snowflakes_lengths.append(sd.randint(10, 50))
    snowflakes_factors_a_b_c.append([
        round(random.uniform(0.3, 0.9), 2),
        round(random.uniform(0.15, 0.55), 2),
        round(sd.randint(50, 70), 2)
    ])

# Пригодятся функции
# sd.get_point()
# sd.snowflake()
# sd.sleep()
# sd.random_number()
# sd.user_want_exit()
Esempio n. 25
0
 def move(self):
     self.center_point = sd.get_point(
         self.center_point.x + sd.randint(2, 10),
         self.center_point.y - sd.randint(2, 10))
Esempio n. 26
0
# (цикл for)

import simple_draw as sd
#sd.resolution = (1200, 600)
rainbow_colors = (sd.COLOR_RED, sd.COLOR_ORANGE, sd.COLOR_YELLOW, sd.COLOR_GREEN,
                  sd.COLOR_CYAN, sd.COLOR_BLUE, sd.COLOR_PURPLE)

# Нарисовать радугу: 7 линий разного цвета толщиной 4 с шагом 5 из точки (50, 50) в точку (350, 450)
def rainbow(point,radius):
     for i in range(7):
        radius += 5
        color = sd.random_color()
        sd.circle(point, radius, rainbow_colors[i], 4)

point = sd.get_point(350, 50)
radius = sd.randint(300, 400)

rainbow(point, radius)
point1 = sd.get_point(0, 0)
point2 = sd.get_point(50, 600)
sd.rectangle(point1, point2, color=sd.background_color)

point3 = sd.get_point(350, 0)
point4 = sd.get_point(600, 600)
sd.rectangle(point3, point4, color=sd.background_color)



# Усложненное задание, делать по желанию.
# Нарисовать радугу дугами от окружности (cсм sd.circle) за нижним краем экрана,
# поэкспериментировать с параметрами, что бы было красиво