猫史档案馆


【Python作品分享】碰到边缘就反弹【求助帖】

用户:我在鱼米之乡我在鱼米之乡查看:0 回复:0 评论:0 创建时间:2022-02-15T16:44:37


【作品展示】

center_image

 

【作品介绍】

请大家帮助我解决反弹的难题,谢谢!

 

【作品源代码】

import turtle
import random
import time


p = turtle.Pen()
p.hideturtle()
p.speed(0)
s = turtle.Screen()
s.tracer(0)
S_W, S_H = 600, 600

def new_goto(pen, x, y):

    pen.penup()
    pen.goto(x, y)
    pen.pendown()

color = ['red', 'blue', 'green', 'purple', 'black', 'pink']
da = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

x = 0
while True:
    if p.xcor()<=500 and p.ycor()<=600:
        b = random.choice(color)
        turtle.bgcolor(b)
        a = random.choice(color)
        c = random.choice(da)
        d = random.choice(da)
        p.dot(c,a)
        new_goto(p, x, 0)
        x += d
        s.update()
        time.sleep(0.2)
        p.clear() 
    else:
        p.right(c)
        continue

turtle.done()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页