猫史档案馆


【Python作品分享】你好,月亮【120强进36】【作品秀】

用户:HJS_鱼缸下的我HJS_鱼缸下的我查看:0 回复:0 评论:0 创建时间:2021-05-15T16:34:55


【作品展示】

center_image

 

【作品介绍】

120强进36参赛作品。

它的所有效果已经在屏幕录像里展示出来了。

 

【作品源代码】

from easygui import *
from random import *
import turtle

def draw(pos, color_1, color_2, addx = 0, addy = 0, size = 1):
    p.color(color_1)
    p.begin_fill()
    p.up()
    p.goto(pos[len(pos) - 1][0] * size + addx, pos[len(pos) - 1][1] * size + addy)
    p.down()
    for x, y in pos:
        p.goto(x * size + addx, y * size + addy)
    p.color(color_2)
    p.end_fill()

def rocket(size, addy):
    draw([[0, 230], [-20, 170], [-20, 120], [20, 120], [20, 170]], 'black', 'blue', size = size, addy = addy)
    draw([[-20, 120], [-20, -115], [-15, -120], [15, -120], [20, -115], [20, 120]], 'black', 'blue', size = size, addy = addy)
    draw([[-25, -65], [-30, -80], [-30, -115], [-20, -115], [-20, -80]], 'black', 'blue', size = size, addy = addy)
    draw([[25, -65], [30, -80], [30, -115], [20, -115], [20, -80]], 'black', 'blue', size = size, addy = addy)

def moon(mx, my):
    p.color(1, 1, 200 / 255)
    p.goto(mx, my)
    p.dot(400)
    p.color(220 / 255, 220 / 255, 150 / 255)
    xys = [[135, 100, 60], [-20, -10, 40], [-10, 100, 50], 
           [-150, 80, 35], [100, -60, 45], [60, 40, 50], 
           [15, -150, 30], [-90, -90, 80], [-70, 20, 60]]
    for x, y, s in xys:
        p.goto(x + mx, y + my)
        p.dot(s)

def space():
    p.color('white')
    p.up()
    d = enterbox('你想绘制多少颗星星?(数字不宜输入过大)', '提示', 30)
    while d == None:
        msgbox('请重新输入!', '提示', '知道了')
        d = enterbox('你想绘制多少颗星星?(数字不宜输入过大)', '提示', 30)
    for x in range(int(d)):
        p.goto(randint(-400, 400), randint(-300, 300))
        p.dot(randint(5, 8))

def zght(addy):
    p.color('red')
    p.up()
    for c in range(4):
        p.goto(-7, 170 + addy - 30 * c)
        p.write('中国航天'[c], font = ['Arial', 15])

def astronant(mx, my):
    p.up()
    p.color('white')
    p.begin_fill()
    p.goto(mx, my)
    p.dot(60)
    cmd = [[2, 135], [0, 20], [2, 15], [0, 30], [1, 20], [0, 40], [1, 20], [0, 30], [1, 90], [0, 20], 
           [1, 90], [0, 30], [2, 20], [0, 25], [2, 155], [0, 70], [2, 20], [0, 60], [1, 90], [0, 30], 
           [1, 90], [0, 60], [2, 150], [0, 60], [1, 90], [0, 30], [1, 90], [0, 60], [2, 10], [0, 100], 
           [2, 40], [0, 60], [1, 90], [0, 20], [1, 90], [0, 60]]
    p.down()
    for c, s in cmd:
        if c == 0:
            p.fd(s)
        if c == 1:
            p.lt(s)
        if c == 2:
            p.rt(s)
    p.goto(mx, my)
    p.end_fill()
    p.pensize(30)
    p.color('black')
    p.rt(170)
    p.fd(25)
    p.up()
    p.goto(mx + 3, my + 20)
    p.color('white')
    p.pensize(2)
    p.rt(40)
    p.down()
    for x in range(15):
        p.rt(3)
        p.fd(1)
    p.up()
    p.rt(12)
    p.fd(4)
    p.dot(3)

p = turtle.Pen()
turtle.setup(800, 600)
turtle.title('你好,月亮')
turtle.bgcolor('black')
p.hideturtle()
p.speed(0)
space()
command = ynbox('你想看哪个画面?', '提示', ('登月', '奔月'))
while command == None:
    msgbox('请重新选择!', '提示', '知道了')
    command = ynbox('你想看哪个画面?', '提示', ('登月', '奔月'))
if command:
    moon(0, 0)
    rocket(0.7, 120)
    zght(0)
else:
    moon(250, 200)
    astronant(-200, -50)
turtle.done()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页