Python葫芦图形7个


简单的一个小创意, 上Python课的一个例子:

import turtle

cs = ['red','orange','yellow','green','cyan','blue','purple']

turtle.color('purple')
turtle.bgcolor('black')
turtle.speed(0)
turtle.delay(0)
turtle.bk(300)

for y in range(7):
    turtle.color(cs[y])
    turtle.right(90)
    for x in range(1,51):
        turtle.pensize(x)
        turtle.fd(1)
    turtle.pensize(1)
    
    turtle.fd(50)
    turtle.dot(70)
    
    turtle.bk(100)          # 退后50
    turtle.left(90)         # 左转90度
    turtle.color('brown')
    turtle.fd(100)          # 前进100

turtle.penup()
turtle.home()               # 回家
turtle.left(90)
turtle.fd(100)
turtle.color('white')
# align对齐,方式有center,left,right
# font字体,小括号括起来的一些数据叫元组, 斜体:italic  粗体:bold, 下划线:underline
turtle.write("葫芦娃",align='center',font=('黑体',32,'italic'))
turtle.done()

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在python, turtle分类目录,贴了标签。将固定链接加入收藏夹。

发表回复