🌈据说,看我文章时 关注、点赞、收藏 的 帅哥美女们 心情都会不自觉的好起来。
前言:
🧡作者简介:大家好我是 user_from_future ,意思是 “ 来自未来的用户 ” ,寓意着未来的自己一定很棒~
✨个人主页:点我直达,在这里肯定能找到你想要的~
👍专栏介绍:Python绘图 ,一个专注于分享绘图案例与教学的专栏~
前言
今天为什么突然想创建这个专栏呢,主要就是因为今天是农历二月甘四,是博主的生日👑,所以想给自己画一个大大的蛋糕🎁,同时也是为这新的专栏剪彩~ 虽然我这画的可能比较简陋,但毕竟是博主第一次画蛋糕送给自己…
成果图
源代码
# 画生日蛋糕
import math
import turtle
# 元素函数
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.