python turtle画4个同心圆方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(半径)


效果如下图所示:



参考技术A

代码

结果:

结果

可以画任意个同心圆,顺序、大小可改变

参考技术B from turtle import *

def test():
reset()
circle(30,-360)
up()
goto(0,-10)
down()
circle(40,-360)
up()
goto(0,-20)
down()
circle(50,-360)
up()
goto(0,-30)
down()
circle(60,-360)

if __name__ == '__main__':
test()

参考技术C from turtle import *
def Circle(radius,angle,length):
for i in range(length):
penup()
goto(0,angle)
pendown()
circle(radius)
angle=angle+50
radius=radius-50
Circle(200,-200,4)
done()

turtle库基础练习

1.画一个同切圆

import turtle
turtle.circle(20)
turtle.circle(30)
turtle.circle(50)
turtle.circle(100)

 

2.画一个同心圆

import turtle
turtle.circle(30)
turtle.up()
turtle.goto(0,-30)
turtle.down()
turtle.circle(50)
turtle.up()
turtle.goto(0,-50)
turtle.down()
turtle.circle(80)
turtle.up()
turtle.goto(0,-80)
turtle.down()
turtle.circle(100)
turtle.up()
turtle.goto(0,-100)
turtle.down()

 

3.画一个五角星

 

import turtle
turtle.color(\'yellow\')
turtle.fillcolor(\'yellow\')
turtlr.bgcolor(\'red\')
turtle.begin_fill()
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.end_fill()


 

 

4.画一个黄色实心五角星

import turtle
turtle.shape(\'turtle\')
turtle.color(\'pink\')
turtle.bgcolor(\'red\')
turtle.fillcolor(\'yellow\')
turtle.begin_fill()
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.end_fill()
turtle.hideturtle()

5.画左上角的五颗五角星

mport turtle

turtle.color(\'yellow\')
turtle.bgcolor(\'red\')
turtle.fillcolor(\'yellow\')

turtle.up()
turtle.goto(-600,250)
turtle.down()
turtle.begin_fill()
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.end_fill()

turtle.up()
turtle.goto(-450,290)
turtle.down()
turtle.begin_fill()
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.end_fill()

turtle.up()
turtle.goto(-425,265)
turtle.down()
turtle.begin_fill()
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.end_fill()

turtle.up()
turtle.goto(-445,175)
turtle.down()
turtle.begin_fill()
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.end_fill()

turtle.up()
turtle.goto(-455,145)
turtle.down()
turtle.begin_fill()
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.right(144)
turtle.forward(35)
turtle.end_fill()

turtle.hideturtle()

以上是关于python turtle画4个同心圆方法的主要内容,如果未能解决你的问题,请参考以下文章

Python之turtle画同心圆和棋盘

4个同心圆

条件循环函数定义 练习

python 9.13作业

条件循环函数定义练习

条件循环函数定义字符串操作练习