闲来无事用海龟绘图画了一个科比的图标,画的比较简陋,有问题欢迎斧正。
话不多说,成品如下(加了个背景)。其中手为科比手是个背景图片,字体和图案为海龟所画。
代码如下:
import turtle def top(x1,y1,s1,s2): #标志最上边的两个图形 turtle.penup() #抬笔 turtle.goto(x1,y1) #海龟爬到这个坐标,即落笔的地点 turtle.pendown() #落笔 turtle.begin_fill() #填充 turtle.fillcolor("#5c275e") #填充的颜色 turtle.setheading(90) #海龟朝向90°的方向 turtle.forward(32) #海龟爬的距离为32 if x1==-46: #因为用的是left和right,有对称的图像,所以加了个判断,判断是左边还是右边的一个图形 turtle.left(67) #海龟左转67度 else: turtle.right(67) turtle.forward(87) if x1==-46: turtle.left(52) else: turtle.right(52) turtle.forward(20) turtle.goto(x1,y1) turtle.end_fill()#结束填充 def mid(x2,y2,s1,s2,s3): turtle.penup() turtle.goto(x2, y2) turtle.pendown() turtle.begin_fill() turtle.fillcolor("#5c275e") turtle.setheading(s1) turtle.forward(115) turtle.setheading(s2) turtle.forward(35) turtle.setheading(s3) turtle.forward(83) turtle.goto(x2,y2) turtle.end_fill() def bottom(x3,y3,s1,s2): turtle.penup() turtle.goto(x3,y3) turtle.pendown() turtle.begin_fill() turtle.fillcolor('#5c275e') turtle.setheading(-90) turtle.forward(180) turtle.setheading(s1) turtle.forward(15) turtle.setheading(s2) turtle.forward(140) turtle.goto(x3,y3) turtle.end_fill() #turtle.bgpic('2.png')#背景图片,在本py文件同级目录下放一张2.png即可使用背景图 turtle.speed(6) #海龟爬行速度 turtle.hideturtle()#隐藏海龟 turtle.width(3)#海龟爬行痕迹粗细 turtle.color('#e6cd21') #海龟爬行痕迹颜色 #调用函数 x=-50 y=80 top(4+x,9+y,67,52) top(16+x,9+y,67,52) mid(-4+x,-4+y,150,-78,-45) mid(20+x,-4+y,30,-102,-135) bottom(0+x,-20+y,140,98) bottom(16+x,-20+y,40,82) #文字部分,如果没有背景颜色,最下边的白色字体会和背景同色导致看不见 turtle.penup() turtle.goto(-210,350)#210 330 turtle.write("Legend will never die,",move='left',font=("宋体",20,"italic")) turtle.pendown() turtle.penup() turtle.goto(-210,310) turtle.write("Mamba never out!",font=("宋体",20,"italic")) turtle.pendown() turtle.penup() turtle.goto(50,-400) turtle.color('white') turtle.write('kobe 24',font=("Comic Sans MS",25,"bold")) turtle.pendown() #turtle.mainloop() #解决程序运行完窗口消失,取消注释即可
下边为初始版代码,和上边差不过,但是更简单化。(记录我的代码完善情况),运行效果如下:
代码如下:
import turtle turtle.speed(6) turtle.hideturtle() turtle.width(3) turtle.color("gold") #左上上的部分 turtle.penup() turtle.goto(4,9) turtle.pendown() turtle.begin_fill() turtle.fillcolor("purple") turtle.setheading(90) turtle.forward(32) turtle.left(67) turtle.forward(87) turtle.left(52) turtle.forward(20) turtle.goto(4,9) turtle.end_fill() #左上下的部分 turtle.penup() turtle.goto(-4,-4) turtle.pendown() turtle.begin_fill() turtle.fillcolor("purple") turtle.setheading(150) turtle.forward(115) turtle.setheading(-78) turtle.forward(35) turtle.setheading(-45) turtle.forward(83) turtle.goto(-4,-4) turtle.end_fill() #左下的部分 turtle.penup() turtle.goto(0,-20) turtle.pendown() turtle.begin_fill() turtle.fillcolor("purple") turtle.setheading(-90) turtle.forward(180) turtle.setheading(140) turtle.forward(15) turtle.setheading(98) turtle.forward(140) turtle.goto(0,-20) turtle.end_fill() #右上上的部分 turtle.penup() turtle.goto(16,9) turtle.pendown() turtle.begin_fill() turtle.fillcolor("purple") turtle.setheading(90) turtle.forward(32) turtle.right(67) turtle.forward(87) turtle.right(52) turtle.forward(20) turtle.goto(16,9) turtle.end_fill() #右上下的部分 turtle.penup() turtle.goto(20,-4) turtle.pendown() turtle.begin_fill() turtle.fillcolor("purple") turtle.setheading(30) turtle.forward(115) turtle.setheading(-102) turtle.forward(35) turtle.setheading(-135) turtle.forward(83) turtle.goto(20,-4) turtle.end_fill() #右下的部分 turtle.penup() turtle.goto(16,-20) turtle.pendown() turtle.begin_fill() turtle.fillcolor("purple") turtle.setheading(-90) turtle.forward(180) turtle.setheading(40) turtle.forward(15) turtle.setheading(82) turtle.forward(140) turtle.goto(16,-20) turtle.end_fill() turtle.hideturtle() turtle.penup() turtle.goto(-180,130) turtle.write("科比.布莱恩特的logo的海龟制图",font=("arial",20,"normal")) turtle.pendown()
最后,欢迎你的到来,祝你学业有成,生活美满。Mamba!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)