python绘图turtle之五角星与小蟒蛇

本文通过使用Python的turtle模块,展示了如何绘制复杂的图形,包括特殊形状的填充、五角星和一条蜿蜒的小蟒蛇,同时介绍了如何利用循环和条件语句来创建动态图形效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import turtle as t
t.screensize(canvwidth =None,canvheight=None,bg="#999")
t.setup(width=1.0,height=1.0,startx=-1,starty=-1)
#设置画笔的大小
t.pensize(2)
#设置画笔速度
t.speed(10)
t.penup()
t.goto(-500,100)
t.color("#0dd","#0f0")
t.begin_fill()

for i in range(41):
    t.pendown()
    t.fd(150)
    t.seth(80+80*i-i)
t.end_fill()
#提笔
t.up()
#变量清零
del(i)
#
#五角星
#
t.goto(-600,-100)
t.color("red","yellow")
t.begin_fill()
i = 0
while i< 5:
    i+=1
    t.down()
    t.forward(200)
    t.setheading(-144*i)
t.end_fill()
t.up()
del(i)
#
#小蟒蛇 
#
t.goto(0,300)
t.pencolor("#0df")
t.pensize(5)
t.down()
t.seth(-45)   
i =0
while i < 33:
    i += 1
    t.circle(5,90)
    t.circle(-5,100)     
t.up()
del(i)
#
#彩色小蟒蛇
#
t.goto(0,0)
colors =['black','grey','darkgreen','gold','violet','purple','green','red']
def huitu(r,angle,length):
    t.seth(-40)
    for i in range(length):
        print(i%8)
        t.pencolor(colors[i%8])
        t.circle(r,angle)
        t.pencolor(colors[(i+1)%8])
        t.circle(-r,angle)
    t.circle(r,angle/2)
    t.fd(40)
    t.circle(16,180)
    t.fd(40*2/3)
t.penup()
t.fd(-350)
t.down()
t.pensize(25)
huitu(35,80,10)


t.done()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值