python可视化绘图2.0

五星红旗

import turtle
import math
 
turtle.pensize(3)
turtle.colormode(255)
 
# 画背景
turtle.pencolor("#ed120c")
turtle.fillcolor("#ed120c")
turtle.begin_fill()
turtle.penup()
turtle.goto(-150, 100)
turtle.pendown()
 
for i in [300, 200, 300, 200]:
    turtle.forward(i)
    turtle.right(90)
turtle.left(90)
turtle.end_fill()
turtle.penup()
 
 
#画五角星函数,要求传入五角星中心坐标,五角星外接圆半径,五角星逆时针旋转角度(默认角度0度为向上,即大五角星方向)
def Pentagram(x, y, radius, degree):
    length = (radius * math.sqrt(8) // 3) * 2  # 根据五角星外接圆半径计算五角星长度
 
    turtle.goto(x, y)  # 五角星外接圆中心坐标(即五角星中心坐标)
    turtle.left(degree)  # 五角星逆时针旋转多少度
    turtle.forward(radius)  # 前进外接圆半径距离,到达五角星顶点
    turtle.pendown()
 
    # 以下为标准画五角星代码,画笔颜色及填充颜色可以通过取色器取
    turtle.right(162)
    turtle.pencolor("#f4ec20")
    turtle.fillcolor("#f4ec20")
    turtle.begin_fill()
    for _ in range(5):
        turtle.forward(length)
        turtle.right(144)
    turtle.end_fill()
    turtle.left(162)
 
    turtle.right(degree)
    turtle.penup()
 
 
# 画大五角星
Pentagram(-100, 50, 30, 0)
 
# 画第一个小五角星
degree1 = 90 + math.atan(3 / 5) * 180 / math.pi  # 计算第一个小五角星相对于大五角星的逆时针旋转角度,atan计算弧度需要转化为角度
Pentagram(-50, 80, 10, degree1)
 
# 画第二个小五角星
degree2 = 90 + math.atan(1 / 7) * 180 / math.pi
Pentagram(-30, 60, 10, degree2)
 
# 画第三个小五角星
degree3 = 90 - math.atan(2 / 7) * 180 / math.pi
Pentagram(-30, 30, 10, degree3)
 
# 画第四个小五角星
degree4 = 90 - math.atan(4 / 5) * 180 / math.pi
Pentagram(-50, 10, 10, degree4)
 
turtle.hideturtle()
turtle.done()

在这里插入图片描述

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值