Python系列 | Turtle绘图学习之羽毛球随机点训练场

绘图之前先要安装turtle模块:
python 2:

pip install turtle

python 3:

pip3 install turtle

绘图思路:
首先绘制出外正方形和内线,然后使用dot绘制出九个跑位的点,记录每个点的x和y轴,写入死循环和if判断条件判断是否为中圆点并闪烁。

效果图展示:

请添加图片描述

效果图代码:

#woshinsy
import turtle
import time
import random
turtle.title("woshinsy python homework")
# 窗口大小
turtle.bgcolor("#367847")
# 大圈
def bcir():
    turtle.dot(65,"yellow")

# 小圈
def cir():
    turtle.dot(45, "white")

# 横纵坐标
def tp(x,y):
    turtle.penup()
    turtle.goto(x,y)
    turtle.pendown()

# 球场设置
def square():
    turtle.color("white")
    for i in range(4):
        turtle.pensize(10)
        turtle.forward(500)
        turtle.left(90)

#隐藏箭头
turtle.speed(9)
turtle.hideturtle()
tp(-250,-250)
square()
tp(-250,125)
turtle.forward(500)
tp(0,120)
turtle.left(-90)
turtle.forward(370)
tp(0,0)
bcir()
# 上1
tp(-250,250)
cir()
# 上2
tp(0,250)
cir()
# 上3
tp(250,250)
cir()
# 中1
tp(-250,0)
cir()
# 中3
tp(250,0)
cir()
# 下1
tp(-250,-250)
cir()
# 下2
tp(0,-250)
cir()
# 下3
tp(250,-250)
cir()

def gogo():
    arr = [[0,0],[-250,250],[0,250],[250,250],[-250,0],[250,0],[-250,-250],[0,-250],[250,-250]]
    while True:
        ran = random.randint(0,8)
        if ran ==0:
            tp(0,0)
            turtle.dot(65, "red")
            time.sleep(2)
            turtle.undo()
        else:
            tp(arr[ran][0],arr[ran][1])
            turtle.dot(45,"red")
            time.sleep(2)
            turtle.undo()

gogo()

# 等待用户关闭
turtle.exitonclick()
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值