CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Day01-15/code/Day01/peppa_pig.py
Views: 729
"""1绘制小猪佩奇2"""3from turtle import *456def nose(x,y):7"""画鼻子"""8penup()9# 将海龟移动到指定的坐标10goto(x,y)11pendown()12# 设置海龟的方向(0-东、90-北、180-西、270-南)13setheading(-30)14begin_fill()15a = 0.416for i in range(120):17if 0 <= i < 30 or 60 <= i <90:18a = a + 0.0819# 向左转3度20left(3)21# 向前走22forward(a)23else:24a = a - 0.0825left(3)26forward(a)27end_fill()28penup()29setheading(90)30forward(25)31setheading(0)32forward(10)33pendown()34# 设置画笔的颜色(红, 绿, 蓝)35pencolor(255, 155, 192)36setheading(10)37begin_fill()38circle(5)39color(160, 82, 45)40end_fill()41penup()42setheading(0)43forward(20)44pendown()45pencolor(255, 155, 192)46setheading(10)47begin_fill()48circle(5)49color(160, 82, 45)50end_fill()515253def head(x, y):54"""画头"""55color((255, 155, 192), "pink")56penup()57goto(x,y)58setheading(0)59pendown()60begin_fill()61setheading(180)62circle(300, -30)63circle(100, -60)64circle(80, -100)65circle(150, -20)66circle(60, -95)67setheading(161)68circle(-300, 15)69penup()70goto(-100, 100)71pendown()72setheading(-30)73a = 0.474for i in range(60):75if 0<= i < 30 or 60 <= i < 90:76a = a + 0.0877lt(3) #向左转3度78fd(a) #向前走a的步长79else:80a = a - 0.0881lt(3)82fd(a)83end_fill()848586def ears(x,y):87"""画耳朵"""88color((255, 155, 192), "pink")89penup()90goto(x, y)91pendown()92begin_fill()93setheading(100)94circle(-50, 50)95circle(-10, 120)96circle(-50, 54)97end_fill()98penup()99setheading(90)100forward(-12)101setheading(0)102forward(30)103pendown()104begin_fill()105setheading(100)106circle(-50, 50)107circle(-10, 120)108circle(-50, 56)109end_fill()110111112def eyes(x,y):113"""画眼睛"""114color((255, 155, 192), "white")115penup()116setheading(90)117forward(-20)118setheading(0)119forward(-95)120pendown()121begin_fill()122circle(15)123end_fill()124color("black")125penup()126setheading(90)127forward(12)128setheading(0)129forward(-3)130pendown()131begin_fill()132circle(3)133end_fill()134color((255, 155, 192), "white")135penup()136seth(90)137forward(-25)138seth(0)139forward(40)140pendown()141begin_fill()142circle(15)143end_fill()144color("black")145penup()146setheading(90)147forward(12)148setheading(0)149forward(-3)150pendown()151begin_fill()152circle(3)153end_fill()154155156def cheek(x,y):157"""画脸颊"""158color((255, 155, 192))159penup()160goto(x,y)161pendown()162setheading(0)163begin_fill()164circle(30)165end_fill()166167168def mouth(x,y):169"""画嘴巴"""170color(239, 69, 19)171penup()172goto(x, y)173pendown()174setheading(-80)175circle(30, 40)176circle(40, 80)177178179def setting():180"""设置参数"""181pensize(4)182# 隐藏海龟183hideturtle()184colormode(255)185color((255, 155, 192), "pink")186setup(840, 500)187speed(10)188189190def main():191"""主函数"""192setting()193nose(-100, 100)194head(-69, 167)195ears(0, 160)196eyes(0, 140)197cheek(80, 10)198mouth(-20, 30)199done()200201202if __name__ == '__main__':203main()204205206