教你用python画一个可爱皮卡丘!

听说CSDN里的人都是绘图的好手,那么有种接受挑战嘛,和我一起绘制全网各态皮卡丘!

最近爬虫遇到瓶颈,于是找了几张图皮卡丘的图绘制一下,勉勉强强,还看得的下去,所以滋生了一个绘图比赛,本篇博客讲诉大致模块方法, 如果你们看完,能画出更好的皮卡丘,欢迎在评论区告诉我,有奖活动哟! 寻找最萌皮卡丘活动正在开始!

在这里插入图片描述


其实我脑子是想画的上面这张皮卡丘图片,结果,我的手做出了相反的决定,如下: 不堪入目------ 我也不知道在我手里就成了这个呆萌样,憨憨一样的,


在这里插入图片描述

准备工作:

  • 预先使用纸和笔大致勾勒出轮廓, 以屏幕中心为原点,建立坐标系,估算五官的几个重要的坐标点,记录下来。
  • 使用函数库: turtle
  • 使用大脑和手 开始绘制:

代码如下:

# -*- coding :  utf-8 -*-
# @Time      :  2020/6/7  17:24
# @author    :  沙漏在下雨
# @Software  :  PyCharm
# @CSDN      :  https://me.csdn.net/qq_45906219

import turtle as T


class Draw:
    def __init__(self):
        """
        初始化实例
        """
        self.t = T.Turtle()
        self.w = T.Screen()
        self.t.getscreen().tracer(5, 0)
        # self.w.exitonclick()
        self.t.pensize(2)
        self.t.hideturtle()
        self.w.screensize(bg='yellow')

    def draw_sun(self, x, y, color):
        self.t.penup()
        self.t.goto(x, y)
        self.t.pendown()
        self.t.begin_fill()
        self.t.fillcolor(color)
        self.t.circle(80)
        self.t.end_fill()

    def draw_eye(self, location):
        """
        绘制眼睛 和 眉毛
        params : location  坐标
        """
        self.t.penup()
        self.t.goto(location[0], location[1])
        self.t.pendown()
        self.t.color((0, 0, 0), (0, 0, 0))
        self.t.begin_fill()
        self.t.circle(location[4])
        self.t.end_fill()
        self.t.penup()
        self.t.goto(location[2], location[3])
        self.t.pendown()
        self.t.begin_fill()
        self.t.color('white', 'white')
        self.t.circle(location[5])
        self.t.end_fill()

        # 开始绘制眉毛
        self.t.penup()
        eyebrow_x, eyebrow_y = location[0] - 70, location[1] + 120
        self.t.goto(eyebrow_x, eyebrow_y)
        self.t.pendown()
        self.t.pensize(10)
        self.t.pencolor('black')
        self.t.circle(location[6], location[7])

    def red_round(self, location):
        """
        绘制左右红晕
        """
        self.t.pensize(2)
        self.t.penup()
        self.t.goto(location[0], location[1])
        self.t.pendown()
        self.t.color('gold', 'red')
        self.t.begin_fill()
        self.t.circle(60)
        self.t.end_fill()

    def draw_nose(self, location):
        """
        绘制鼻子
        """
        self.t.penup()
        self.t.goto(location[0], location[1])
        self.t.pendown()
        self.t.pensize(0.1)
        self.t.color('black', 'black')
        self.t.left(30)
        self.t.begin_fill()
        for i in range(100):
            self.t.right(1)
            self.t.fd(0.8)
        self.t.end_fill()

    def draw_outward(self, location):
        """
        绘制轮廓
        """
        self.t.penup()
        self.t.goto(location[0], location[1])
        self.t.pendown()
        self.t.pensize(4)
        self.t.pencolor('Tan')
        self.t.circle(500, 140)

    def time_draw(self):
        """
        调度函数, 在此调用其他函数的执行
        """

        # self.t.pencolor('gold')
        # self.draw_sun(200, 200, 'red')
        #  绘制皮卡丘左眼
        self.draw_eye(location=[-200, 100, -230, 130, 50, 15, 200, 20])
        #  绘制皮卡丘右眼
        self.draw_eye(location=[200, 100, 210, 135, 48, 10, 600, 5])
        # 绘制左红晕
        self.red_round(location=[-250, -60])
        # 绘制右红晕
        self.red_round(location=[290, -60])
        # 绘制鼻子
        self.draw_nose(location=[-40, 0])
        #  绘制轮廓
        self.draw_outward(location=[-400, -100])

        self.w.exitonclick()


if __name__ == '__main__':
    life = Draw()
    life.time_draw()

猜你喜欢

转载自blog.csdn.net/qq_45906219/article/details/106648488