【Python】用turtle绘制“混沌皮”
画的不好看,不喜勿喷。
目录
展示
设置界面
绘制全身
绘制眼睛
全部代码
展示
我用的是turtle绘制的,不会的可以看这篇文章:【Python】turtle库的介绍及使用(计算机二级常考)_刘佳皓_Leo的博客-CSDN博客_tutle库
https://blog.csdn.net/weixin_70445937/article/details/126414684?spm=1001.2014.3001.5501当然我写的可能不是很好,有大佬写的很好,可以去看看。
设置界面
首先设置一个画布,方便我们在上面操作。
p = t.pen()
t.hideturtle()t.colormode(255) # 颜色模式
t.speed(0)
t.screensize(800, 800, "#e7f1fb") # 画布大小背景颜色
t.setup(width=800, height=800, startx=None, starty=None) # 绘图窗口的大小和起始坐标
# t.bgpic("di_2_800.gif")
t.title("可爱的混沌皮") # 设置绘图窗口的标题
t.resizemode('no-resize') # 大小调整模式:auto,user,noresize
t.tracer(1)
t.hideturtle()
定义一个方法,这样可以让我们快速移动画笔。
def pen(x, y):# 提笔t.penup()# 位移t.goto(x, y)# 落笔t.pendown()
绘制全身
我没有用直线,全用的是曲线来绘制。
def face(x, y):# 身体t.begin_fill()t.fillcolor("#f7fbfe")t.pensize(3)t.begin_fill()pen(100, 100)# 设置海龟的方向t.setheading(90)t.circle(100, 180)t.setheading(230)t.circle(-300, 40)t.circle(40, 80)t.circle(10, 60)t.setheading(330)t.circle(-700, 30)t.setheading(55)t.circle(-700, 35)t.circle(10, 90)t.circle(100, 30)t.setheading(154)t.circle(-1080, 10)t.end_fill()t.setheading(190)t.circle(100, 30)t.circle(-100, 30)t.circle(-90, 40)t.setheading(130)t.circle(100, 30)# 嘴t.begin_fill()pen(1, 110)t.fillcolor('#ce545f')t.setheading(-20)t.circle(30, 60)t.setheading(290)t.circle(-15, 199)t.end_fill()# 左眉毛t.pensize(8)t.color('#3f383b')pen(-30, 177)t.fillcolor('#ce545f')t.setheading(180)t.circle(30, 45)# 右眉毛t.pensize(8)t.color('#3f383b')pen(40, 185)t.fillcolor('#ce545f')t.setheading(160)t.circle(30, 45)# 头巾t.color('#3e3739')t.pensize(8)pen(45, 190)t.setheading(165)t.circle(140, 50)
绘制眼睛
眼睛绘制了一个,另一个是复制调了一下参数。
# 左眼pen(-20, 130)t.setheading(50)t.circle(20, 280)t.setheading(50)t.circle(-20, 80)t.begin_fill()pen(-21, 135)t.fillcolor('#d57436')t.setheading(50)t.circle(10, 280)t.setheading(50)t.circle(-10, 80)t.end_fill()t.begin_fill()pen(-24, 138)t.fillcolor('#25170a')t.setheading(50)t.circle(5)t.end_fill()# 右眼pen(60, 140)t.setheading(50)t.circle(20, 280)t.setheading(50)t.circle(-20, 80)t.begin_fill()pen(47, 143)t.fillcolor('#d57436')t.setheading(50)t.circle(10, 280)t.setheading(50)t.circle(-10, 80)t.end_fill()t.begin_fill()pen(43, 146)t.fillcolor('#25170a')t.setheading(50)t.circle(5)t.end_fill()
全部代码
下面就是全部代码了,喜欢可以直接拿去,需要下载turtle库,然后运行就可以执行。
没有图片,不知道为什么放上图片就显示违规,可能是版权冲突导致的。
import turtle as tp = t.pen()
t.hideturtle()t.colormode(255) # 颜色模式
t.speed(0)
t.screensize(800, 800, "#e7f1fb") # 画布大小背景颜色
t.setup(width=800, height=800, startx=None, starty=None) # 绘图窗口的大小和起始坐标
# t.bgpic("di_2_800.gif")
t.title("可爱的混沌皮") # 设置绘图窗口的标题
t.resizemode('no-resize') # 大小调整模式:auto,user,noresize
t.tracer(1)
t.hideturtle()def pen(x, y):# 提笔t.penup()# 位移t.goto(x, y)# 落笔t.pendown()def face(x, y):# 身体t.begin_fill()t.fillcolor("#f7fbfe")t.pensize(3)t.begin_fill()pen(100, 100)# 设置海龟的方向t.setheading(90)t.circle(100, 180)t.setheading(230)t.circle(-300, 40)t.circle(40, 80)t.circle(10, 60)t.setheading(330)t.circle(-700, 30)t.setheading(55)t.circle(-700, 35)t.circle(10, 90)t.circle(100, 30)t.setheading(154)t.circle(-1080, 10)t.end_fill()t.setheading(190)t.circle(100, 30)t.circle(-100, 30)t.circle(-90, 40)t.setheading(130)t.circle(100, 30)# 左眼pen(-20, 130)t.setheading(50)t.circle(20, 280)t.setheading(50)t.circle(-20, 80)t.begin_fill()pen(-21, 135)t.fillcolor('#d57436')t.setheading(50)t.circle(10, 280)t.setheading(50)t.circle(-10, 80)t.end_fill()t.begin_fill()pen(-24, 138)t.fillcolor('#25170a')t.setheading(50)t.circle(5)t.end_fill()# 右眼pen(60, 140)t.setheading(50)t.circle(20, 280)t.setheading(50)t.circle(-20, 80)t.begin_fill()pen(47, 143)t.fillcolor('#d57436')t.setheading(50)t.circle(10, 280)t.setheading(50)t.circle(-10, 80)t.end_fill()t.begin_fill()pen(43, 146)t.fillcolor('#25170a')t.setheading(50)t.circle(5)t.end_fill()# 嘴t.begin_fill()pen(1, 110)t.fillcolor('#ce545f')t.setheading(-20)t.circle(30, 60)t.setheading(290)t.circle(-15, 199)t.end_fill()# 左眉毛t.pensize(8)t.color('#3f383b')pen(-30, 177)t.fillcolor('#ce545f')t.setheading(180)t.circle(30, 45)# 右眉毛t.pensize(8)t.color('#3f383b')pen(40, 185)t.fillcolor('#ce545f')t.setheading(160)t.circle(30, 45)# 头巾t.color('#3e3739')t.pensize(8)pen(45, 190)t.setheading(165)t.circle(140, 50)# 足球pen(-210, -30)t.pensize(3)t.circle(28)t.circle(28, 15)t.left(56)t.fd(15)t.right(56)t.fd(15)t.left(56)t.circle(28, 15)t.left(56)t.fd(15)t.right(56)t.fd(15)t.left(56)t.circle(28, 15)t.left(56)t.fd(15)t.right(56)t.fd(15)t.left(56)t.circle(28, 15)t.left(56)t.fd(15)t.right(56)t.fd(15)t.left(56)t.circle(28, 15)t.left(56)t.fd(15)t.right(56)t.fd(15)t.right(180)t.fd(15)t.right(62)t.fd(10)t.left(45)t.fd(11)t.left(77)t.fd(11)t.left(180)t.fd(11)t.left(30)t.fd(11)t.left(90)t.fd(9.1)t.left(180)t.fd(9)t.left(15)t.fd(11)t.left(90)t.fd(7.1)t.left(180)t.fd(7.1)t.left(15)t.fd(11)t.left(77)t.fd(9)t.left(180)t.fd(9)t.left(41)t.fd(10)def main():face(-132, 115)if __name__ == '__main__':main()
t.mainloop()
代码中有的借鉴一些大佬,第一次用海龟画东西,一个新的尝试。
好了以上就是全部内容,如果觉得我做的还可以请留下你的赞。
感谢您的观看。

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
