Python_海龟绘图2

这篇博客介绍了使用Python海龟模块绘制彩色螺旋线的方法,用户可以选择螺旋的方向(左旋或右旋)以及线条的颜色。此外,还探讨了如何设置线条的填充色和描边色。

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

彩色螺旋线

import turtle
length=int(input('最长线段的长度:'))
direction=int(input('请输入方向值(1:左旋,2:右旋):'))
color=input('请输入颜色英文(red,yellow,blue,black,gold,purple,brown,pink,seashell,tomato,while,magenta,cyan):')
turtle.pencolor(color)
turtle.width(2)
while length>0 :
    turtle.forward(length)
    turtle.back(length)
    if direction==1:
        turtle.left(5)
    else:
        turtle.right(5)
    length=length-5

运行结果

最长线段的长度:300
请输入方向值(1:左旋,2:右旋):2
请输入颜色英文(red,yellow,blue,black,gold,purple,brown,pink,seashell,tomato,while,magenta,cyan):pink
在这里插入图片描述

填充色和描边色

import turtle
n=int(input("请输入边数:"))
turtle.penup()
turtle.goto(-200,200)    
turtle.pendown()
turtle.width(5)
turtle.pencolor("yellow")
turtle.fillcolor("red")
turtle.begin_fill()
for i in range(1,n+1):
    turtle.forward(100)
    turtle.right(360/n)
turtle.end_fill()
turtle.hideturtle()
turtle.done()

运行结果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值