示例#1
1
def main():
    points = [Point(x=230, y=450), Point(x=240, y=460), Point(x=230, y=470), Point(x=240, y=480)]
    polygon(point_list=points)
    points2 = [Point(p.x + 20, p.y + 20) for p in points]
    lines(point_list=points2, color=COLOR_DARK_ORANGE)
    line(start_point=Point(x=20, y=20), end_point=Point(x=40, y=300))
    square(left_bottom=Point(400, 300, ), side=100)
    rectangle(
        left_bottom=Point(x=200, y=200),
        right_top=Point(x=300, y=300),
        color=COLOR_DARK_GREEN
    )
    rectangle(
        left_bottom=Point(x=400, y=300),
        right_top=Point(x=300, y=400),
        color=COLOR_DARK_GREEN
    )
    sleep(2)
    clear_screen()
    vector(start=Point(x=230, y=260), angle=70, length=200, color=COLOR_PURPLE)
    for i in range(10):
        point = random_point()
        color = random_color()
        radius = random_number(20, 60)
        circle(center_position=point, radius=radius, color=color, width=0)
    sleep(2)
    clear_screen()
    for i in range(10):
        point = random_point()
        color = random_color()
        dx = random_number(30, 100)
        dy = random_number(30, 100)
        right_top = Point(x=point.x + dx, y=point.y + dy)
        ellipse(left_bottom=point, right_top=right_top, color=color)
    v3 = Vector(start_point=Point(0, 0), direction=45, length=50)
    for direction in range(0, 181, 20):
        v = Vector(start_point=Point(x=300, y=300), direction=direction, length=100)
        v.draw()
        v2 = Vector(start_point=v.end_point, direction=direction + 30, length=50)
        v2.draw(color=COLOR_GREEN)
        v2.add(v3)
        v2.draw(color=COLOR_ORANGE)
    snowflake(center=Point(), length=60, factor_b=0.2, factor_c=100)
    sleep(2)
    for k in range(2):
        y = 500
        for i in range(10):
            clear_screen()
            y -= 30
            for x in [100, 200, 300, 400, 500]:
                radius = random_number(30, 50)
                point = Point(x=x, y=y)
                snowflake(center=point, length=radius)
                mouse_point, mouse_buttons = get_mouse_state()
                print("mouse_state is {} + {}".format(mouse_point, mouse_buttons))
            if user_want_exit(sleep_time=0.1):
                break
        if user_want_exit(0):
            break
示例#2
0
 def do(self):
     self.draw_items()
     self.manage_mobile_items_collisions()
     self.move_mobile_items()
     self.check_mobile_items_in_window()
     self.check_mobile_item_is_immovable()
     [cursorPos, mouseState] = sd.get_mouse_state()
     if mouseState[2] != 0:
         self.export_mobile_items()
示例#3
0
def snowfall():
    for k in range(2):
        y = 500
        for i in range(10):
            sd.clear_screen()
            y -= 30
            for x in [100, 200, 300, 400, 500]:
                radius = sd.random_number(30, 50)
                point = sd.Point(x=x, y=y)
                sd.snowflake(center=point, length=radius)
                mouse_point, mouse_buttons = sd.get_mouse_state()
                print("mouse_state is {} + {}".format(mouse_point,
                                                      mouse_buttons))
            if sd.user_want_exit(sleep_time=0.1):
                break
        if sd.user_want_exit(0):
            break
示例#4
0
def massive_snowfall():
    flakes = [Snowflake() for _ in range(100)]

    while True:
        sd.start_drawing()
        for flake in flakes:
            flake.draw(color=sd.background_color)
        fallen_count = 0
        for flake in flakes:
            if flake.move():
                fallen_count += 1
        for flake in flakes:
            flake.draw(color=sd.COLOR_WHITE)
        for _ in range(fallen_count):
            flakes.append(Snowflake())
        sd.finish_drawing()
        if TAKE_SNAPSHOTS:
            sd.take_snapshot(path=SNAPSHOTS_PATH)
        mouse_point, mouse_buttons = sd.get_mouse_state()
        print("mouse_state is {} + {}".format(mouse_point, mouse_buttons))
        if sd.user_want_exit(sleep_time=0.1):
            break
示例#5
0
def get_wind_power():
    half_res = sd.resolution[0] / 2
    mouse_pos = sd.get_mouse_state()[0]
    return (mouse_pos.x - half_res) / half_res
示例#6
0
        sd.sleep(0.1)
        sd.finish_drawing()
        if sd.user_want_exit():
            break


if __name__ == "__main__":
    sd._init()
    sd.background_color = sd.COLOR_WHITE
    clear_screen()
    user_interface = UserInterface()
    user_interface.add_button(10, 10, "Go!",
                              event=show_bicycle).set_size(60, 30)
    while True:
        mouse_pos, mouse_buttons = sd.get_mouse_state()
        point = mouse_pos
        on_click = False

        if mouse_buttons[2] == 1 and mode == EMPTY_MODE:
            mode = START_MODE

        elif mouse_buttons[2] == 0 and mode == START_MODE:
            mode = EMPTY_MODE

        elif mouse_buttons[0] == 1 and mode == EMPTY_MODE:
            mode = LEFT_CLICK

        elif mouse_buttons[0] == 0 and mode == LEFT_CLICK:
            on_click = True
            mode = EMPTY_MODE