用python函数画德国国旗代码_求一段python中用class方法绘制国旗的代码!记得不是常见的海龟做法!这个星期给我再加送财富点!...

展开全部

from matplotlib import patches, pyplot as plt

from math import sin, cos, pi

fig = plt.figure(figsize=(6, 4))

ax = fig.add_subplot(111)

def star(coord, size, rotate):

pts = [(size * sin(i * 4 * pi / 5 + rotate) + coord[0], size * cos(i * 4 * pi / 5 + rotate) + coord[1]) for i in range(5)]

return patches.Polygon(pts, fc='yellow', ec='yellow')

ax.add_patch(patches.Rectangle([0, -2], 3, 2, fc='red', ec='red'))

ax.add_patch(star((0.5, -0.5), 0.3, 0.0))

ax.add_patch(star((1.0, -0.2), 0.07, 0.3))

ax.add_patch(star((1.2, -0.4), 0.07, 0.9))

ax.add_patch(star((1.2, -0.7), 0.07, 0.0))

ax.add_patch(star((1.0, -0.9), 0.07, 0.3))

ax.set_axis_off()

plt.axis('scaled')

plt.show()

import turtle

import time

import os

#

def draw_square(org_x, org_y, x, y):

turtle.setpos(org_x, org_y) # to left and bottom connor

turtle.color('red', 'red')

turtle.begin_fill()

turtle.fd(x)

turtle.lt(90)

turtle.fd(y)

turtle.lt(90)

turtle.fd(x)

#print(turtle.pos())

turtle.lt(90)

turtle.fd(y)

turtle.end_fill()

def draw_star(center_x, center_y, radius):

print(center_x, center_y)

turtle.pencolor('black')

turtle.setpos(center_x, center_y)

pt1 = turtle.pos()

turtle.circle(-radius, 360 / 5)

pt2 = turtle.pos()

turtle.circle(-radius, 360 / 5)

pt3 = turtle.pos()

turtle.circle(-radius, 360 / 5)

pt4 = turtle.pos()

turtle.circle(-radius, 360 / 5)

pt5 = turtle.pos()

turtle.color('yellow', 'yellow')

turtle.begin_fill()

turtle.goto(pt3)

turtle.goto(pt1)

turtle.goto(pt4)

turtle.goto(pt2)

turtle.goto(pt5)

turtle.end_fill()

print(turtle.pos())

turtle.pu()

draw_square(-320, -260, 660, 440)

star_part_x = -320

star_part_y = -260 + 440

star_part_s = 660 / 30

center_x, center_y = star_part_x + star_part_s * 5, star_part_y - star_part_s * 5

turtle.setpos(center_x, center_y) # big star center

turtle.lt(90)

draw_star(star_part_x + star_part_s * 5, star_part_y - star_part_s * 2, star_part_s * 3)

# draw 1st small star

turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 2) # go to 1st small star center

turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())

turtle.fd(star_part_s)

turtle.rt(90)

draw_star(turtle.xcor(), turtle.ycor(), star_part_s)

# draw 2nd small star

turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 4) # go to 1st small star center

turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())

turtle.fd(star_part_s)

turtle.rt(90)

draw_star(turtle.xcor(), turtle.ycor(), star_part_s)

# draw 3rd small star

turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 7) # go to 1st small star center

turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())

turtle.fd(star_part_s)

turtle.rt(90)

draw_star(turtle.xcor(), turtle.ycor(), star_part_s)

# draw 4th small star

turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 9) # go to 1st small star center

turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())

turtle.fd(star_part_s)

turtle.rt(90)

draw_star(turtle.xcor(), turtle.ycor(), star_part_s)

turtle.ht()

time.sleep(5)

os._exit(1)

两个版本,仅供参考62616964757a686964616fe4b893e5b19e31333361326266

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值