python 画机器猫
Python语言很容易学习,也很有趣。今天,我们来用Python画一个非常经典的机器猫!
import turtle # 设置画布 turtle.setup(800,400) turtle.speed(10) # 绘制头部 turtle.penup() turtle.goto(⑸0,40) turtle.pendown() turtle.begin_fill() turtle.color("grey") turtle.circle(80) turtle.end_fill() # 绘制耳朵 turtle.penup() turtle.goto(⑵0,130) turtle.pendown() turtle.begin_fill() turtle.color("white") turtle.circle(20) turtle.end_fill() turtle.penup() turtle.goto(⑻0,130) turtle.pendown() turtle.begin_fill() turtle.color("white") turtle.circle(20) turtle.end_fill() # 绘制眼睛 turtle.penup() turtle.goto(⑷0,70) turtle.pendown() turtle.begin_fill() turtle.color("white") turtle.circle(15) turtle.end_fill() turtle.penup() turtle.goto(⑻0,70) turtle.pendown() turtle.begin_fill() turtle.color("white") turtle.circle(15) turtle.end_fill() # 绘制瞳孔 turtle.penup() turtle.goto(⑶5,75) turtle.pendown() turtle.begin_fill() turtle.color("black") turtle.circle(5) turtle.end_fill() turtle.penup() turtle.goto(⑺5,75) turtle.pendown() turtle.begin_fill() turtle.color("black") turtle.circle(5) turtle.end_fill() # 绘制鼻子和嘴巴 turtle.penup() turtle.goto(⑸0,40) turtle.pendown() turtle.begin_fill() turtle.color("red") turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(⑹5,25) turtle.pendown() turtle.pensize(8) turtle.right(45) turtle.forward(35) # 绘制身体 turtle.penup() turtle.goto(⑴00,⑹0) turtle.pendown() turtle.begin_fill() turtle.color("grey") for _ in range(2): turtle.forward(200) turtle.right(90) turtle.forward(120) turtle.right(90) turtle.end_fill() turtle.hideturtle() turtle.done()
运行这段代码,你会看到一个非常可爱的机器猫在你的屏幕上出现!
这个小案例是一个很好的Python绘图初学者练手的小练习,能够帮助你加深对Python语言的理解和应用。
文章来源:丸子建站
文章标题:python 画机器猫
https://www.wanzijz.com/view/58027.html