你能用python画一个西瓜吗
当然可以!以下是用Python绘制西瓜的代码:
import turtle
# 设置画布和画笔
wn = turtle.Screen()
wn.bgcolor("lightgreen")
wn.title("Watermelon")
t = turtle.Turtle()
t.pensize(3)
# 绘制西瓜的外形
t.color("darkgreen", "green")
t.begin_fill()
t.penup()
t.goto(0, -150)
t.pendown()
t.circle(150)
t.end_fill()
# 绘制西瓜的纹路
t.color("black", "black")
t.penup()
t.goto(0, 0)
t.pendown()
t.begin_fill()
t.goto(75, 75)
t.goto(0, 150)
t.goto(-75, 75)
t.goto(0, 0)
t.end_fill()
# 绘制西瓜的种子
t.color("black", "white")
t.penup()
t.goto(-60, 100)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(60, 100)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(-60, 70)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(60, 70)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
# 隐藏画笔
t.hideturtle()
# 点击窗口关闭程序
wn.exitonclick()
运行代码后,将会弹出一个绘制好的西瓜窗口,效果如下图所示:
原文地址: http://www.cveoy.top/t/topic/gRk 著作权归作者所有。请勿转载和采集!