情人节,我表白了CSDN小姐姐后,竟然...【为表白写了一个绘图工具,让我不再手残】

2022-01-06 09:56:30 浏览数 (2)

情人节,我表白了CSDN小姐姐后,竟然…竟然有人看了这篇文。 以下图片素材由一个还没写完的工具绘制,稍后会放在CSDN的代码仓库(现在能用了,还没时间改,颜色填充算法还没写,有能力的朋友可以修改一下):https://codechina.csdn.net/A757291228/draw_pixel/-/tree/master

无情!竟然告诉我有情人节活动

很快呀,啪的一下又一年情人节又来了,本来我压根记不住的,但是CSDN竟然告诉我有情人节活动。怎么办?这不能忍,那就只能表白CSDN的小姐姐了。你们要不要一起表白?评论区一起表白吧!

表白肯定要写写情书了。结果…一看征文字数要求,竟然600字!你是看不起我吗? 一封情书根本用不到600字,我200字就写完了。为什么才写200字?不要问,问就是是写不出来600字。

我们要表白哪个小姐姐?

这还要想?当然是全都要了!小孩子才做选择。 例如小婷婷、小慧慧,这可都是集美貌、才华于一身的女子。

沉鱼落雁 小婷婷 闭月羞花 小慧慧

小婷婷是谁?小婷婷就是前几天博客之星直播中的主持之一!还记得的弹幕中刷屏的“小婷露脸 流量百万”吗?在CSDN社群中有一个付费专栏群,小婷婷可是付费专栏群中的第一女神。只要小婷婷在线,群里必是最热闹的时候。

那小慧慧又是谁?在微信群中,有一个经常公布信息,到处活跃的运营还记得吗?名字叫做CSDN博客。她就是小慧慧。小慧慧时而性格温柔,时而高冷,就像一个冰雪女王!气质十足!

那怎么样表白这两个小姐姐呢?当然是…写!代!码!生为一个程序直男一定要把这优点发扬光大!

表白CSDN来一幅图~

颜色填充还没写完,不然肯定这图片是漂漂亮亮dev~

一、技术实现(这个工具我本人会不断的迭代更新,包括素材绘制逻辑,因为我要用来画自媒体素材)

毕竟是要画画,首选比较简单的那就是turtle了。但是turtle画东西好麻烦,本身自己就是个手残党,线条都不懂怎么弄。那怎么办?那我们就是用“俄罗斯方块”的画法吧,那就是叠积木~

我们以方块作为线条,进行堆叠就可以完成了。

1.1 完成点绘制

我们先引入turtle库,然后新建一个类,名为core:

代码语言:javascript复制
from turtle import *

class Core:

随后新建一个core类的方法point,作为基本的方块点,作为一个线条的基本单位:

代码语言:javascript复制
	'''
    设置
    '''
    #填充颜色色值
    #@fcolor=点填充颜色
    def fillcolor_set(self,fcolor="black"):
        fillcolor(fcolor)
    
    #笔杆颜色设置
    #@fcolor=点填充颜色
    #@pcolor=线颜色
    def pencolor_set(self,fcolor="black",pcolor="1"):
        if pcolor=="1":
            pcolor=fcolor
            pencolor(pcolor)
        else:
            pencolor(pcolor)
    
    #笔杆尺寸
    #@psize=线尺寸
    def pensize_set(self,psize=1):
        pensize(psize)
    
	#绘制点
    #@plenght=点长度
    #@fcolor=点填充颜色
    #@pcolor=线颜色
    #@psize=线尺寸
    def point(self,plenght=10,fcolor="black",pcolor="1",psize=1):
        poslist=[]
        self.fillcolor_set(fcolor)
        self.pencolor_set(fcolor,pcolor)
        self.pensize_set(psize)
        begin_fill()
        for i in range(0,4):
            poslist.append(pos())
            fd(plenght)
            right(90)
        end_fill()
        return poslist

point方法默认plenght为10。也就是说基本方块为一个正方形,长宽都为plenght;fcolor为填充的颜色,默认为黑色;pcolor为线条的颜色,其实也就是pen color;psize为相对应的笔的粗细。

在方法中,我们使用poslist记录我们点的每次绘制的位置,这样的话我们在某些时候就可以使用poslist来进行精确定位了。我们再通过fillcolor_set、pencolor_set、pensize_set方法来设置填充色、线条色、现调大小。

在正式绘制方块时开启填充使用begin_fill方法,随后开始绘制一个“点”。这个“点”的绘制也是非常简单,直接循环4次,画出一个矩形即可。并且使用pos方法获取当前的坐标,随后结束绘制“点”后使用end_fill方法进行颜色填充。

这样一个点绘制的方法就完成了。

1.2 完成线段的绘制

点绘制完了接下来我们就需要绘制线了。线从点的基础上进行堆叠,并排排列那就是线。线的方向可以是上下左右,我们可以通过参数传递从而控制线段绘制方向,并且还可以使用对称方法,让我们减少绘制难度。对于对称来说,也有上下左右基于某个中心点的进行的中心对称。 代码如下:

代码语言:javascript复制
	#step方法的绘图跳转控制
    #@lenght=总长
    #@blenght=bit一个位长度
    #@plenght=点长度
    #@direction1=横线绘制方向
    #@direction2=竖线绘制方向
    #@fcolor=填充颜色
    #@pcolor=笔颜色
    #@psize=笔大小
    #@gotopos=如何跳转pos位置
    #@cout_i=循环控制变量i
    def step_control_func_draw_move(self,lenght,blenght,plenght,direction1,direction2,fcolor,pcolor,psize,gotopos1,gotopos2,cout_i,height):
        print('-----------',blenght)
        posdict={}
        posdict['line' str(cout_i)]=self.line(lenght=blenght,plenght=plenght,direction=direction1,fcolor=fcolor,pcolor=pcolor,psize=psize)
        self.loc_goto(gotopos1)
        posdict['vline' str(cout_i)]=self.line(lenght=height,plenght=plenght,direction=direction2,fcolor=fcolor,pcolor=pcolor,psize=psize)
        if cout_i!=(lenght-1):
            self.loc_goto(gotopos2)
        return posdict
        
	#绘制线段
    #@lenght=线长度
    #@plenght=点长度
    #@fcolor=点填充颜色
    #@pcolor=线颜色
    #@psize=线尺寸
    def line(self,lenght=1,plenght=10,direction="right",fcolor="white",pcolor="1",psize=1,symmetrical="f",symmetrical_direction="right"):
        posdict={}

        symmetrical_point="f"
        if symmetrical!="f":
            if symmetrical_direction=="right":
                symmetrical_point=pos() (int(symmetrical)*plenght,0)
            elif symmetrical_direction=="left":
                symmetrical_point=pos() (-int(symmetrical)*plenght,0)
            elif symmetrical_direction=="up":
                symmetrical_point=pos() (0,int(symmetrical)*plenght)
            elif symmetrical_direction=="down":
                symmetrical_point=pos() (0,-int(symmetrical)*plenght)
        for i in range(0,lenght):
            posdict['point' str(i)]=self.point(plenght=plenght,fcolor=fcolor,pcolor=pcolor,psize=psize)
            self.line_control_func_draw_move(i,direction,lenght,plenght)
        if symmetrical!="f":
            self.goto_(symmetrical_point)
            posdict['symmetrical_point']=self.line(lenght=lenght,plenght=plenght,direction=direction,fcolor=fcolor,pcolor=pcolor,psize=psize,symmetrical="f")
            self.goto_(posdict['point' str(lenght-1)][3])
        return posdict    

以上代码我们主要看line方法。line方法参数plenght为需要传入的点的边长大小,lenght为这个线有多长;direction为需要从哪边开始绘制,从左到右绘制,还是从上到下绘制;symmetrical为对称的位置,symmetrical_direction表示是左右对称,还是右坐对称;symmetrical_direction默认为右,表示左边的绘制线段,将会镜像到左侧,若symmetrical为10,那么对称位置就是10*边长大小为对称位置。

我们接下来看line方法中的代码,其中symmetrical_point默认为f,若symmetrical传入参数则表示有对称需求,这时将会通过传入对称位置从而计算x与y的坐标:

代码语言:javascript复制
symmetrical_point="f"
        if symmetrical!="f":
            if symmetrical_direction=="right":
                symmetrical_point=pos() (int(symmetrical)*plenght,0)
            elif symmetrical_direction=="left":
                symmetrical_point=pos() (-int(symmetrical)*plenght,0)
            elif symmetrical_direction=="up":
                symmetrical_point=pos() (0,int(symmetrical)*plenght)
            elif symmetrical_direction=="down":
                symmetrical_point=pos() (0,-int(symmetrical)*plenght)

其中左右对称,那么就是左右两边x的正负,如果是上下对称则需要对y进行操作,上对称y则正,下对称则y负。随后我们开始进行循环点的个数,多长就循环多少次:

代码语言:javascript复制
for i in range(0,lenght):
            posdict['point' str(i)]=self.point(plenght=plenght,fcolor=fcolor,pcolor=pcolor,psize=psize)
            self.line_control_func_draw_move(i,direction,lenght,plenght)

以上代码主要查看line_control_func_draw_move方法。line_control_func_draw_move作为控制线段绘制的方法,而point就直接绘制出一个点,如何使绘制开始位置进行控制,就需要查看line_control_func_draw_move:

代码语言:javascript复制
def line_control_func_draw_move(self,cout_i,direction,lenght,plenght):
        if cout_i!=(lenght-1):
            if direction=="right":
                self.loc_goto((plenght,0))
            elif direction=="left":
                self.loc_goto((-plenght,0))
            elif direction=="up":
                self.loc_goto((0,plenght))
            elif direction=="down":
                self.loc_goto((0,-plenght))
        elif cout_i==(lenght-1):
            if direction=="left":
                self.loc_goto((plenght,0))
            if direction=="up":
                self.loc_goto((0,-plenght))

line_control_func_draw_move中,如果是从左往右绘制,只需要通过loc_goto方法直接跳转到当前位置增加1个基本单位plenght处即可完成下一个绘制位置的控制,loc_goto方法如下:

代码语言:javascript复制
	#跳转
    def loc_goto(self,movepos):
        penup()
        goto(pos() movepos)
        pendown()

最后,我们查看对称线段的如何绘制,代码如下:

代码语言:javascript复制
if symmetrical!="f":
            self.goto_(symmetrical_point)
            posdict['symmetrical_point']=self.line(lenght=lenght,plenght=plenght,direction=direction,fcolor=fcolor,pcolor=pcolor,psize=psize,symmetrical="f")
            self.goto_(posdict['point' str(lenght-1)][3])

其实对称线段绘制就很简单了,直接传入需要从哪个点开始绘制,随后调用line方法就可以了,这个时候关闭对称参数即可。

1.3 完成阶梯的绘制

在方块堆叠的实现的内容中,绘制出来的效果更像是马赛克风格的图像,那么阶梯的绘制是较为常见的。代码如下:

代码语言:javascript复制
	#step方法的绘图跳转控制
    #@lenght=总长
    #@blenght=bit一个位长度
    #@plenght=点长度
    #@direction1=横线绘制方向
    #@direction2=竖线绘制方向
    #@fcolor=填充颜色
    #@pcolor=笔颜色
    #@psize=笔大小
    #@gotopos=如何跳转pos位置
    #@cout_i=循环控制变量i
    def step_control_func_draw_move(self,lenght,blenght,plenght,direction1,direction2,fcolor,pcolor,psize,gotopos1,gotopos2,cout_i,height):
        print('-----------',blenght)
        posdict={}
        posdict['line' str(cout_i)]=self.line(lenght=blenght,plenght=plenght,direction=direction1,fcolor=fcolor,pcolor=pcolor,psize=psize)
        self.loc_goto(gotopos1)
        posdict['vline' str(cout_i)]=self.line(lenght=height,plenght=plenght,direction=direction2,fcolor=fcolor,pcolor=pcolor,psize=psize)
        if cout_i!=(lenght-1):
            self.loc_goto(gotopos2)
        return posdict
        
	#绘制线段
    #@lenght=线长度
    #@height=线高度
    #@blenght=bit一个位长度
    #@plenght=点长度
    #@fcolor=点填充颜色
    #@pcolor=线颜色
    #@psize=线尺寸
    def step(self,lenght=1,height=1,blenght=1,plenght=10,direction="right",fcolor="black",pcolor="1",psize=1,symmetrical="f",symmetrical_direction="right"):
        posdict={}
        symmetrical_point="f"
        symmetrical_draw_direction=''
        if symmetrical!="f":
            if symmetrical_direction=="right":
                symmetrical_point=pos() (int(symmetrical)*plenght,0)
                if direction=="right":
                    symmetrical_draw_direction="left"
                elif direction=="left":
                    symmetrical_draw_direction="right"
                elif direction=="rightdown":
                    symmetrical_draw_direction="leftdown"
                elif direction=="leftdown":
                    symmetrical_draw_direction="rightdown"
            elif symmetrical_direction=="left":
                symmetrical_point=pos() (-int(symmetrical)*plenght,0)
                if direction=="right":
                    symmetrical_draw_direction="left"
                elif direction=="left":
                    symmetrical_draw_direction="right"
                elif direction=="rightdown":
                    symmetrical_draw_direction="leftdown"
                elif direction=="leftdown":
                    symmetrical_draw_direction="rightdown"
            elif symmetrical_direction=="rightdown":
                symmetrical_point=pos() (0,int(symmetrical)*plenght)
                if direction=="right":
                    symmetrical_draw_direction="left"
                elif direction=="left":
                    symmetrical_draw_direction="right"
                elif direction=="rightdown":
                    symmetrical_draw_direction="leftdown"
                elif direction=="leftdown":
                    symmetrical_draw_direction="rightdown"
            elif symmetrical_direction=="leftdown":
                symmetrical_point=pos() (0,-int(symmetrical)*plenght)
                if direction=="right":
                    symmetrical_draw_direction="left"
                elif direction=="left":
                    symmetrical_draw_direction="right"
                elif direction=="rightdown":
                    symmetrical_draw_direction="leftdown"
                elif direction=="leftdown":
                    symmetrical_draw_direction="rightdown"

        for i in range(0,lenght):
            if direction=="right":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,direction,"up",fcolor,pcolor,psize,(plenght,plenght),(plenght,plenght*2),i,height)
            elif direction=="left":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"left","up",fcolor,pcolor,psize,(-plenght*2,plenght),(-plenght,plenght*2),i,height)
            elif direction=="rightdown":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"right","down",fcolor,pcolor,psize,(plenght,-plenght),(plenght,-plenght),i,height)
            elif direction=="leftdown":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"left","down",fcolor,pcolor,psize,(-plenght*2,-plenght),(-plenght,-plenght),i,height)
        #对称
        if symmetrical!="f":
            self.goto_(symmetrical_point)
            posdict['symmetrical_step']=self.step(lenght=lenght,height=height,blenght=blenght,plenght=plenght,direction=symmetrical_draw_direction,fcolor=fcolor,pcolor=pcolor,psize=psize)
            print(posdict)
            self.goto_(posdict['step' str(lenght-1)]['vline' str(lenght-1)]['point' str(height-1)][0])
        
        return posdict

其实阶梯的绘制方法跟线段原理是一致的。首先看一下绘制控制:

代码语言:javascript复制
for i in range(0,lenght):
            if direction=="right":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,direction,"up",fcolor,pcolor,psize,(plenght,plenght),(plenght,plenght*2),i,height)
            elif direction=="left":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"left","up",fcolor,pcolor,psize,(-plenght*2,plenght),(-plenght,plenght*2),i,height)
            elif direction=="rightdown":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"right","down",fcolor,pcolor,psize,(plenght,-plenght),(plenght,-plenght),i,height)
            elif direction=="leftdown":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"left","down",fcolor,pcolor,psize,(-plenght*2,-plenght),(-plenght,-plenght),i,height)

阶梯的绘制方向我们有左上、左下、右上和右下,这个时候直接判断绘制内容,随后使用控制方法控制即可:

代码语言:javascript复制
	#step方法的绘图跳转控制
    #@lenght=总长
    #@blenght=bit一个位长度
    #@plenght=点长度
    #@direction1=横线绘制方向
    #@direction2=竖线绘制方向
    #@fcolor=填充颜色
    #@pcolor=笔颜色
    #@psize=笔大小
    #@gotopos=如何跳转pos位置
    #@cout_i=循环控制变量i
    def step_control_func_draw_move(self,lenght,blenght,plenght,direction1,direction2,fcolor,pcolor,psize,gotopos1,gotopos2,cout_i,height):
        print('-----------',blenght)
        posdict={}
        posdict['line' str(cout_i)]=self.line(lenght=blenght,plenght=plenght,direction=direction1,fcolor=fcolor,pcolor=pcolor,psize=psize)
        self.loc_goto(gotopos1)
        posdict['vline' str(cout_i)]=self.line(lenght=height,plenght=plenght,direction=direction2,fcolor=fcolor,pcolor=pcolor,psize=psize)
        if cout_i!=(lenght-1):
            self.loc_goto(gotopos2)
        return posdict

控制方法此时就不像线段那样只移动一个坐标位置,阶梯需要x和y坐标都进行增删才可以实现,同理可得就不再赘述内容了。

1.4完整的core类代码

至此,完整的core类基本代码就已经写完了,代码如下:

代码语言:javascript复制
from turtle import *

class Core:
    '''
    设置
    '''
    #填充颜色色值
    #@fcolor=点填充颜色
    def fillcolor_set(self,fcolor="black"):
        fillcolor(fcolor)
    
    #笔杆颜色设置
    #@fcolor=点填充颜色
    #@pcolor=线颜色
    def pencolor_set(self,fcolor="black",pcolor="1"):
        if pcolor=="1":
            pcolor=fcolor
            pencolor(pcolor)
        else:
            pencolor(pcolor)
    
    #笔杆尺寸
    #@psize=线尺寸
    def pensize_set(self,psize=1):
        pensize(psize)
    
    '''
    other func 
    '''
    #跳转
    def loc_goto(self,movepos):
        penup()
        goto(pos() movepos)
        pendown()

    def goto_(self,pos_):
        penup()
        goto(pos_)
        pendown()
    #line方法的绘图跳转控制
    def line_control_func_draw_move(self,cout_i,direction,lenght,plenght):
        if cout_i!=(lenght-1):
            if direction=="right":
                self.loc_goto((plenght,0))
            elif direction=="left":
                self.loc_goto((-plenght,0))
            elif direction=="up":
                self.loc_goto((0,plenght))
            elif direction=="down":
                self.loc_goto((0,-plenght))
        elif cout_i==(lenght-1):
            if direction=="left":
                self.loc_goto((plenght,0))
            if direction=="up":
                self.loc_goto((0,-plenght))
    #step方法的绘图跳转控制
    #@lenght=总长
    #@blenght=bit一个位长度
    #@plenght=点长度
    #@direction1=横线绘制方向
    #@direction2=竖线绘制方向
    #@fcolor=填充颜色
    #@pcolor=笔颜色
    #@psize=笔大小
    #@gotopos=如何跳转pos位置
    #@cout_i=循环控制变量i
    def step_control_func_draw_move(self,lenght,blenght,plenght,direction1,direction2,fcolor,pcolor,psize,gotopos1,gotopos2,cout_i,height):
        print('-----------',blenght)
        posdict={}
        posdict['line' str(cout_i)]=self.line(lenght=blenght,plenght=plenght,direction=direction1,fcolor=fcolor,pcolor=pcolor,psize=psize)
        self.loc_goto(gotopos1)
        posdict['vline' str(cout_i)]=self.line(lenght=height,plenght=plenght,direction=direction2,fcolor=fcolor,pcolor=pcolor,psize=psize)
        if cout_i!=(lenght-1):
            self.loc_goto(gotopos2)
        return posdict
    '''
    绘制
    '''
    #绘制点
    #@plenght=点长度
    #@fcolor=点填充颜色
    #@pcolor=线颜色
    #@psize=线尺寸
    def point(self,plenght=10,fcolor="black",pcolor="1",psize=1):
        poslist=[]
        self.fillcolor_set(fcolor)
        self.pencolor_set(fcolor,pcolor)
        self.pensize_set(psize)
        begin_fill()
        for i in range(0,4):
            poslist.append(pos())
            fd(plenght)
            right(90)
        end_fill()
        return poslist
        
    #绘制线段
    #@lenght=线长度
    #@plenght=点长度
    #@fcolor=点填充颜色
    #@pcolor=线颜色
    #@psize=线尺寸
    def line(self,lenght=1,plenght=10,direction="right",fcolor="white",pcolor="1",psize=1,symmetrical="f",symmetrical_direction="right"):
        posdict={}

        symmetrical_point="f"
        if symmetrical!="f":
            if symmetrical_direction=="right":
                symmetrical_point=pos() (int(symmetrical)*plenght,0)
            elif symmetrical_direction=="left":
                symmetrical_point=pos() (-int(symmetrical)*plenght,0)
            elif symmetrical_direction=="up":
                symmetrical_point=pos() (0,int(symmetrical)*plenght)
            elif symmetrical_direction=="down":
                symmetrical_point=pos() (0,-int(symmetrical)*plenght)
        for i in range(0,lenght):
            posdict['point' str(i)]=self.point(plenght=plenght,fcolor=fcolor,pcolor=pcolor,psize=psize)
            self.line_control_func_draw_move(i,direction,lenght,plenght)
        if symmetrical!="f":
            self.goto_(symmetrical_point)
            posdict['symmetrical_point']=self.line(lenght=lenght,plenght=plenght,direction=direction,fcolor=fcolor,pcolor=pcolor,psize=psize,symmetrical="f")
            self.goto_(posdict['point' str(lenght-1)][3])
        return posdict    

    #绘制线段
    #@lenght=线长度
    #@height=线高度
    #@blenght=bit一个位长度
    #@plenght=点长度
    #@fcolor=点填充颜色
    #@pcolor=线颜色
    #@psize=线尺寸
    def step(self,lenght=1,height=1,blenght=1,plenght=10,direction="right",fcolor="black",pcolor="1",psize=1,symmetrical="f",symmetrical_direction="right"):
        posdict={}
        symmetrical_point="f"
        symmetrical_draw_direction=''
        if symmetrical!="f":
            if symmetrical_direction=="right":
                symmetrical_point=pos() (int(symmetrical)*plenght,0)
                if direction=="right":
                    symmetrical_draw_direction="left"
                elif direction=="left":
                    symmetrical_draw_direction="right"
                elif direction=="rightdown":
                    symmetrical_draw_direction="leftdown"
                elif direction=="leftdown":
                    symmetrical_draw_direction="rightdown"
            elif symmetrical_direction=="left":
                symmetrical_point=pos() (-int(symmetrical)*plenght,0)
                if direction=="right":
                    symmetrical_draw_direction="left"
                elif direction=="left":
                    symmetrical_draw_direction="right"
                elif direction=="rightdown":
                    symmetrical_draw_direction="leftdown"
                elif direction=="leftdown":
                    symmetrical_draw_direction="rightdown"
            elif symmetrical_direction=="rightdown":
                symmetrical_point=pos() (0,int(symmetrical)*plenght)
                if direction=="right":
                    symmetrical_draw_direction="left"
                elif direction=="left":
                    symmetrical_draw_direction="right"
                elif direction=="rightdown":
                    symmetrical_draw_direction="leftdown"
                elif direction=="leftdown":
                    symmetrical_draw_direction="rightdown"
            elif symmetrical_direction=="leftdown":
                symmetrical_point=pos() (0,-int(symmetrical)*plenght)
                if direction=="right":
                    symmetrical_draw_direction="left"
                elif direction=="left":
                    symmetrical_draw_direction="right"
                elif direction=="rightdown":
                    symmetrical_draw_direction="leftdown"
                elif direction=="leftdown":
                    symmetrical_draw_direction="rightdown"

        for i in range(0,lenght):
            if direction=="right":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,direction,"up",fcolor,pcolor,psize,(plenght,plenght),(plenght,plenght*2),i,height)
            elif direction=="left":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"left","up",fcolor,pcolor,psize,(-plenght*2,plenght),(-plenght,plenght*2),i,height)
            elif direction=="rightdown":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"right","down",fcolor,pcolor,psize,(plenght,-plenght),(plenght,-plenght),i,height)
            elif direction=="leftdown":
                posdict["step" str(i)]=self.step_control_func_draw_move(lenght,blenght,plenght,"left","down",fcolor,pcolor,psize,(-plenght*2,-plenght),(-plenght,-plenght),i,height)
        #对称
        if symmetrical!="f":
            self.goto_(symmetrical_point)
            posdict['symmetrical_step']=self.step(lenght=lenght,height=height,blenght=blenght,plenght=plenght,direction=symmetrical_draw_direction,fcolor=fcolor,pcolor=pcolor,psize=psize)
            print(posdict)
            self.goto_(posdict['step' str(lenght-1)]['vline' str(lenght-1)]['point' str(height-1)][0])
        
        return posdict

1.5再次封装,逻辑绘图

但是我们的绘制方法需要自己敲代码,是不是觉得很麻烦?我们那么懒,那么就再写个方法封装一下,让我们直接使用比较轻松的方式进行线段绘制吧。新建一个文件,叫做drawTools,引入core类以及turtle:

代码语言:javascript复制
from core import Core
from turtle import *

我们新建一个类,继承Core,叫做Tools:

代码语言:javascript复制
class Tools(Core):

我们甚至可以直接做辅助线,如何做?很简单,画格子就可以了,直接把辅助线的绘制方法写在init方法中吧:

代码语言:javascript复制
width,height=0,0
    def __init__(self,open=False,helperline='red'):
        
        width=window_width()
        height=window_height()
        #行列
        lines=int(height/10)
        rows=int(width/10)
        #左上角
        leftx=-int(width/2)
        topy=int(height/2)
        self.goto_((leftx,topy))
        if open==True:
            for l in range(lines):
                nowpos=pos()-(0,0)
                self.line(rows,10,pcolor=helperline)
                topy-=10
                self.goto_((leftx,topy))
            qx,qy=-160,160
            self.goto_((qx,qy))
            for l in range(32):
                nowpos=pos()-(0,0)
                self.line(32,10,pcolor="blue")
                qy-=10
                self.goto_((qx,qy))
            qx,qy=-80,80
            self.goto_((qx,qy))
            for l in range(16):
                nowpos=pos()-(0,0)
                self.line(16,10,pcolor="green")
                qy-=10
                self.goto_((qx,qy))
            qx,qy=-20,20
            self.goto_((qx,qy))
            for l in range(4):
                nowpos=pos()-(0,0)
                self.line(4,10,pcolor="red")
                qy-=10
                self.goto_((qx,qy))
            self.goto_((0,0))

init接收2个参数,一个是open,决定是否开启辅助线,helperline则是辅助线的颜色。 我们首先需要获取整个canvas画布的长宽,以及我们辅助线可以有多长,还有就是左上角绘制起始点的位置,随后跳到该位置准备进行绘制:

代码语言:javascript复制
		width=window_width()
        height=window_height()
        #行列
        lines=int(height/10)
        rows=int(width/10)
        #左上角
        leftx=-int(width/2)
        topy=int(height/2)
        self.goto_((leftx,topy))

随后就是简单的代码进行画格子了,为了比较清晰,我们可以分别用不同颜色进行区分:

代码语言:javascript复制
if open==True:
            for l in range(lines):
                nowpos=pos()-(0,0)
                self.line(rows,10,pcolor=helperline)
                topy-=10
                self.goto_((leftx,topy))
            qx,qy=-160,160
            self.goto_((qx,qy))
            for l in range(32):
                nowpos=pos()-(0,0)
                self.line(32,10,pcolor="blue")
                qy-=10
                self.goto_((qx,qy))
            qx,qy=-80,80
            self.goto_((qx,qy))
            for l in range(16):
                nowpos=pos()-(0,0)
                self.line(16,10,pcolor="green")
                qy-=10
                self.goto_((qx,qy))
            qx,qy=-20,20
            self.goto_((qx,qy))
            for l in range(4):
                nowpos=pos()-(0,0)
                self.line(4,10,pcolor="red")
                qy-=10
                self.goto_((qx,qy))
            self.goto_((0,0))

以上代码中的qx,qy则是到达该区域后进行的不同颜色的绘制,代码没有优化,所以就将就着看着吧。(可以用我就懒了,哈哈哈)最后跳转到0,0中心点。

那么接下来我们需要使用比较简单的方式进行绘制内容了。新建一个方法叫做drawlines:

代码语言:javascript复制
#绘制线段 'length:2;direction:down;fcolor:black;pos:(0,-100);symmetrical:13'
    def drawlines(self,drawcon=[],startpos=(0,0)):
        for c in drawcon:
            c_val=c.split(';')
            length=0
            direction=''
            fcolor=''
            posv=None
            symmetrical='f'
            symmetrical_direction="right"
            line_type='line'
            for v in c_val:
                demens=v.split(':')
                if demens[0]=='length':
                    length=int(demens[1])
                elif demens[0]=='direction':
                    direction=demens[1]
                elif demens[0]=='fcolor':
                    fcolor=demens[1]
                elif demens[0]=='pos':
                    posval=demens[1].split(',')
                    posv=(int(posval[0]) startpos[0],int(posval[1]) startpos[1])
                elif demens[0]=='symmetrical':
                    symmetrical=int(demens[1])
                elif demens[0]=='symmetrical_direction':
                    symmetrical_direction=demens[1]
                elif demens[0]=='line_type':
                    line_type=demens[1]
            self.goto_(posv)
            if line_type=='line':
                self.line(length,fcolor=fcolor,direction=direction,symmetrical=symmetrical,symmetrical_direction=symmetrical_direction)

接收参数drawcon为一个列表,列表里面包含了绘制逻辑,绘制逻辑示例为:length:2;direction:down;fcolor:black;pos:(0,-100);symmetrical:13,length表示长度多少,direction表示从绘制点往下画还是往左、往右、往上画,fcolor为填充颜色yay,pos为其实绘制点,symmetrical表示对称位置,默认对称为右对称镜像。 我们的命令是使用分号进行分隔,由于我们的一张图片不止一条线段,所以我们直接使用循环遍历列表的内容。遍历内容时,使用split分隔字符即可。

代码语言:javascript复制
for c in drawcon:
            c_val=c.split(';')
            length=0
            direction=''
            fcolor=''
            posv=None
            symmetrical='f'
            symmetrical_direction="right"
            line_type='line'

以上一些变量是作为局部变量方便接下来使用而已,用法基础,内容就不再赘述了。随后使用分号进行分隔后得到一组一组的数据,例如length:2、direction:down…他们之间使用的是冒号进行分隔,那么再遍历内容,进行冒号分隔即可。这个时候获取他们的第0维度的文本就可以知道是什么数据了,随后使用局部变量赋值,最后传入到line方法中,这样的话就可以通过字符串形式调用lline方法了,而且及其简单:

代码语言:javascript复制
for v in c_val:
                demens=v.split(':')
                if demens[0]=='length':
                    length=int(demens[1])
                elif demens[0]=='direction':
                    direction=demens[1]
                elif demens[0]=='fcolor':
                    fcolor=demens[1]
                elif demens[0]=='pos':
                    posval=demens[1].split(',')
                    posv=(int(posval[0]) startpos[0],int(posval[1]) startpos[1])
                elif demens[0]=='symmetrical':
                    symmetrical=int(demens[1])
                elif demens[0]=='symmetrical_direction':
                    symmetrical_direction=demens[1]
                elif demens[0]=='line_type':
                    line_type=demens[1]
            self.goto_(posv)
            if line_type=='line':
                self.line(length,fcolor=fcolor,direction=direction,symmetrical=symmetrical,symmetrical_direction=symmetrical_direction)

1.6完整的逻辑绘图类代码

这个时候再次封装将会使我们的代码变得十分简单。完整的代码如下:

代码语言:javascript复制
from core import Core
from turtle import *

class Tools(Core):
    width,height=0,0
    def __init__(self,open=False,helperline='red'):
        
        width=window_width()
        height=window_height()
        #行列
        lines=int(height/10)
        rows=int(width/10)
        #左上角
        leftx=-int(width/2)
        topy=int(height/2)
        self.goto_((leftx,topy))
        if open==True:
            for l in range(lines):
                nowpos=pos()-(0,0)
                self.line(rows,10,pcolor=helperline)
                topy-=10
                self.goto_((leftx,topy))
            qx,qy=-160,160
            self.goto_((qx,qy))
            for l in range(32):
                nowpos=pos()-(0,0)
                self.line(32,10,pcolor="blue")
                qy-=10
                self.goto_((qx,qy))
            qx,qy=-80,80
            self.goto_((qx,qy))
            for l in range(16):
                nowpos=pos()-(0,0)
                self.line(16,10,pcolor="green")
                qy-=10
                self.goto_((qx,qy))
            qx,qy=-20,20
            self.goto_((qx,qy))
            for l in range(4):
                nowpos=pos()-(0,0)
                self.line(4,10,pcolor="red")
                qy-=10
                self.goto_((qx,qy))
            self.goto_((0,0))
    
    #绘制线段 'length:2;direction:down;fcolor:black;pos:(0,-100);symmetrical:13'
    def drawlines(self,drawcon=[],startpos=(0,0)):
        for c in drawcon:
            c_val=c.split(';')
            length=0
            direction=''
            fcolor=''
            posv=None
            symmetrical='f'
            symmetrical_direction="right"
            line_type='line'
            for v in c_val:
                demens=v.split(':')
                if demens[0]=='length':
                    length=int(demens[1])
                elif demens[0]=='direction':
                    direction=demens[1]
                elif demens[0]=='fcolor':
                    fcolor=demens[1]
                elif demens[0]=='pos':
                    posval=demens[1].split(',')
                    posv=(int(posval[0]) startpos[0],int(posval[1]) startpos[1])
                elif demens[0]=='symmetrical':
                    symmetrical=int(demens[1])
                elif demens[0]=='symmetrical_direction':
                    symmetrical_direction=demens[1]
                elif demens[0]=='line_type':
                    line_type=demens[1]
            self.goto_(posv)
            if line_type=='line':
                self.line(length,fcolor=fcolor,direction=direction,symmetrical=symmetrical,symmetrical_direction=symmetrical_direction)

1.7 实例

现在我想画个狗头,只需要编写出绘制逻辑,如下:

代码语言:javascript复制
#dog face
dog_face=[
        #耳朵
      'length:9;direction:down;fcolor:black;pos:0,0;symmetrical:20;',
      'length:2;direction:right;fcolor:black;pos:10,10;symmetrical:17;',
      'length:1;direction:right;fcolor:black;pos:30,0;symmetrical:14;',
      'length:1;direction:right;fcolor:black;pos:40,-10;symmetrical:12;',
      'length:11;direction:right;fcolor:black;pos:50,-20;',
      'length:1;direction:right;fcolor:black;pos:40,-30;symmetrical:12;',
      'length:2;direction:down;fcolor:black;pos:30,-40;symmetrical:14;',
      'length:2;direction:right;fcolor:black;pos:10,-60;symmetrical:17;',
      #脸蛋
      'length:7;direction:down;fcolor:black;pos:-10,-90;symmetrical:22;',
      'length:2;direction:down;fcolor:black;pos:0,-160;symmetrical:20;',
      'length:2;direction:right;fcolor:black;pos:10,-180;symmetrical:17;',
      'length:2;direction:down;fcolor:black;pos:30,-190;symmetrical:14;',
      'length:1;direction:down;fcolor:black;pos:40,-210;',
      'length:2;direction:right;fcolor:black;pos:150,-210;',
      'length:10;direction:right;fcolor:black;pos:50,-220;',
      #眼眶
      'length:2;direction:down;fcolor:black;pos:0,-110;symmetrical:12;',
      'length:6;direction:right;fcolor:black;pos:10,-100;symmetrical:12;',
      'length:2;direction:down;fcolor:black;pos:70,-110;symmetrical:12;',
      'length:6;direction:right;fcolor:black;pos:10,-130;symmetrical:12;',
      #眼珠
      'length:2;direction:down;fcolor:black;pos:60,-110;symmetrical:12;',
      'length:1;direction:down;fcolor:gray;pos:50,-110;symmetrical:12;',
      'length:1;direction:down;fcolor:black;pos:50,-120;symmetrical:12;',
      #鼻子嘴巴
      'length:2;direction:down;fcolor:black;pos:70,-150;symmetrical:2;',
      'length:5;direction:down;fcolor:black;pos:80,-150;',
      'length:7;direction:right;fcolor:black;pos:60,-200;',
      'length:1;direction:right;fcolor:black;pos:130,-190;',
      'length:1;direction:right;fcolor:black;pos:140,-180;',
]

然后引入库:

代码语言:javascript复制
from drawTools import Tools
from turtle import *

调用工具即可:

代码语言:javascript复制
tool=Tools()
tracer(5,1)

tool.drawlines(zan)

狗头就完成了:

再画个程序员吧:

逻辑如下:

代码语言:javascript复制
#programer
programer=[
        #头发
        'length:3;direction:right;fcolor:black;pos:0,0;',
        'length:11;direction:right;fcolor:black;pos:30,10;',
        'length:2;direction:right;fcolor:black;pos:140,0;',
        'length:1;direction:right;fcolor:black;pos:160,-10;',
        'length:3;direction:right;fcolor:black;pos:170,-20;',
        'length:4;direction:down;fcolor:black;pos:200,-30;',
        'length:2;direction:left;fcolor:black;pos:190,-70;',
        'length:2;direction:left;fcolor:black;pos:170,-80;',
        'length:5;direction:up;fcolor:black;pos:150,-70;',
        'length:2;direction:up;fcolor:black;pos:140,-70;',
        'length:3;direction:left;fcolor:black;pos:140,-70;',
        'length:3;direction:left;fcolor:black;pos:110,-80;',
        'length:1;direction:left;fcolor:black;pos:80,-70;',
        'length:2;direction:left;fcolor:black;pos:70,-80;',
        'length:1;direction:left;fcolor:black;pos:50,-70;',
        'length:3;direction:down;fcolor:black;pos:40,-60;',
        'length:4;direction:left;fcolor:black;pos:30,-80;',
        'length:5;direction:down;fcolor:black;pos:-10,-80;',#左侧脸最左侧坐标
        'length:2;direction:up;fcolor:black;pos:-20,-110;',
        'length:8;direction:up;fcolor:black;pos:-30,-100;',
        'length:1;direction:up;fcolor:black;pos:-20,-20;',
        'length:1;direction:up;fcolor:black;pos:-10,-10;',
        #脸廓
        'length:2;direction:down;fcolor:black;pos:0,-130;',
        'length:6;direction:down;fcolor:black;pos:10,-150;',
        'length:1;direction:down;fcolor:black;pos:20,-210;',
        'length:12;direction:right;fcolor:black;pos:30,-220;',
        'length:1;direction:right;fcolor:black;pos:150,-210;',
        'length:1;direction:right;fcolor:black;pos:160,-200;',
        'length:11;direction:up;fcolor:black;pos:170,-190;',
        #眼睛
        'length:4;direction:right;fcolor:black;pos:40,-105;symmetrical:8;',
        #眉毛
        'length:2;direction:down;fcolor:black;pos:70,-125;symmetrical:5;',
        #嘴巴
        'length:2;direction:down;fcolor:black;pos:50,-175;symmetrical:8;',
        'length:2;direction:down;fcolor:black;pos:50,-175;symmetrical:8;',
        'length:7;direction:right;fcolor:black;pos:60,-195;',
]

再点个赞:

逻辑:

代码语言:javascript复制
#赞
zan=[
   #袖子
   'length:6;direction:down;fcolor:black;pos:0,0;symmetrical:3;',    
   'length:4;direction:right;fcolor:black;pos:0,10;symmetrical:7;symmetrical_direction:down;', 
   #拇指
   'length:1;direction:down;fcolor:black;pos:40,10;',
   'length:1;direction:down;fcolor:black;pos:50,20;symmetrical:4;',
   'length:1;direction:down;fcolor:black;pos:60,30;',
   'length:3;direction:up;fcolor:black;pos:70,40;',
   'length:1;direction:up;fcolor:black;pos:80,70;symmetrical:2;',
   'length:2;direction:right;fcolor:black;pos:90,80;',
   'length:6;direction:down;fcolor:black;pos:100,80;',
   #握拳
   'length:6;direction:right;fcolor:black;pos:80,10;',
   'length:6;direction:down;fcolor:black;pos:140,10;',
   'length:1;direction:down;fcolor:black;pos:130,-50;',
   'length:9;direction:left;fcolor:black;pos:120,-60;',
]

当然还有更多的逻辑代码如下:

代码语言:javascript复制
drawcon=['length:4;direction:down;fcolor:black;pos:0,0',
        'length:6;direction:down;fcolor:black;pos:-10,-40',
        'length:2;direction:down;fcolor:black;pos:0,-100;symmetrical:13',
        'length:2;direction:right;fcolor:black;pos:10,-120;symmetrical:10',
        'length:8;direction:right;fcolor:black;pos:30,-130',
        'length:8;direction:down;fcolor:black;pos:140,-20',
        'length:2;direction:down;fcolor:black;pos:130,0',
        'length:3;direction:right;fcolor:black;pos:100,10',
        'length:2;direction:down;fcolor:black;pos:90,0',
        'length:5;direction:left;fcolor:black;pos:90,-20',
        'length:2;direction:up;fcolor:black;pos:40,-20',
        'length:3;direction:left;fcolor:black;pos:30,0',
        'length:1;direction:left;fcolor:black;pos:0,-60;symmetrical:13',
        'length:1;direction:down;fcolor:black;pos:0,-80;symmetrical:13',
        'length:2;direction:down;fcolor:black;pos:30,-70;symmetrical:7',
        'length:2;direction:right;fcolor:black;pos:60,-90',
        ]

drawcon1=['length:1;direction:down;fcolor:black;pos:0,0',
        'length:3;direction:down;fcolor:black;pos:-10,-10',
        'length:2;direction:right;fcolor:black;pos:0,-40',
        'length:2;direction:right;fcolor:black;pos:10,-20',
        'length:1;direction:right;fcolor:black;pos:20,-30',
        'length:1;direction:right;fcolor:black;pos:20,-30',
        'length:2;direction:right;fcolor:black;pos:30,-40',
        'length:1;direction:right;fcolor:black;pos:40,-50',
        'length:2;direction:right;fcolor:black;pos:50,-60',
        'length:1;direction:right;fcolor:black;pos:70,-50',
        'length:3;direction:up;fcolor:black;pos:80,-40',
        'length:2;direction:left;fcolor:black;pos:70,-10',
        'length:2;direction:down;fcolor:black;pos:50,-20',
        'length:2;direction:left;fcolor:black;pos:40,-10',
        'length:2;direction:up;fcolor:black;pos:20,0',
        'length:1;direction:left;fcolor:black;pos:10,10',
        ]


human_head=[
        'length:26;direction:right;fcolor:black;pos:0,0;symmetrical:21;symmetrical_direction:down',
        'length:21;direction:down;fcolor:black;pos:0,0;symmetrical:25;',
        'length:7;direction:right;fcolor:black;pos:20,-85;symmetrical:14;',
        'length:1;direction:down;fcolor:black;pos:120,-152;symmetrical:2;symmetrical_direction:down;',
        'length:1;direction:down;fcolor:black;pos:110,-162;symmetrical:2;symmetrical_direction:down;',
        'length:3;direction:right;fcolor:black;pos:120,-192;',
]

web=[
       'length:32;direction:right;fcolor:black;pos:0,0;symmetrical:21;symmetrical_direction:down', 
       'length:21;direction:down;fcolor:black;pos:0,0;symmetrical:31;',
       'length:4;direction:down;fcolor:black;pos:160,-210;',
       'length:17;direction:right;fcolor:black;pos:80,-250;',
       'length:6;direction:right;fcolor:blue;pos:20,-50;',
       'length:6;direction:right;fcolor:blue;pos:50,-70;',
]

phone=[
       'length:16;direction:right;fcolor:black;pos:0,0;symmetrical:20;symmetrical_direction:down', 
       'length:20;direction:down;fcolor:black;pos:0,0;symmetrical:15;',
       'length:16;direction:right;fcolor:black;pos:0,-170;',
       'length:1;direction:right;fcolor:black;pos:75,-185;',
]

spider=[
        'length:17;direction:right;fcolor:black;pos:0,0;symmetrical:11;symmetrical_direction:down',
        'length:11;direction:down;fcolor:black;pos:0,0;symmetrical:16;',
        'length:6;direction:right;fcolor:black;pos:20,-20;symmetrical:6;symmetrical_direction:down',
        'length:6;direction:down;fcolor:black;pos:20,-20;symmetrical:5;',
        'length:6;direction:right;fcolor:black;pos:90,-20;symmetrical:6;symmetrical_direction:down',
        'length:6;direction:down;fcolor:black;pos:90,-20;symmetrical:5;',
        'length:2;direction:right;fcolor:black;pos:40,-40;symmetrical:7;',
        'length:2;direction:right;fcolor:black;pos:40,-50;symmetrical:7;',
        'length:6;direction:left;fcolor:black;pos:0,-20;symmetrical:22;',#第一根腿
        'length:3;direction:down;fcolor:black;pos:-60,-20;symmetrical:28;',
        'length:7;direction:left;fcolor:black;pos:0,-60;symmetrical:23;',#中间腿
        'length:8;direction:left;fcolor:black;pos:0,-80;symmetrical:24;',#最前面的腿
        'length:4;direction:down;fcolor:black;pos:-80,-80;symmetrical:32;',
]


camera=[
        'length:26;direction:right;fcolor:black;pos:0,0;symmetrical:14;symmetrical_direction:down',
        'length:14;direction:down;fcolor:black;pos:0,0;symmetrical:25;',
        'length:6;direction:right;fcolor:black;pos:20,-30;symmetrical:4;symmetrical_direction:down',
        'length:4;direction:down;fcolor:black;pos:20,-30;symmetrical:5;',
        'length:3;direction:right;fcolor:black;pos:200,-20;',
]

led=[
        'length:8;direction:right;fcolor:black;pos:0,0',
        'length:1;direction:right;fcolor:black;pos:-10,-10;symmetrical:9;',
        'length:9;direction:down;fcolor:black;pos:-20,-20;symmetrical:11;',
        'length:1;direction:down;fcolor:black;pos:-10,-110;symmetrical:9;',
        'length:1;direction:down;fcolor:black;pos:0,-120;symmetrical:7;',
        'length:1;direction:down;fcolor:black;pos:10,-130;symmetrical:5;',
        'length:4;direction:right;fcolor:black;pos:20,-150;symmetrical:2;symmetrical_direction:down',#灯座
        'length:2;direction:up;fcolor:black;pos:0,20',#灯光
        'length:2;direction:up;fcolor:black;pos:20,20',
        'length:2;direction:up;fcolor:black;pos:40,20',
        'length:2;direction:up;fcolor:black;pos:60,20',
        'length:2;direction:up;fcolor:black;pos:80,20',
        
]

#----------------------------
#哭脸
cry_face=[
        'length:26;direction:right;fcolor:black;pos:0,0;symmetrical:21;symmetrical_direction:down',
        'length:21;direction:down;fcolor:black;pos:0,0;symmetrical:25;',
        'length:7;direction:right;fcolor:black;pos:20,-85;symmetrical:14;',
        'length:12;direction:down;fcolor:black;pos:20,-105;symmetrical:14;',
        'length:12;direction:down;fcolor:black;pos:80,-105;symmetrical:14;',
        'length:5;direction:right;fcolor:black;pos:100,-145;',
]

#苹果
apple=[
        'length:2;direction:right;fcolor:black;pos:0,0;symmetrical:10;symmetrical_direction:down',
        'length:1;direction:right;fcolor:black;pos:20,-10;symmetrical:8;symmetrical_direction:down',#苹果凹坑
        'length:3;direction:right;fcolor:black;pos:30,0;symmetrical:10;symmetrical_direction:down',
        'length:1;direction:right;fcolor:black;pos:-10,-10;symmetrical:8;symmetrical_direction:down',
        'length:1;direction:right;fcolor:black;pos:-20,-20;symmetrical:6;symmetrical_direction:down',
        'length:5;direction:down;fcolor:black;pos:-30,-30;',
        'length:1;direction:right;fcolor:black;pos:60,-10;symmetrical:8;symmetrical_direction:down',#咬痕
        'length:1;direction:right;fcolor:black;pos:50,-20;symmetrical:6;symmetrical_direction:down',
        'length:1;direction:left;fcolor:black;pos:40,-30;symmetrical:4;symmetrical_direction:down',
        'length:3;direction:down;fcolor:black;pos:30,-40;',
        'length:1;direction:down;fcolor:black;pos:20,20;',#叶子
        'length:2;direction:right;fcolor:black;pos:30,30;',
        'length:1;direction:down;fcolor:black;pos:50,40;',
]

#书本
notebook=[
        'length:12;direction:right;fcolor:black;pos:0,0;symmetrical:21;symmetrical_direction:down',
        'length:1;direction:right;fcolor:black;pos:120,-10;symmetrical:21;symmetrical_direction:down',#凹
        'length:13;direction:right;fcolor:black;pos:130,0;symmetrical:21;symmetrical_direction:down',
        'length:21;direction:down;fcolor:black;pos:0,0;symmetrical:25;',
        'length:5;direction:down;fcolor:black;pos:120,-10;',#中间
]
#字母
letter_p=[
        'length:21;direction:down;fcolor:black;pos:0,0;',
        'length:6;direction:right;fcolor:black;pos:0,0;symmetrical:8;symmetrical_direction:down',
        'length:1;direction:right;fcolor:black;pos:60,-10;symmetrical:6;symmetrical_direction:down',
        'length:5;direction:down;fcolor:black;pos:70,-20;',
]
letter_h=[
        'length:21;direction:down;fcolor:black;pos:0,0;symmetrical:13;symmetrical_direction:right',
        'length:13;direction:right;fcolor:black;pos:0,-80;',
]
letter_t=[
        'length:13;direction:right;fcolor:black;pos:0,0;',
        'length:18;direction:down;fcolor:black;pos:60,0;',
]
letter_m=[
        'length:20;direction:right;fcolor:black;pos:0,0;',
        'length:21;direction:down;fcolor:black;pos:0,0;symmetrical:20;symmetrical_direction:right',
        'length:21;direction:down;fcolor:black;pos:100,0;',
]
letter_l=[
        'length:21;direction:down;fcolor:black;pos:0,0;',
        'length:14;direction:right;fcolor:black;pos:0,-210;',
]
letter_s=[
        'length:10;direction:right;fcolor:black;pos:0,0;',
        'length:10;direction:down;fcolor:black;pos:0,0;',
        'length:10;direction:right;fcolor:black;pos:0,-100;symmetrical:9;symmetrical_direction:down',
        'length:10;direction:down;fcolor:black;pos:100,-100;',
]

letter_q=[
        'length:10;direction:right;fcolor:black;pos:0,0;symmetrical:20;symmetrical_direction:down',
        'length:20;direction:down;fcolor:black;pos:0,0;symmetrical:10;symmetrical_direction:right',
        'length:5;direction:right;fcolor:black;pos:80,-150;',
        ]
letter_j=[
        'length:7;direction:right;fcolor:black;pos:0,0;',
        'length:18;direction:down;fcolor:black;pos:70,0;',
        'length:1;direction:down;fcolor:black;pos:60,-180;',
        'length:1;direction:down;fcolor:black;pos:50,-190;',
        'length:3;direction:left;fcolor:black;pos:40,-200;',
        'length:1;direction:left;fcolor:black;pos:10,-190;',
        'length:2;direction:up;fcolor:black;pos:0,-180;',
]

#笑脸
happy_face=[
        'length:26;direction:right;fcolor:black;pos:0,0;symmetrical:21;symmetrical_direction:down',
        'length:21;direction:down;fcolor:black;pos:0,0;symmetrical:25;',
        'length:7;direction:right;fcolor:black;pos:20,-85;symmetrical:14;',
        'length:9;direction:right;fcolor:black;pos:80,-175;',#笑脸嘴
        'length:1;direction:right;fcolor:black;pos:70,-165;symmetrical:10;symmetrical_direction:right',
        'length:1;direction:right;fcolor:black;pos:60,-155;symmetrical:12;symmetrical_direction:right',
]


#dog face
dog_face=[
        #耳朵
      'length:9;direction:down;fcolor:black;pos:0,0;symmetrical:20;',
      'length:2;direction:right;fcolor:black;pos:10,10;symmetrical:17;',
      'length:1;direction:right;fcolor:black;pos:30,0;symmetrical:14;',
      'length:1;direction:right;fcolor:black;pos:40,-10;symmetrical:12;',
      'length:11;direction:right;fcolor:black;pos:50,-20;',
      'length:1;direction:right;fcolor:black;pos:40,-30;symmetrical:12;',
      'length:2;direction:down;fcolor:black;pos:30,-40;symmetrical:14;',
      'length:2;direction:right;fcolor:black;pos:10,-60;symmetrical:17;',
      #脸蛋
      'length:7;direction:down;fcolor:black;pos:-10,-90;symmetrical:22;',
      'length:2;direction:down;fcolor:black;pos:0,-160;symmetrical:20;',
      'length:2;direction:right;fcolor:black;pos:10,-180;symmetrical:17;',
      'length:2;direction:down;fcolor:black;pos:30,-190;symmetrical:14;',
      'length:1;direction:down;fcolor:black;pos:40,-210;',
      'length:2;direction:right;fcolor:black;pos:150,-210;',
      'length:10;direction:right;fcolor:black;pos:50,-220;',
      #眼眶
      'length:2;direction:down;fcolor:black;pos:0,-110;symmetrical:12;',
      'length:6;direction:right;fcolor:black;pos:10,-100;symmetrical:12;',
      'length:2;direction:down;fcolor:black;pos:70,-110;symmetrical:12;',
      'length:6;direction:right;fcolor:black;pos:10,-130;symmetrical:12;',
      #眼珠
      'length:2;direction:down;fcolor:black;pos:60,-110;symmetrical:12;',
      'length:1;direction:down;fcolor:gray;pos:50,-110;symmetrical:12;',
      'length:1;direction:down;fcolor:black;pos:50,-120;symmetrical:12;',
      #鼻子嘴巴
      'length:2;direction:down;fcolor:black;pos:70,-150;symmetrical:2;',
      'length:5;direction:down;fcolor:black;pos:80,-150;',
      'length:7;direction:right;fcolor:black;pos:60,-200;',
      'length:1;direction:right;fcolor:black;pos:130,-190;',
      'length:1;direction:right;fcolor:black;pos:140,-180;',
]

#programer
programer=[
        #头发
        'length:3;direction:right;fcolor:black;pos:0,0;',
        'length:11;direction:right;fcolor:black;pos:30,10;',
        'length:2;direction:right;fcolor:black;pos:140,0;',
        'length:1;direction:right;fcolor:black;pos:160,-10;',
        'length:3;direction:right;fcolor:black;pos:170,-20;',
        'length:4;direction:down;fcolor:black;pos:200,-30;',
        'length:2;direction:left;fcolor:black;pos:190,-70;',
        'length:2;direction:left;fcolor:black;pos:170,-80;',
        'length:5;direction:up;fcolor:black;pos:150,-70;',
        'length:2;direction:up;fcolor:black;pos:140,-70;',
        'length:3;direction:left;fcolor:black;pos:140,-70;',
        'length:3;direction:left;fcolor:black;pos:110,-80;',
        'length:1;direction:left;fcolor:black;pos:80,-70;',
        'length:2;direction:left;fcolor:black;pos:70,-80;',
        'length:1;direction:left;fcolor:black;pos:50,-70;',
        'length:3;direction:down;fcolor:black;pos:40,-60;',
        'length:4;direction:left;fcolor:black;pos:30,-80;',
        'length:5;direction:down;fcolor:black;pos:-10,-80;',#左侧脸最左侧坐标
        'length:2;direction:up;fcolor:black;pos:-20,-110;',
        'length:8;direction:up;fcolor:black;pos:-30,-100;',
        'length:1;direction:up;fcolor:black;pos:-20,-20;',
        'length:1;direction:up;fcolor:black;pos:-10,-10;',
        #脸廓
        'length:2;direction:down;fcolor:black;pos:0,-130;',
        'length:6;direction:down;fcolor:black;pos:10,-150;',
        'length:1;direction:down;fcolor:black;pos:20,-210;',
        'length:12;direction:right;fcolor:black;pos:30,-220;',
        'length:1;direction:right;fcolor:black;pos:150,-210;',
        'length:1;direction:right;fcolor:black;pos:160,-200;',
        'length:11;direction:up;fcolor:black;pos:170,-190;',
        #眼睛
        'length:4;direction:right;fcolor:black;pos:40,-105;symmetrical:8;',
        #眉毛
        'length:2;direction:down;fcolor:black;pos:70,-125;symmetrical:5;',
        #嘴巴
        'length:2;direction:down;fcolor:black;pos:50,-175;symmetrical:8;',
        'length:2;direction:down;fcolor:black;pos:50,-175;symmetrical:8;',
        'length:7;direction:right;fcolor:black;pos:60,-195;',
]

#赞
zan=[
   #袖子
   'length:6;direction:down;fcolor:black;pos:0,0;symmetrical:3;',    
   'length:4;direction:right;fcolor:black;pos:0,10;symmetrical:7;symmetrical_direction:down;', 
   #拇指
   'length:1;direction:down;fcolor:black;pos:40,10;',
   'length:1;direction:down;fcolor:black;pos:50,20;symmetrical:4;',
   'length:1;direction:down;fcolor:black;pos:60,30;',
   'length:3;direction:up;fcolor:black;pos:70,40;',
   'length:1;direction:up;fcolor:black;pos:80,70;symmetrical:2;',
   'length:2;direction:right;fcolor:black;pos:90,80;',
   'length:6;direction:down;fcolor:black;pos:100,80;',
   #握拳
   'length:6;direction:right;fcolor:black;pos:80,10;',
   'length:6;direction:down;fcolor:black;pos:140,10;',
   'length:1;direction:down;fcolor:black;pos:130,-50;',
   'length:9;direction:left;fcolor:black;pos:120,-60;',
]

0 人点赞