Ticker

6/recent/ticker-posts

Unique Pattern With Turtle In Python - pattern 6 ( Anime Character )

   






        In this program we are going to make a anime character in python using turtle library.

        Its super easy to code and so much fun. Try out this program and the code is following :



import turtle as te
import time
WriteStep = 15  # Sampling times of Bessel function
Speed = 5
Width = 600  # Interface width
Height = 500  # Interface height
Xh = 0  # Record the handle of the previous Bessel function
Yh = 0


def Bezier(p1p2t):  # First order Bessel function
    return p1 * (1 - t+ p2 * t


def Bezier_2(x1y1x2y2x3y3):  # Second-order Bessel function
    te.goto(x1y1)
    te.pendown()
    for t in range(0, WriteStep + 1):
        x = Bezier(Bezier(x1x2, t / WriteStep),
                   Bezier(x2x3, t / WriteStep), t / WriteStep)
        y = Bezier(Bezier(y1y2, t / WriteStep),
                   Bezier(y2y3, t / WriteStep), t / WriteStep)
        te.goto(x, y)
    te.penup()


def Bezier_3(x1y1x2y2x3y3x4y4):  # Third-order Bessel function
    x1 = -Width / 2 + x1
    y1 = Height / 2 - y1
    x2 = -Width / 2 + x2
    y2 = Height / 2 - y2
    x3 = -Width / 2 + x3
    y3 = Height / 2 - y3
    x4 = -Width / 2 + x4
    y4 = Height / 2 - y4  # Coordinate transformation
    te.goto(x1y1)
    te.pendown()
    for t in range(0, WriteStep + 1):
        x = Bezier(Bezier(Bezier(x1x2, t / WriteStep), Bezier(x2x3, t / WriteStep), t / WriteStep),
                   Bezier(Bezier(x2x3, t / WriteStep), Bezier(x3x4, t / WriteStep), t / WriteStep), t / WriteStep)
        y = Bezier(Bezier(Bezier(y1y2, t / WriteStep), Bezier(y2y3, t / WriteStep), t / WriteStep),
                   Bezier(Bezier(y2y3, t / WriteStep), Bezier(y3y4, t / WriteStep), t / WriteStep), t / WriteStep)
        te.goto(x, y)
    te.penup()


def Moveto(xy):  # Move to svg coordinates (x, y)
    te.penup()
    te.goto(-Width / 2 + x, Height / 2 - y)


def line(x1y1x2y2):  # Connect two points under svg coordinates
    te.penup()
    te.goto(-Width / 2 + x1, Height / 2 - y1)
    te.pendown()
    te.goto(-Width / 2 + x2, Height / 2 - y2)
    te.penup()


def lineto(dxdy):  # Connect the current point and the point with relative coordinates (dx, dy)
    te.pendown()
    te.goto(te.xcor() + dxte.ycor() - dy)
    te.penup()


def Lineto(xy):  # Connect the current point and svg coordinates (x, y)
    te.pendown()
    te.goto(-Width / 2 + x, Height / 2 - y)
    te.penup()


def Horizontal(x):  # Make the horizontal line with the abscissa x in the svg coordinates
    te.pendown()
    te.setx(x - Width / 2)
    te.penup()


def horizontal(dx):  # Make the horizontal line with relative abscissa dx
    te.seth(0)
    te.pendown()
    te.fd(dx)
    te.penup()


def vertical(dy):  # Make the vertical line with the relative ordinate dy
    te.seth(-90)
    te.pendown()
    te.fd(dy)
    te.penup()
    te.seth(0)


def polyline(x1y1x2y2x3y3):  # Make a polyline under svg coordinates
    te.penup()
    te.goto(-Width / 2 + x1, Height / 2 - y1)
    te.pendown()
    te.goto(-Width / 2 + x2, Height / 2 - y2)
    te.goto(-Width / 2 + x3, Height / 2 - y3)
    te.penup()


def Curveto(x1y1x2y2xy):  # Third-order Bezier curve to (x, y)
    te.penup()
    X_now = te.xcor() + Width / 2
    Y_now = Height / 2 - te.ycor()
    Bezier_3(X_now, Y_now, x1y1x2y2xy)
    global Xh
    global Yh
    Xh = x - x2
    Yh = y - y2


def curveto_r(x1y1x2y2xy):  # Third-order Bezier curve to relative coordinates (x, y)
    te.penup()
    X_now = te.xcor() + Width / 2
    Y_now = Height / 2 - te.ycor()
    Bezier_3(X_now, Y_now, X_now + x1, Y_now + y1,
             X_now + x2, Y_now + y2, X_now + x, Y_now + y)
    global Xh
    global Yh
    Xh = x - x2
    Yh = y - y2


def Smooth(x2y2xy):  # Smooth the third-order Bezier curve to (x, y)
    global Xh
    global Yh
    te.penup()
    X_now = te.xcor() + Width / 2
    Y_now = Height / 2 - te.ycor()
    Bezier_3(X_now, Y_now, X_now + Xh, Y_now + Yh, x2y2xy)
    Xh = x - x2
    Yh = y - y2


def smooth_r(x2y2xy):  # Smooth the third-order Bezier curve to relative coordinates (x, y)
    global Xh
    global Yh
    te.penup()
    X_now = te.xcor() + Width / 2
    Y_now = Height / 2 - te.ycor()
    Bezier_3(X_now, Y_now, X_now + Xh, Y_now + Yh,
             X_now + x2, Y_now + y2, X_now + x, Y_now + y)
    Xh = x - x2
    Yh = y - y2

te.tracer(10)
te.setup(Width, Height, 00)
te.pensize(1)
te.speed(Speed)
te.penup()

# Layer_2
time.sleep(20)
te.color("black""#F2F2F2")  # Coat
Moveto(61462)
te.begin_fill()
smooth_r(12-4127-58)
curveto_r(-6-366-1189-132)
curveto_r(-15-27-23-51-26-74)
curveto_r(4-6638-10565-149)
Horizontal(486)
curveto_r(1224409933114)
curveto_r(39825512939144)
smooth_r(-3123-3928)
smooth_r(-1237-1237)
lineto(5092)
Horizontal(445)
smooth_r(-29-38-31-46)
smooth_r(78-10772-119)
Smooth(355178340176)
Smooth(2726326464)
smooth_r(-2967-2773)
Curveto(99292174428173439)
smooth_r(-823-823)
Lineto(61462)
te.end_fill()

Moveto(60.5461.5)  # Shadow
te.color("black""#D3DFF0")
te.begin_fill()
curveto_r(0017-4227-59)
curveto_r(-6-336-12810-133)
curveto_r(-15-10-27-66-27.285-75)
te.pencolor("#D3DFF0")
curveto_r(12.2851182.96315682.963156)
te.pencolor("black")
smooth_r(12.3227519.32286)
curveto_r(-111-825-825)
Horizontal(60.5)
te.end_fill()

Moveto(444.5464)
te.begin_fill()
curveto_r(00-29-36-31-46)
smooth_r(53.59-82.33753.59-82.337)
te.pencolor("#D3DFF0")
smooth_r(86.41-47.66396.072-54.85)
Curveto(563.5297.5570.5299.5518.5334)
te.pencolor("black")
curveto_r(-216-1233-1237)
smooth_r(50925093)
Horizontal(444.5)
te.end_fill()

Moveto(19549)
te.begin_fill()
te.pencolor("#D3DFF0")
polyline(19549175.5106.5202.52249)
te.pencolor("black")
Horizontal(195)
te.pencolor("#D3DFF0")
te.end_fill()

Moveto(327.99749)
te.begin_fill()
te.pencolor("#D3DFF0")
curveto_r(0011.503121.08713.503128.087)
curveto_r(11254375437)
lineto(-40-165.087)
te.pencolor("black")
Horizontal(327.997)
te.pencolor("#D3DFF0")
te.end_fill()

te.pencolor("black")
line(94.5397.5107.5373.5)  # Wrinkles
line(122.5317.595.875274.699)
line(122.5341.5141.5402.5)
line(141.5409.5153.5431.5)
# line(328,47.712,344,175.977)
line(340.02349360.5144)
# line(353.5,47.5,395.5,208.5)
line(478.595.5518.5161.5)
line(518.5332.5460.5359.5)
polyline(506.5369.5493.5402.5502.5443.5)
Moveto(530429)
curveto_r(416-533-533)

# Layer_3
te.color("black""#2b1d2a")  # Inside the jacket
Moveto(225462)
te.begin_fill()
Horizontal(165)
smooth_r(9-158-25)
curveto_r(-47-1266-21212-225)
Curveto(185305202428225462)
Lineto(225462)
te.end_fill()

Moveto(390462)
te.begin_fill()
curveto_r(10-2334-18035-222)  # !!!227
curveto_r(7454456161)  # 61
smooth_r(-73101-72118)
curveto_r(51531463145)
Lineto(390462)
te.end_fill()
# Layer_4
te.color("black""#2b1d29")  # Inside the jacket
Moveto(225462)
te.begin_fill()
curveto_r(-28-50-40-166-40-250)
curveto_r(651-68745106)
smooth_r(64278924)
smooth_r(49-1856-20)
smooth_r(50-1051-85)
curveto_r(029-25201-36225)
Lineto(225462)
te.end_fill()
# Layer_5
te.color("black""#3D3D3D")  # Clothes
Moveto(225462)
te.begin_fill()
curveto_r(-5-5-22-53-23-70)
lineto(32-13)
curveto_r(3-256-2812-36)
smooth_r(13-1216-12)
vertical(-2)
curveto_r(45206414941)
vertical(2)
curveto_r(8-2152174)
smooth_r(06-29)
curveto_r(101010291133)
smooth_r(234256)
smooth_r(-1783-1778)
Lineto(225462)
te.end_fill()
# Layer_6
te.color("black""#968281")  # Neck
Moveto(262329)
te.begin_fill()
vertical(17)
curveto_r(1244144515)
smooth_r(312312)
horizontal(3)
vertical(-5)
curveto_r(1-34-65-7)
lineto(36-14)
curveto_r(1-13-162-17)
Curveto(318348296344262329)
te.end_fill()
# Layer_8
te.color("black""#E7F1FF")  # White folds
Moveto(225462)
te.begin_fill()
lineto(-3-5)  # -3,-3,-3,-5
curveto_r(0-24-45-6)
smooth_r(16319-8)
smooth_r(0-70-11)
smooth_r(5-89-5)
smooth_r(19-819-11)
smooth_r(6-76-7)
smooth_r(7-29-4)
lineto(41-2)
lineto(129)
smooth_r(315718)
smooth_r(154174)
smooth_r(4-46-4)
smooth_r(6459)
smooth_r(0909)
smooth_r(1776)
smooth_r(8080)
lineto(-28)
Lineto(225462)
te.end_fill()

te.pensize(2)
Moveto(240450)
smooth_r(09312)
Moveto(372462)
curveto_r(-2-4-5-29-7-28)
te.pensize(1)
# Layer_7
te.color("black""#A2B8D6")  # Collar
Moveto(262331)
te.begin_fill()
curveto_r(08-113015)
smooth_r(43144515)
lineto(312)
horizontal(3)
smooth_r(-1-30-5)
lineto(5-7)
lineto(36-14)
curveto_r(1-12-122-15)
smooth_r(25-21513)
curveto_r(-24-729-732)
smooth_r(-3519-4122)
smooth_r(-914-1214)
smooth_r(-7-12-14-15)
curveto_r(-19-2-41-25-41-25)
smooth_r(-10-26-10-30)
Smooth(255332262331)
te.end_fill()

Moveto(262346)
lineto(-12-6)
Moveto(369333)
curveto_r(24-610-1514)
# Layer_9
te.color("black""#151515")  # Tie
Moveto(247358)
te.begin_fill()
curveto_r(-53-820-623)
curveto_r(252150175017)
lineto(-2364)
horizontal(22)
smooth_r(1-132-16)
lineto(13-50)
curveto_r(2273101)
smooth_r(18651865)
horizontal(19)
lineto(-24-65)
curveto_r(21539-1044-13)
curveto_r(5-201-210-24)
curveto_r(-18-2-4915-5217)
smooth_r(-11-3-15-1)
Smooth(252356247358)
te.end_fill()
# Layer_10
te.color("black""#A2B8D6")  # Collar (through bow tie)
Moveto(297387)
te.begin_fill()
lineto(-116)
curveto_r(-10-20-7-30-19)
Curveto(259373297385297387)
te.end_fill()

Moveto(323384)
te.begin_fill()
lineto(87)
lineto(30-14)
curveto_r(1-15-64-7)
Smooth(329379323384)
te.end_fill()
# Layer_11
te.color("black""#F3EEEB")  # Face
Moveto(185212)
te.begin_fill()
curveto_r(4-946-7752-75)
curveto_r(-2-1719-6827-73)
curveto_r(16157110876112)
smooth_r(76538660)
curveto_r(065-2775-3176)
curveto_r(-5028-7030-8530)
smooth_r(-77-22-86-26)
Curveto(180302186228185212)
te.end_fill()
# Layer_12
te.color("black""#2B1D29")  # Hair
Moveto(189202)
te.begin_fill()
curveto_r(-12219511951)
smooth_r(-10-427-92)
Curveto(212168196189189202)
te.end_fill()

Moveto(221155)
te.begin_fill()
curveto_r(-26548548)
smooth_r(18-2820-48)
curveto_r(-524443750)
curveto_r(-10-493-7213-106)
curveto_r(-2-7-3-32-3-35)
curveto_r(-1718-2771-2771)
Lineto(221155)
te.end_fill()

Moveto(26464)
te.begin_fill()
curveto_r(-451410014100)
smooth_r(-6-79-5-85)
curveto_r(0984913949139)
smooth_r(8-503-65)
Smooth(2726426464)
te.end_fill()

Moveto(342176)
te.begin_fill()
curveto_r(-127-1057-1057)
smooth_r(20-3317-54)
Lineto(342176)
te.end_fill()

te.penup()
te.begin_fill()
polyline(349180353203361203)
polyline(361203362188349180)
te.end_fill()
# Layer_13
te.pensize(2)
Moveto(210180)  # Eyebrows
curveto_r(5-46396314)
Moveto(338193)
curveto_r(0-318-618-6)
te.pensize(1)
# Layer_14
te.color("black""#D1D1D1")  # Eye 1
te.pensize(2)
Moveto(206212)
te.begin_fill()
lineto(15-7)
curveto_r(4-126-2300)
smooth_r(103127)
te.pencolor("#D1D1D1")
te.pensize(1)
smooth_r(227-130)
smooth_r(-395-441)
Smooth(206212206212)
te.end_fill()

Moveto(384204)
te.begin_fill()
te.pencolor("black")
te.pensize(2)
curveto_r(-3-1-18-1-281)
smooth_r(-96-109)
te.pencolor("#D1D1D1")
te.pensize(1)
smooth_r(318623)
smooth_r(386404)
smooth_r(10-913-22)
te.pencolor("black")
te.pensize(2)
Lineto(384204)
te.end_fill()
# Layer_15
te.color("#0C1631""#0C1631")  # Eye 2
te.pensize(1)
Moveto(216206)
te.begin_fill()
curveto_r(-15026735)
smooth_r(302330)
smooth_r(5-312-34)
Smooth(219203216206)
te.end_fill()

Moveto(354207)
te.begin_fill()
curveto_r(-21229431)
smooth_r(303331)
smooth_r(6-244-27)
lineto(-11-8)
Curveto(382204357206354207)
te.end_fill()

# Layer_17
te.color("#F5F5F5""#F5F5F5")  # Eye 3
Moveto(253211)
te.begin_fill()
curveto_r(-30-88110)
Smooth(258210253211)
te.end_fill()

Moveto(392209)
te.begin_fill()
lineto(43)
vertical(4)
lineto(-42)
Curveto(386214392209392209)
te.end_fill()
# Layer_18
te.color("#352F53""#352F53")  # Eye 4
Moveto(219229)
te.begin_fill()
smooth_r(2-56-4)
smooth_r(1813271)
curveto_r(305353)
vertical(13)
Horizontal(224)
Lineto(219229)
te.end_fill()

Moveto(357227)
te.begin_fill()
smooth_r(4-610-2)
smooth_r(1013191)
curveto_r(608686)
lineto(-29)
curveto_r(-123-290-32-2)
Smooth(357227357227)
te.end_fill()

# Layer_19
te.color("#9A90CB""#9A90CB")  # Eye 5
Moveto(227231)
te.begin_fill()
curveto_r(-60-55-38)
smooth_r(242270)
smooth_r(0-8-1-8)
Smooth(234231227231)
te.end_fill()

Moveto(361227)
te.begin_fill()
curveto_r(2182614306)
smooth_r(-1-3-2-4)
smooth_r(-159-24-4)
Curveto(363224361225361227)
te.end_fill()

# Layer_16
te.pencolor("black")  # Eyes (lines)
te.pensize(3)
# Moveto(206,213)
# lineto(14,-8)
# curveto_r(3,-1,30,0,33,1)
# lineto(10,6)
Moveto(225215)
curveto_r(10282216246)
Moveto(365219)
curveto_r(414182422-3)
te.pensize(2)
line(240.5207.5227.5211.5)
line(245.5209.5227.5214.5)
line(247.5211.5227.5217.5)
line(247.5214.5229.5220.5)
line(247.5218.5230.5223.5)
line(246.5222.5232.5226.5)
line(244.5225.5234.5228.5)

line(377.5207.5367.5210.5)
line(384.5207.5366.5212.5)
line(385.5210.5366.5215.5)
line(384.5213.5366.5218.5)
line(384.5215.5367.5220.5)
line(384.5218.5368.5223.5)
# line(383.5,220.5,368.5,225.5)
line(382.5223.5370.5227.5)
# line(381.5,226.5,373.5,229.5)
# Layer_20
te.pencolor("black")
Moveto(309270)  # Nose, mouth
curveto_r(004719)
line(296.5307.5303.5307.5)
Moveto(315307)
smooth_r(10-1102)

te.penup()
te.hideturtle()
te.update()
te.done()

Post a Comment

0 Comments