用Python程式碼畫世界盃吉祥物拉伊卜(附程式碼)

專注的阿熊發表於2022-12-01

# coding=utf-8

from turtle import *

import time

def set_start(x, y, w=0.5, c='black'):

    # 設定畫筆開始的位置,繪製每一個部分的圖形時,將滑鼠移到起始點

    penup()  # 提起畫筆

    setx(x)  # 設定畫筆的x座標

    sety(y)  # 設定畫筆的y座標

    setheading(towards(0, 0))  # 預設設定畫筆指向座標原點0,0

    width(w)  # 設定畫筆的寬度

    pencolor(c)  # 設定畫筆的顏色

    pendown()  # 落下畫筆,開始繪圖

    speed(0)  # 設定畫筆的速度,1-9依次越來越快,其他數字比9更快

def left_rotate(time, angle, length):

    # 繪製向左轉的弧度,左轉一定角度然後前進一段距離,重複多次就得到一個弧度

    for i in range(time):  # 重複次數

        left(angle)  # 左轉的角度

        forward(length)  # 前進距離

def right_rotate(time, angle, length):

    # 繪製向右轉的弧度,右轉一定角度然後前進一段距離,重複多次就得到一個弧度

    for i in range(time):  # 重複次數

        right(angle)  # 外匯跟單gendan5.com右轉的角度

        forward(length)  # 前進距離

def fill_color_patch(x, y, c='white'):

    # 填充顏色時會找上一個圖形的介紹點,此函式重置結束點,避免填充效果不準

    set_start(x, y, 1, c=c)

    forward(1)

def draw_circle(radius, color, color2=''):

    # 繪製一個圓,radius是圓的半徑,color是邊框顏色,color2是填充顏色

    if color2 == '':

        color2 = color

    penup()

    setheading(towards(0, 0))

    right(90)

    pencolor(color)

    pendown()

    begin_fill()

    circle(radius)  # 畫圓

    fillcolor(color2)

    end_fill()

def draw_football():

    # 足球

    # set_start(15, -157, w=1, c='black')

    # draw_circle(39, 'black', '#DCDCDC')

    fill_color_patch(39.34, -90.63)

    begin_fill()

    set_start(39.34, -90.63, w=2, c='black')

    setheading(124.2)

    left_rotate(20, 18, 12.2)

    goto(39.34, -90.63)

    fillcolor('#DCDCDC')

    end_fill()

    fill_color_patch(-25, -110)

    begin_fill()

    set_start(-25, -110, w=1, c='white')

    right_rotate(1, 160, 10)

    left_rotate(5, 20, 12)

    left_rotate(4, 18, 12)

    pencolor('black')

    left_rotate(1, 35, 12)

    left_rotate(7, 18, 12.1)

    goto(-25, -110)

    fillcolor('white')

    end_fill()

    fill_color_patch(-25, -108)

    begin_fill()

    set_start(-25, -108, w=1, c='black')

    right_rotate(1, 20, 4)

    right_rotate(2, 10, 3)

    left_rotate(1, 35, 5)

    left_rotate(1, 165, 5)

    right_rotate(2, 15, 3)

    goto(-25, -108)

    fillcolor('black')

    end_fill()

    fill_color_patch(-16, -101)

    begin_fill()

    set_start(-16, -101, w=1, c='black')

    right_rotate(1, 35, 8)

    right_rotate(1, 140, 4)

    left_rotate(2, 21, 2)

    left_rotate(2, 8, 4.5)

    right_rotate(1, 105, 8)

    right_rotate(1, 120, 3)

    left_rotate(3, 15, 4)

    goto(-16, -101)

    fillcolor('black')

    end_fill()

    fill_color_patch(-10, -93)

    begin_fill()

    set_start(-10, -93, w=1, c='black')

    left_rotate(1, 90, 4)

    right_rotate(1, 135, 5)

    right_rotate(2, 3, 7)

    right_rotate(1, 60, 3)

    right_rotate(1, 135, 5)

    left_rotate(3, 10, 4)

    goto(-10, -93)

    fillcolor('black')

    end_fill()

    fill_color_patch(6, -82)

    begin_fill()

    set_start(6, -82, w=1, c='black')

    right_rotate(1, 50, 4)

    right_rotate(1, 60, 6)

    right_rotate(2, 3, 7)

    right_rotate(1, 130, 4)

    right_rotate(1, 60, 5)

    left_rotate(3, 8, 4)

    goto(6, -82)

    fillcolor('black')

    end_fill()

    fill_color_patch(30, -88)

    begin_fill()

    set_start(30, -88, w=1, c='black')

    right_rotate(1, 130, 5)

    right_rotate(1, 15, 5)

    right_rotate(1, 150, 5)

    goto(30, -88)

    fillcolor('black')

    end_fill()

    fill_color_patch(25, -89)

    begin_fill()

    set_start(25, -89, w=1, c='black')

    right_rotate(1, 140, 8)

    right_rotate(1, 95, 4)

    left_rotate(2, 25, 6)

    right_rotate(1, 130, 8)

    right_rotate(1, 110, 3)

    left_rotate(3, 20, 4)

    goto(25, -89)

    fillcolor('black')

    end_fill()

    fill_color_patch(20, -106)

    begin_fill()

    set_start(20, -106, w=1, c='black')

    right_rotate(1, 180, 8)

    right_rotate(1, 120, 4)

    left_rotate(3, 18, 5.8)

    right_rotate(1, 120, 8)

    right_rotate(1, 110, 3)

    left_rotate(3, 14, 5)

    goto(20, -106)

    fillcolor('black')

    end_fill()

    fill_color_patch(-8, -117)

    begin_fill()

    set_start(-8, -117, w=1, c='black')

    right_rotate(1, 100, 8)

    right_rotate(1, 115, 4)

    left_rotate(2, 16, 5)

    left_rotate(1, 22, 6)

    right_rotate(1, 125, 8)

    right_rotate(1, 120, 3)

    left_rotate(1, 25, 4)

    left_rotate(3, 15, 4)

    goto(-8, -117)

    fillcolor('black')

    end_fill()

    fill_color_patch(-12, -137)

    begin_fill()

    set_start(-12, -137, w=1, c='black')

    right_rotate(1, 145, 8)

    right_rotate(1, 148, 4)

    left_rotate(2, 18, 3.2)

    right_rotate(1, 55, 7)

    right_rotate(1, 165, 3)

    left_rotate(3, 20, 3)

    goto(-12, -137)

    fillcolor('black')

    end_fill()

    fill_color_patch(-6, -144)

    begin_fill()

    set_start(-6, -144, w=1, c='black')

    right_rotate(1, 35, 6)

    right_rotate(1, 105, 4)

    left_rotate(3, 16, 5.5)

    right_rotate(1, 130, 5)

    right_rotate(1, 78, 3)

    left_rotate(3, 5, 4)

    goto(-6, -144)

    fillcolor('black')

    end_fill()

    fill_color_patch(23, -115)

    begin_fill()

    set_start(23, -115, w=1, c='black')

    right_rotate(1, 60, 8)

    right_rotate(1, 120, 4)

    left_rotate(3, 12, 5.3)

    right_rotate(1, 100, 8)

    right_rotate(1, 130, 3)

    left_rotate(3, 15, 5)

    goto(23, -115)

    fillcolor('black')

    end_fill()

    fill_color_patch(32, -133)

    begin_fill()

    set_start(32, -133, w=1, c='black')

    right_rotate(1, 140, 6)

    right_rotate(1, 110, 4)

    left_rotate(3, 8, 5)

    right_rotate(1, 80, 7)

    right_rotate(1, 140, 3)

    left_rotate(3, 14, 6)

    goto(32, -133)

    fillcolor('black')

    end_fill()

    fill_color_patch(39, -135)

    begin_fill()

    set_start(39, -135, w=1, c='black')

    right_rotate(1, 30, 7)

    right_rotate(1, 80, 3)

    left_rotate(3, 20, 2.2)

    right_rotate(1, 160, 5)

    right_rotate(1, 60, 3)

    left_rotate(2, 15, 3)

    goto(39, -135)

    fillcolor('black')

    end_fill()

    fill_color_patch(14, -153)

    begin_fill()

    set_start(14, -153, w=1, c='black')

    right_rotate(1, 90, 7)

    right_rotate(1, 130, 3.5)

    right_rotate(1, 60, 3)

    goto(14, -153)

    fillcolor('black')

    end_fill()

if __name__ == '__main__':

    title('世界盃吉祥物拉伊卜Laeeb(公眾號:小斌哥ge)')

    wide = 600

    height = 500

    screensize(wide, height, '#FF0049')

    setup(wide+30, height+30, 100, 50)

    shape(name='turtle')

    time.sleep(2)

    # draw_body()

    # draw_head()

    # draw_mouth()

    # draw_eye()

    # draw_cap()

    # draw_hair()

    draw_football()

    # draw_clothes()

    set_start(1000, 1000, 1)

    done()

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2926227/,如需轉載,請註明出處,否則將追究法律責任。

相關文章