小精灵采到了七色花很开心,到处都是他们开心的笑脸。请完成屏幕上随机出现若干个笑脸的绘制任务。
基本要求:笑脸大小相同
提升要求:笑脸大小不同
这个题,本来是三条杠做嘴,但是我感觉好丑,就修改了一下
# Description: 命里有时终须有,命里无时莫强求
# Autor: Neptune
# Date: 2021/10/8 17:23
import random
import turtle
pen = turtle.Pen()
colors = ["red", "orange", "yellow", "green", "indigo", "blue", "violet"]
pen.speed(0)
pen.hideturtle()
def draw_eye(x, y): # 画眼函数
pen.pencolor()
pen.penup()
pen.goto(x, y)
pen.pendown()
pen.begin_fill()
pen.circle(25)
pen.fillcolor("blue")
pen.end_fill()
def draw_mouse(x, y):
pen.right(60)
pen.penup()
pen.goto(x - 65, y - 30)
pen.pendown()
pen.circle(75, 120)
pen.penup()
def draw_fl(x, y):
pen.penup() # 提笔
pen.goto(x + 0, y - 100) # 移动位置
pen.pendown() # 放笔
pen.begin_fill() # 开始填充
pen.circle(100) # 画半径为100的圆
pen.fillcolor("yellow") # 填充颜色
pen.end_fill() # 结束填充
# 画眼睛
draw_eye(x - 40, y) # 画左眼
draw_eye(x + 40, y) # 画右眼
# 画嘴巴
draw_mouse(x, y)
turtle.screensize(1920, 1080, "black")
# 屏幕大小800*600像素 背景黑色
n = random.randint(1, 999999)
for i in range(n):
x = random.randrange(-turtle.window_width() // 2, turtle.window_width() // 2)
y = random.randrange(-turtle.window_height() // 2, turtle.window_height() // 2)
draw_fl(x, y)
pen.home()
turtle.mainloop() # 启动事件循环