python画同心圆循环代码(python画同心圆并分别填充颜色)
加载中程序怎么编写画同心圆
加载中程序编写画同心圆。
1、打开在线python编辑器。这里用Python中的turtle函数画同心圆。
2、定义画圆的初始代码。
3、循环执行画5个同心圆。turtle.circle是从下方开始画圆的,画同心圆,则每一次都要将画笔移动到下一个圆的底部位置。
4、点击程序左上角的”运行“,查看画出的同心圆的效果。
python画同心圆并填充颜色
用海龟画图,代码如下:
import turtle
my_colors=('red','green','yellow','blue','black')
t=turtle.Pen()
for i in range(5):
t.penup()
t.goto(0,-i*10)
t.pendown()
t.color(my_colors[i%len(my_colors)])
t.circle(15+i*10)'''t.goto(0,0)
turtle.done()#程序执行完,窗口仍然在
python turtle画4个同心圆方法
import?turtle
#draw?first?circle
turtle.penup()
turtle.goto(0,-200)
turtle.pendown()
turtle.circle(200)
#draw?second?circle
turtle.penup()
turtle.goto(0,-150)
turtle.pendown()
turtle.circle(150)
#draw?third?circle
turtle.penup()
turtle.goto(0,-100)
turtle.pendown()
turtle.circle(100)
#draw?fourth?circle
turtle.penup()
turtle.goto(0,-50)
turtle.pendown()
turtle.circle(50)
画笔的坐标默认在0,0,就以它为圆心。
因为turtle画圆的时候是从圆的底部开始画的,所以需要找到四个圆底部的坐标
比如:
第一个半径为200的圆,底部为(0,-200)
第二个半径为150的圆,底部为(0,-150)
第三个半径为100的圆,底部为(0,-100)
第四个半径为 ?50的圆,底部为(0, ?-50)
画的时候按下面的步骤:
抬起画笔:turtle.penup()
移动到相应坐标:turtle.goto(坐标)
放下画笔:turtle.pendown()
画圆:turtle.circle(半径)
效果如下图所示: