python做简单的笑脸的编程,python画笑脸表情包教程

大家好,小编为大家解答python画笑脸步骤的中文翻译的问题。很多人还不知道python用turtle画笑脸的代码,现在让我们一起来看看吧!

我正在开发一个涉及游戏的程序,该程序将根据用户输入更改笑脸(使用乌龟绘制)。 程序启动时,将绘制一张规则的笑脸(黄色的脸,黑色的眼睛和嘴巴,微笑)python自学能成功吗。 然后,通过以下菜单提示用户更改面孔:

换脸

1)让我皱眉

2)让我生气

3)让我的眼睛变蓝

0)退出

输入选择:

如果用户选择1,则将笑脸重新绘制,皱眉变成微笑,菜单将更改为:

换脸

1)让我微笑

2)让我生气

3)让我的眼睛变蓝

0)退出

输入选择:

如果用户选择2,将重新绘制笑脸并用皱眉填充红色,菜单将更改为:

换脸

1)让我微笑

2)让我开心

3)让我的眼睛变蓝

0)退出

输入选择:

我很难根据用户输入更改笑脸。 我该如何改变笑脸?

据我所知,请帮助!:

import turtle

turtle.up()

turtle.goto(0, -100) # center circle around origin

turtle.down()

turtle.begin_fill()

turtle.fillcolor("yellow") # draw head

turtle.circle(100)

turtle.end_fill()

turtle.up()

turtle.goto(-67, -40)

turtle.setheading(-60)

turtle.width(5)

turtle.down()

turtle.circle(80, 120) # draw smile

turtle.fillcolor("black")

for i in range(-35, 105, 70):

turtle.up()

turtle.goto(i, 35)

turtle.setheading(0)

turtle.down()

turtle.begin_fill()

turtle.circle(10) # draw eyes

turtle.end_fill()

class Face:

def __init__(self):

self.__smile = True

self.__happy = True

self.__dark_eyes = True

def draw_face(self):

turtle.clear()

self.__draw_head()

self.__draw_eyes()

self.__draw_mouth()

def is_smile(self):

self.__smile = False

def is_happy(self):

self.__happy = False

def is_dark_eyes(self):

self.__dark_eyes = False

def __draw_head(self):

self.__draw_head

def __draw_eyes(self):

self.__draw_eyes

def __draw_mouth(self):

self.__draw_mouth

def change_mouth(self):

self.__smile = not self.__smile

self.draw_face()

def change_emotion(self):

self.__happy = not self.__happy

self.draw_face()

def change_eyes(self):

self.__dark_eyes = not self.__dark_eyes

self.draw_face()

def main():

face = Face()

face.draw_face()

done = False

while not done:

print("Change My Face")

mouth = "frown" if face.is_smile() else "smile"

emotion = "angry" if face.is_happy() else "happy"

eyes = "blue" if face.is_dark_eyes() else "black"

print("1) Make me", mouth)

print("2) Make me", emotion)

print("3) Make my eyes", eyes)

print("0) Quit")

menu = int(input("Enter a selection: "))

if menu == 1:

face.change_mouth()

face.draw_face()

elif menu == 2:

face.change_emotion()

face.draw_face()

elif menu == 3:

face.change_eyes()

face.draw_face()

else:

break

print("Thanks for Playing")

turtle.hideturtle()

turtle.done()

main()

如何实现乌龟代码,以便可以根据用户输入绘制笑脸?

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值