美文网首页
使用python3的turtle库制作日本旗

使用python3的turtle库制作日本旗

作者: 虚无一代 | 来源:发表于2017-12-02 14:10 被阅读0次

代码

import turtle


def main():
    t = turtle.Turtle()
    t.hideturtle()
    rectangle(t, -500, 309, 1000, 618)
    redsun(t)
    write(t)


def rectangle(t, x, y, w, h, color1='white', color2='black'):
    t.fillcolor(color1)
    t.begin_fill()
    t.pencolor(color2)
    t.up()
    t.goto(x, y)
    t.down()
    t.goto(x + w, y)
    t.goto(x + w, y - h)
    t.goto(x, y - h)
    t.goto(x, y)
    t.end_fill()


def redsun(t):
    t.up()
    t.goto(0, 0)
    t.down
    t.dot(350, 'red')


def write(t):
    t.up()
    t.goto(0, -250)
    t.write('japanese flag', font=(30), align='center')


main()
turtle.done()

效果图

image.png

代码注意事项:

  1. t.fillcolor(color1) 语句需要写在t.begin_fill()之前
  2. 要想使自己绘制的图形停留可以使用turtle.done()语句

另外需要注意:

使用模块化的编程,这样代码会更清晰一些

相关文章

网友评论

      本文标题:使用python3的turtle库制作日本旗

      本文链接:https://www.haomeiwen.com/subject/yadnbxtx.html