Python 可以快速、輕松地繪制出各種形狀的圖形,如下面這張玉藻前的圖片。
from turtle import Turtle from math import sin, cos, radians # 玉藻前的頭 def head(turtle): turtle.penup() turtle.goto(0, 100) turtle.pendown() turtle.begin_fill() turtle.circle(50) turtle.end_fill() # 玉藻前的眼睛 def eyes(turtle): turtle.penup() turtle.goto(-20, 130) turtle.pendown() turtle.color("white") turtle.begin_fill() turtle.circle(15) turtle.end_fill() turtle.penup() turtle.goto(20, 130) turtle.pendown() turtle.begin_fill() turtle.circle(15) turtle.end_fill() turtle.penup() turtle.goto(-20, 140) turtle.pendown() turtle.color("black") turtle.begin_fill() turtle.circle(5) turtle.end_fill() turtle.penup() turtle.goto(20, 140) turtle.pendown() turtle.begin_fill() turtle.circle(5) turtle.end_fill() turtle.color("black") # 玉藻前的頭飾 def headwear(turtle): turtle.penup() turtle.goto(0, 180) turtle.setheading(270) turtle.pendown() turtle.begin_fill() turtle.circle(60, -120) turtle.left(90) turtle.forward(40) for i in range(6): turtle.left(60) turtle.forward(40) turtle.left(90) turtle.forward(40) turtle.end_fill() # 玉藻前的髻 def hair(turtle): turtle.penup() turtle.goto(0, 150) turtle.setheading(270) turtle.pendown() turtle.begin_fill() turtle.circle(70, 180) turtle.end_fill() # 玉藻前的帶子 def band(turtle): turtle.penup() turtle.goto(-50, 70) turtle.pendown() turtle.setheading(60) turtle.begin_fill() for i in range(2): turtle.forward(100 * cos(radians(60))) turtle.left(60) turtle.forward(30) turtle.left(120) turtle.forward(30) turtle.left(60) turtle.forward(100 * cos(radians(60))) turtle.left(120) turtle.end_fill() # 創(chuàng)建玉藻前的畫(huà)布 def yuzao(): t = Turtle() t.speed(0) head(t) eyes(t) headwear(t) hair(t) band(t) t.hideturtle() yuzao()
玉藻前是《Fate/Grand Order》游戲中的一名角色,她以美麗的形象和強(qiáng)大的戰(zhàn)斗力受到了廣泛的關(guān)注。利用 Python 畫(huà)出來(lái)的玉藻前,不僅能夠表達(dá)對(duì)這個(gè)角色的熱愛(ài),還能夠展示出 Python 的圖形繪制能力。