今年社交平台上最受欢迎的销售女王是谁?范冰冰?杨幂? ?不,这是小猪佩奇,小猪佩奇。
如果你经常使用抖音、快手、哔哩哔哩、知乎、微博……或者任何类似的内容或社交平台,那么你大概率可以回答这个问题:
答案是:掌声是给社会上的人的。
凭借这句口号,小猪佩奇这位社交人物似乎一夜之间就在短视频平台和社交网络上走红。与此同时,网络上流传着小猪佩奇的九步画法。于是儿童节就画了,结果简直不忍直视……
我画的,哈哈
人物画
观察这张图,我们可以发现,小猪佩奇的构图基本上是各种曲线,比如抛物线状、圆形、椭圆形、二次贝塞尔曲线等。我这里说的是“阶级”,这也是《小猪佩奇》构图的精髓,是手绘风格而不是标准的死板线条。说到前端技术选型,画图第一个想到的就是svg,不过他们擅长画图,而且有在线编辑svg的在线工具。这很无聊,我想佩奇不会同意。所以我想纯粹地做,这会更具挑战性,因为绘制图形曲线不是我擅长的。
基本思路:选择画板的大小,设置画笔的颜色和粗细,摆好位置,依次画出鼻子、头、耳朵、眼睛、脸颊、嘴巴、身体、手脚、尾巴。
众所周知,是一个内置的有趣模块,俗称海龟画图。它是基于模块构建的,并提供了一些简单的绘图工具。
在乌龟绘图中,我们可以编写指令让虚拟(想象的)乌龟在屏幕上来回移动。这只乌龟带着一支笔,我们可以让乌龟用这支笔在它移动的任何地方画线。通过编写代码让乌龟以各种炫酷的图案移动,我们可以画出令人惊叹的图画。使用海龟映射,我们不仅可以用几行代码创建令人印象深刻的视觉效果,而且我们还可以跟随海龟来查看每行代码如何影响它的运动。这可以帮助我们理解代码的逻辑。因此,乌龟画法经常被作为新手学习的一种方式。更详细的功能和知识请参考:
官方文档:
了解了用法之后就可以开始实战了。哈哈,我们先看一下效果视频:
详细代码如下:
#coding:utf-8
from turtle import *
def nose(x,y):#鼻子
penup()#提起笔
goto(x,y)#定位
pendown()#落笔,开始画
setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)
begin_fill()#准备开始填充图形
a=0.4
for i in range(120):
if 0<=i<30 or 60<=i<90:
a=a+0.08
left(3) #向左转3度
forward(a) #向前走a的步长
else:
a=a-0.08
left(3)
forward(a)
end_fill()#填充完成
penup()
setheading(90)
forward(25)
setheading(0)
forward(10)
pendown()
pencolor(255,155,192)#画笔颜色
setheading(10)
begin_fill()
circle(5)
color(160,82,45)#返回或设置pencolor和fillcolor
end_fill()
penup()
setheading(0)
forward(20)
pendown()
pencolor(255,155,192)
setheading(10)
begin_fill()
circle(5)
color(160,82,45)
end_fill()
def head(x,y):#头
color((255,155,192),"pink")
penup()
goto(x,y)
setheading(0)
pendown()
begin_fill()
setheading(180)
circle(300,-30)
circle(100,-60)
circle(80,-100)
circle(150,-20)
circle(60,-95)
setheading(161)
circle(-300,15)
penup()
goto(-100,100)
pendown()
setheading(-30)
a=0.4
for i in range(60):
if 0<=i<30 or 60<=i<90:
a=a+0.08
lt(3) #向左转3度
fd(a) #向前走a的步长
else:
a=a-0.08
lt(3)
fd(a)
end_fill()
def ears(x,y): #耳朵
color((255,155,192),"pink")
penup()
goto(x,y)
pendown()
begin_fill()
setheading(100)
circle(-50,50)
circle(-10,120)
circle(-50,54)
end_fill()
penup()
setheading(90)
forward(-12)
setheading(0)
forward(30)
pendown()
begin_fill()
setheading(100)
circle(-50,50)
circle(-10,120)
circle(-50,56)
end_fill()
def eyes(x,y):#眼睛
color((255,155,192),"white")
penup()
setheading(90)
forward(-20)
setheading(0)
forward(-95)
pendown()
begin_fill()
circle(15)
end_fill()
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
color((255,155,192),"white")
penup()
seth(90)
forward(-25)
seth(0)
forward(40)
pendown()
begin_fill()
circle(15)
end_fill()
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
def cheek(x,y):#腮
color((255,155,192))
penup()
goto(x,y)
pendown()
setheading(0)
begin_fill()
circle(30)
end_fill()
def mouth(x,y): #嘴
color(239,69,19)
penup()
goto(x,y)
pendown()
setheading(-80)
circle(30,40)
circle(40,80)
def setting(): #参数设置
pensize(4)
hideturtle() #使乌龟无形(隐藏)
colormode(255) #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内
color((255,155,192),"pink")
setup(840,500)
speed(10)
def main():
setting() #画布、画笔设置
nose(-100,100) #鼻子
head(-69,167) #头
ears(0,160) #耳朵
eyes(0,140) #眼睛
cheek(80,10) #腮
mouth(-20,30) #嘴
done()
if __name__ == '__main__':
main()
思路其实很简单,就是通过模块来实现基本的圆、椭圆、曲线等。难点在于如何定位各个部分的位置(建议先画草图)。完整的代码需要300行。限于篇幅,仅包含部分代码。只画了小猪佩奇的头。你能完成吗?
需要完整源码的朋友可以在活动后台回复小猪佩奇获取。
(超过)