🌈据说,看我文章时 关注、点赞、收藏 的 帅哥美女们 心情都会不自觉的好起来。
前言:
🧡作者简介:大家好我是 user_from_future ,意思是 “ 来自未来的用户 ” ,寓意着未来的自己一定很棒~
✨个人主页:点我直达,在这里肯定能找到你想要的~
👍专栏介绍:Python绘图 ,一个专注于分享绘图案例与教学的专栏~
专栏文章直链:
【Python绘图】绘图常见的构成元素2
【Python绘图】绘图常见的构成元素1
【Python绘图】学习绘图第一步,先要知道哪些操作是常用的
【Python绘图】朋友过生日不知道送什么?免费的蛋糕送给他
Python基础图形绘图教学3
绘画蜡烛
先从之前的蛋糕案例中搞几个已经写好的图形。
根据蜡烛底部的中心坐标、蜡烛的高度宽度绘制蜡烛,以蜡烛的宽度作为烛焰的直径:
def draw_candle(location, width, height):
"""
画蜡烛。
:param location: 蜡烛底部中心坐标
:param width: 蜡烛宽度
:param height: 蜡烛高度
"""
color = turtle.color()
angle = turtle.heading()
turtle.penup()
turtle.color('skyblue')
turtle.setheading(0)
turtle.goto(*location)
turtle.pendown()
turtle.begin_fill()
turtle.forward(width / 2)
turtle.setheading(90)
turtle.forward(height)
turtle.setheading(180)
turtle.forward(width)
turtle.setheading(270)
turtle.forward(height)
turtle.setheading(0)
turtle.forward(width / 2)
turtle.end_fill()
turtle.penup()
turtle.setheading(90)
turtle.forward(height)
turtle.setheading(20)
turtle.color('red')
turtle.pendown()
turtle.begin_fill()
turtle.circle(width / 2, 180)
turtle.setheading(20)
turtle.circle(-width / 4, 180)
turtle.setheading(200)
turtle.circle(width / 4, 180)
turtle.end_fill()
turtle.penup()
turtle.color(*color)
turtle.goto(*location)
turtle.setheading(angle)
这个还是很简单,一个长方形和一个半太极就完成了。
绘画椭圆
这里就是通过椭圆中心坐标进行绘图的,比从边开始绘图方便了点,易于管理:
def draw_oval(location, width, height, fill=True, color='#000000'):
"""
画椭圆。
:param location: 椭圆中心坐标
:param width: 椭圆长轴(横向)
:param height: 椭圆短轴(纵向)
:param fill: 是否填充
:param color: 椭圆颜色
"""
assert width >= height, ValueError('目前只能长轴是 x 轴,即 width >= height (width == height 时是圆)!')
a = width / 2
b = height / 2
color_old = turtle.color()
angle = turtle.heading()
turtle.color(color)
turtle.penup()
turtle.goto(*location)
turtle.setheading(0)
turtle.forward(width / 2)
turtle.setheading(90)
turtle.pendown()
if fill:
turtle