用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - python代码库

python画标准国旗

2022-10-01 作者: Python自学举报

[python]代码库

# coding: utf-8

import turtle
import time
import math

turtle.setup(width=1.0, height=1.0, startx=None, starty=None)
turtle.ht()
# turtle.tracer(0, 0)
turtle.bgcolor("white")
turtle.speed(10)
turtle.pensize(1)


# 绘制星星
def star(center, angle, length, penc, fillc):
    turtle.pensize(1)
    turtle.fillcolor(fillc)
    turtle.pencolor(penc)
    L = length * math.sin(36 * math.pi / 180) / math.sin(54 * math.pi / 180)
    turtle.up()
    turtle.goto(center)
    turtle.seth(90 + angle)
    turtle.fd(length)
    turtle.seth(180 + 72 + angle)
    turtle.down()
    turtle.begin_fill()
    for _ in range(5):
        turtle.fd(L)
        turtle.right(72)
        turtle.fd(L)
        turtle.left(144)
    turtle.end_fill()


# 绘制长方形
def rectangle(center, length_x, length_y, penc, fillc):
    turtle.pensize(1)
    turtle.fillcolor(fillc)
    turtle.pencolor(penc)
    turtle.up()
    pos = (center[0] - length_x / 2, center[1] + length_y / 2)
    turtle.goto(pos)
    turtle.begin_fill()
    turtle.down()
    turtle.seth(0)
    turtle.fd(length_x)
    turtle.seth(-90)
    turtle.fd(length_y)
    turtle.seth(180)
    turtle.fd(length_x)
    turtle.seth(90)
    turtle.fd(length_y)
    turtle.end_fill()


W = 1200
H = 800
dW = W / 30
dH = H / 20

# time.sleep(6)

rectangle((0, 0), W, H, 'red', 'red')
C0 = (-dW * 10, dH * 5)

A0 = 0
L0 = dW * 3
star(C0, A0, L0, 'yellow', 'yellow')
C1 = (-dW * 5, dH * 8)
A1 = 90 + math.atan(3 / 5) * 180 / math.pi
L1 = dW
star(C1, A1, L1, 'yellow', 'yellow')
C2 = (-dW * 3, dH * 6)
A2 = 90 + math.atan(1 / 7) * 180 / math.pi
L2 = dW
star(C2, A2, L2, 'yellow', 'yellow')
C3 = (-dW * 3, dH * 3)
A3 = 90 - math.atan(2 / 7) * 180 / math.pi
L3 = dW
star(C3, A3, L3, 'yellow', 'yellow')
C4 = (-dW * 5, dH)
A4 = 90 - math.atan(4 / 5) * 180 / math.pi
L4 = dW
star(C4, A4, L4, 'yellow', 'yellow')

turtle.hideturtle()
turtle.done()

[代码运行效果截图]


python画标准国旗


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...