用函数画个场景示例,场景为蓝天松树鸟飞

用函数画个场景示例,场景为蓝天松树鸟飞

"""
用函数画个场景示例,场景为蓝天松树鸟飞
"""

# 导入arcade库
import arcade

# 常量定义
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 600
SCREEN_TITLE = "用函数画个场景示例_译者:李兴球"

def draw_background():
    """
    此函数画背景,2/3屏幕为天空,下面为地面
    """
    # 画矩形
    arcade.draw_lrtb_rectangle_filled(0,
                                      SCREEN_WIDTH,
                                      SCREEN_HEIGHT,
                                      SCREEN_HEIGHT * (1 / 3),
                                      arcade.color.SKY_BLUE)

    # 画矩形
    arcade.draw_lrtb_rectangle_filled(0,
                                      SCREEN_WIDTH,
                                      SCREEN_HEIGHT / 3,
                                      0,
                                      arcade.color.DARK_SPRING_GREEN)


def draw_bird(x, y):
    """
    画两个弧形表示一只鸟
    """
    arcade.draw_arc_outline(x, y, 20, 20, arcade.color.BLACK, 0, 90)
    arcade.draw_arc_outline(x + 40, y, 20, 20, arcade.color.BLACK, 90, 180)


def draw_pine_tree(x, y):
    """
    本函数画颗松树
    """
    # Draw the triangle on top of the trunk
    arcade.draw_triangle_filled(x + 40, y,
                                x, y - 100,
                                x + 80, y - 100,
                                arcade.color.DARK_GREEN)

    # 画树杆,lrtb是left,right,top,bottom,如下:
    # left:	矩形最左边的x坐标
    # right:	矩形最右边的x坐标
    # top:	矩形最上边的y坐标
    # bottom:	矩形最下边的y坐标
    # color:	矩形的颜色
    # border_width:	矩形边框的宽度像素值,默认为1.

    arcade.draw_lrtb_rectangle_filled(x + 30, x + 50, y - 100, y - 140,
                                      arcade.color.DARK_BROWN)


def main():
    """
    This is the main program.
    """

    # 打开一个窗口,参数为宽度高度标题
    arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
   
    # 开始渲染,它要在所有命令之前
    arcade.start_render()

    # 调用所有的函数
    draw_background()
    draw_pine_tree(50, 250)
    draw_pine_tree(350, 320)
    draw_bird(70, 500)
    draw_bird(470, 550)

    #结束渲染
    arcade.finish_render()

    # 进入游戏循环
    arcade.run()


if __name__ == "__main__":
    main()

 

李兴球

李兴球的博客是Python创意编程原创博客

评论已关闭。