淘先锋技术网

首页 1 2 3 4 5 6 7

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()
# 创建玉藻前的画布
def yuzao():
t = Turtle()
t.speed(0)
head(t)
eyes(t)
headwear(t)
hair(t)
band(t)
t.hideturtle()
yuzao()

玉藻前是《Fate/Grand Order》游戏中的一名角色,她以美丽的形象和强大的战斗力受到了广泛的关注。利用 Python 画出来的玉藻前,不仅能够表达对这个角色的热爱,还能够展示出 Python 的图形绘制能力。