怎么用Python绘制五环

2024-10-29 04:15:02
推荐回答(3个)
回答1:

1、创建python文件,test5circle.py;

2、编写python代码,分别定义颜色、圆的位置、圆的半径等,并进行绘画;

import turtle 

turtle.color("blue") #定义颜色

turtle.penup() 

turtle.goto(-110,-25) 

turtle.pendown()

turtle.circle(45) #圆的半径

turtle.color("black")

turtle.penup()

turtle.goto(0,-25)

turtle.pendown()

turtle.circle(45)

turtle.color("red")

turtle.penup()

turtle.goto(110,-25)

turtle.pendown()

turtle.circle(45)

turtle.color("yellow")

turtle.penup()

turtle.goto(-55,-75)

turtle.pendown()

turtle.circle(45)

turtle.color("green")

turtle.penup()

turtle.goto(55,-75)

turtle.pendown()

turtle.circle(45)

input()

3、右击并选择‘在终端中运行Python文件’选项,执行python代码;

4、查看运行结果,可以发现代码绘制的五环;

回答2:

1 import turtle #导入turtle模块

2 turtle.color("blue") #定义颜色
3 turtle.penup() #penup和pendown()设置画笔抬起或放下时是否绘制直线

4 turtle.goto(-110,-25) #初始位置以中心坐标为(0,0)

5 turtle.pendown()
6 turtle.circle(45) #绘制圆的半径

7

8 turtle.color("black")

9 turtle.penup()
10 turtle.goto(0,-25)
11 turtle.pendown()
12 turtle.circle(45)
13

14 turtle.color("red")
15 turtle.penup()
16 turtle.goto(110,-25)
17 turtle.pendown()
18 turtle.circle(45)
19

20 turtle.color("yellow")
21 turtle.penup()
22 turtle.goto(-55,-75)
23 turtle.pendown()
24 turtle.circle(45)
25

26 turtle.color("green")
27 turtle.penup()
28 turtle.goto(55,-75)
29 turtle.pendown()
30 turtle.circle(45)
31

32 input()

回答3:

matplotlib中把结果存成图片,然后tkinter中打开图片