Python画五星红旗

单颗星

效果图:

 单颗星代码:

import turtle
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)

五星红旗

五星红旗1效果图:

 五星红旗1代码:

import turtle as t

t.bgcolor("red")


def wjx(x):
    t.begin_fill()
    t.fillcolor("yellow")
    for i in range(5):
        t.pencolor("yellow")
        t.fd(x)
        t.right(144)
    t.end_fill()


t.up()
t.goto(-600, 220)
t.down()
wjx(150)

t.up()
t.goto(-400, 295)
t.setheading(305)
t.down()
wjx(50)

t.up()
t.goto(-350, 212)
t.setheading(30)
t.down()
wjx(50)

t.up()
t.goto(-350, 145)
t.setheading(5)
t.down()
wjx(50)

t.up()
t.goto(-400, 90)
t.setheading(300)
t.down()
wjx(50)
t.hideturtle()
t.done()

五星红旗2效果图:

 五星红旗2代码:

# coding: utf-8

import turtle
import math

turtle.setup(width=1.0, height=1.0, startx=None, starty=None)
turtle.ht()
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


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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值