SoFunction
Updated on 2024-11-16

Drawing a handsome Pikachu in python

惊呆了!python画出全网最帅比卡丘_Python

That's right, I have the most handsome Pikachu in the whole internet~~

惊呆了!python画出全网最帅比卡丘_ide_02

In order to access the Python library, you need to import it into your Python environment, using the following command to import turtle into your Python script.

import turtle

First, let's create a Screen instance.

wn = ()

Now, create a Turtle instance.

 = ()

Let's set the speed to 3 Using the speed method means that Pikachu won't just appear on the screen, the drawing will also have some animation. If you want to change the background color, you can use the bgcolor method, which defaults to white. You can adjust the thickness of the pen using the pensize method, which will thicken it slightly. ondrag Dragging Turtle will move it around on the screen, resulting in a hand drawing (if the pen is down).

(3)
(9)
(getPosition)

Now let's look at some of the common methods used in this program:

Turtle(): Used to create and return a new turtle object.

forward(value): moves the turtle forward relative to the specified value.

Backward (value): The turtle moves backward relative to the specified value.

The turtle turns clockwise.

left(angle): The turtle rotates counterclockwise.

penup(): Pick up the turtle pen.

pendown(): Turtle pen down.

up(): same as penup().

down(): same as pendown().

color(color name): The color of the Turtle pen changes.

fillcolor: The color used to fill a particular shape has changed.

Title (): return the current title.

position(): return the current position.

goto(x, y): Move the turtle's position to coordinates x, y.

end_fill(): fill the current fill color after closing the polygon.

begin_fill(): remembers the starting point of the filled polygon.

dot(): the dot stays at the current position.

stamp(): The turtle-shaped impression stays at the current position.

Shape(): should be - 'turtle', 'classic', 'arrow' or 'circle'.

Up Code:

import turtle


def getPosition(x, y):
    (x)
    (y)
    print(x, y)


class Pikachu:

    def __init__(self):
         = ()
        t = 
        (3)
        (9)
        (getPosition)

    def noTrace_goto(self, x, y):
        ()
        (x, y)
        ()

    def leftEye(self, x, y):
        self.noTrace_goto(x, y)
        t = 
        (0)
        ('#333333')
        t.begin_fill()
        (22)
        t.end_fill()

        self.noTrace_goto(x, y + 10)
        ('#000000')
        t.begin_fill()
        (10)
        t.end_fill()

        self.noTrace_goto(x + 6, y + 22)
        ('#ffffff')
        t.begin_fill()
        (10)
        t.end_fill()

    def rightEye(self, x, y):
        self.noTrace_goto(x, y)
        t = 
        (0)
        ('#333333')
        t.begin_fill()
        (22)
        t.end_fill()

        self.noTrace_goto(x, y + 10)
        ('#000000')
        t.begin_fill()
        (10)
        t.end_fill()

        self.noTrace_goto(x - 6, y + 22)
        ('#ffffff')
        t.begin_fill()
        (10)
        t.end_fill()

    def mouth(self, x, y):
        self.noTrace_goto(x, y)
        t = 

        ('#88141D')
        t.begin_fill()

        # Lower Lip
        l1 = []
        l2 = []
        (190)
        a = 0.7
        for i in range(28):
            a += 0.1
            (3)
            (a)
            (())

        self.noTrace_goto(x, y)

        (10)
        a = 0.7
        for i in range(28):
            a += 0.1
            (3)
            (a)
            (())

        # Upper Lip
        (10)
        (50, 15)
        (180)
        (-50, 15)

        (-50, 40)
        (233)
        (-50, 55)
        (180)
        (50, 12.1)
        t.end_fill()

        # Tongue
        self.noTrace_goto(17, 54)
        ('#DD716F')
        t.begin_fill()
        (145)
        (40, 86)
        ()
        for pos in reversed(l1[:20]):
            (pos[0], pos[1] + 1.5)
        for pos in l2[:20]:
            (pos[0], pos[1] + 1.5)
        ()
        t.end_fill()

        # Nose
        self.noTrace_goto(-17, 94)
        (8)
        (4)
        (8)

    # Red Cheeks
    def leftCheek(self, x, y):
        (False)
        t = 
        self.noTrace_goto(x, y)
        (300)
        ('#DD4D28')
        t.begin_fill()
        a = 2.3
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                (3)
                (a)
            else:
                a += 0.05
                (3)
                (a)
        t.end_fill()
        (True)

    def rightCheek(self, x, y):
        t = 
        (False)
        self.noTrace_goto(x, y)
        (60)
        ('#DD4D28')
        t.begin_fill()
        a = 2.3
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                (3)
                (a)
            else:
                a += 0.05
                (3)
                (a)
        t.end_fill()
        (True)

    def colorLeftEar(self, x, y):
        t = 
        self.noTrace_goto(x, y)
        ('#000000')
        t.begin_fill()
        (330)
        (100, 35)
        (219)
        (-300, 19)
        (110)
        (-30, 50)
        (-300, 10)
        t.end_fill()

    def colorRightEar(self, x, y):
        t = 
        self.noTrace_goto(x, y)
        ('#000000')
        t.begin_fill()
        (300)
        (-100, 30)
        (35)
        (300, 15)
        (30, 50)
        (190)
        (300, 17)
        t.end_fill()

    def body(self):
        t = 

        ('#F6D02F')
        t.begin_fill()
        # Right face contour
        ()
        (130, 40)
        ()
        (100, 105)
        (180)
        (-100, 5)

        # Right ear
        (20)
        (300, 30)
        (30, 50)
        (190)
        (300, 36)

        # Upper profile
        (150)
        (150, 70)

        # Left ear
        (200)
        (300, 40)
        (30, 50)
        (20)
        (300, 35)
        #print(())

        # Left face contour
        (240)
        (105, 95)
        (180)
        (-105, 5)

        # Left hand
        (210)
        (500, 18)
        (200)
        (10)
        (280)
        (7)
        (210)
        (10)
        (300)
        (10, 80)
        (220)
        (10)
        (300)
        (10, 80)
        (240)
        (12)
        (0)
        (13)
        (240)
        (10, 70)
        (10)
        (10, 70)
        (10)
        (300, 18)

        (75)
        (500, 8)
        (180)
        (-500, 15)
        (250)
        (100, 65)

        # Left foot
        (320)
        (100, 5)
        (180)
        (-100, 5)
        (220)
        (200, 20)
        (20, 70)

        (60)
        (-100, 20)
        (180)
        (100, 20)
        (300)
        (10, 70)

        (60)
        (-100, 20)
        (180)
        (100, 20)
        (10)
        (100, 60)

        # Horizontal
        (180)
        (-100, 10)
        (180)
        (100, 10)
        (5)
        (100, 10)
        (-100, 40)
        (100, 35)
        (180)
        (-100, 10)

        # Right foot
        (290)
        (100, 55)
        (10, 50)

        (120)
        (100, 20)
        (180)
        (-100, 20)

        (0)
        (10, 50)

        (110)
        (100, 20)
        (180)
        (-100, 20)

        (30)
        (20, 50)

        (100)
        (100, 40)

        # Right body contour
        (200)
        (-100, 5)
        (180)
        (100, 5)
        (30)
        (100, 75)
        (15)
        (-300, 21)
        (180)
        (300, 3)

        # Right hand
        (43)
        (200, 60)

        (10)
        (10)

        (5, 160)
        (90)
        (5, 160)
        (90)

        (10)
        (90)
        (5, 180)
        (10)

        (180)
        (20)
        (10)
        (5, 170)
        (10)
        (240)
        (50, 30)

        t.end_fill()
        self.noTrace_goto(130, 125)
        (-20)
        (5)
        (-5, 160)
        (5)

        # Fingers
        self.noTrace_goto(166, 130)
        (-90)
        (3)
        (-4, 180)
        (3)
        (-90)
        (3)
        (-4, 180)
        (3)

        # Tail
        self.noTrace_goto(168, 134)
        ('#F6D02F')
        t.begin_fill()
        (40)
        (200)
        (-80)
        (150)
        (210)
        (150)
        (90)
        (100)
        (95)
        (100)
        (110)
        (70)
        (110)
        (80)
        (110)
        (30)
        (110)
        (32)

        (106)
        (100, 25)
        (15)
        (-300, 2)
        #print(())
        (30)
        (40)
        (100)
        (70)
        (100)
        (80)
        (100)
        (46)
        (66)
        (200, 38)
        (10)
        (10)
        t.end_fill()

        # Tail Pattern
        ('#923E24')
        self.noTrace_goto(126.82, -156.84)
        t.begin_fill()

        (30)
        (40)
        (100)
        (40)
        ('#923e24')
        (-30)
        (30)
        (140)
        (20)
        (150)
        (20)
        (150)
        (20)
        (150)
        (20)
        (130)
        (18)
        ('#000000')
        (-45)
        (67)
        (110)
        (80)
        (110)
        (30)
        (110)
        (32)
        (106)
        (100, 25)
        (15)
        (-300, 2)
        t.end_fill()

        # Hat, Eye, Mouth, Cheek
        (-134.07, 147.81)
        (-5, 25)
        (-126, 32)
        (107, 63)
        (-250, 100)
        (140, 270)
        (-85, 90)
        (50, 110)
        ()

    def cap(self, x, y):
        self.noTrace_goto(x, y)
        t = 
        ('#CD0000')
        t.begin_fill()
        (200)
        (400, 7)
        (180)
        (-400, 30)
        (30, 60)
        (50)
        (30, 45)
        (60)
        (5)
        (30, 70)
        (20)
        (200, 70)
        (30, 60)
        (70)
        #print(())
        (35)
        (50)
        (8, 100)
        t.end_fill()
        self.noTrace_goto(-168.47, 185.52)
        (36)
        (-270, 54)
        (180)
        (270, 27)
        (-80, 98)

        ('#444444')
        t.begin_fill()
        (180)
        (80, 197)
        (58)
        (200, 45)
        t.end_fill()

        self.noTrace_goto(-58, 270)
        ('#228B22')
        (35)

        self.noTrace_goto(-30, 280)
        ('#228B22')
        t.begin_fill()
        (100)
        (30, 180)
        (190)
        (15)
        (100)
        (-45, 180)
        (90)
        (15)
        t.end_fill()
        ('#000000')

    def start(self):
        ()


def main():
    print('Painting the Pikachu... ')
    wn = ()
    (width=600, height=800)
    pikachu = Pikachu()
    ()
    ()


if __name__ == '__main__':
    main()

to this article on the use of python to draw a handsome Pikachu article is introduced to this, more related python Pikachu content please search for my previous articles or continue to browse the following related articles I hope that you will support me more in the future!