python编程画同心圆(python123画一组同心圆)
如何用python画一个同心圆,外环为红色?
#?encoding:?utf-8
#?Python?3.6.0
import?turtle
for?i?in?range(1,3):
????if?i==2:
????????turtle.pencolor("red")
????turtle.pensize(10)
????turtle.penup()
????turtle.goto(0,-60*i)
????turtle.pendown()
????turtle.circle(60*i)
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(半径)
效果如下图所示:
请问怎么用python画出这样的图?
#?encoding:?utf-8
#?Python?3.9.0
#??turtle画出不同颜色的同心环/同心圆
import?turtle
pen=turtle.Turtle()
n=100
colors=['#0000FF','#FF0000','#FFD700','#008000','#800080']
for?i?in?range(5):
????pen.fillcolor(colors[i])
????pen.begin_fill()
????pen.penup()
????pen.goto(0,20*(i+1))
????pen.pendown()
????pen.circle(n-i*20)
????pen.end_fill()
turtle.done()
如何用python画同心圆并内接一个五角星?
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
theta = np.linspace(0, 2* np.pi, 100)
r, R = 9, 10 # 小圆和大圆的半径
# outter circle
X = R * np.cos(theta)
Y = R * np.sin(theta)
# innner circle
x = r * np.cos(theta)
y = r * np.sin(theta)
# pentagon vertices
p_theta = [np.pi/2 + np.pi*4/5 * i for i in range(6)] # 五角星的定点.
px = r * np.cos(p_theta)
py = r * np.sin(p_theta)
# plot
plt.plot(X, Y, label='Big Circle', color='blue')
plt.plot(x, y, label='Small Circle', color='green')
plt.plot(px, py, label='Pentagon', color='red')
plt.axis('equal')
plt.legend(loc='upper left')
用python画一百个同心圆的代码?
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
# 创建一个图形对象
fig = plt.figure()
# 循环绘制一百个同心圆
for i in range(100):
# 使用 Circle 类创建圆形,并指定半径和圆心坐标
circle = Circle(xy=(0, 0), radius=i+1)
# 使用 fig.add_subplot() 方法将圆形添加到图中
ax = fig.add_subplot(1, 1, 1)
ax.add_patch(circle)
# 调用 plt.show() 方法显示图形
plt.show()
请编写Python: 使用小海龟,在屏幕上绘制一系列的同心圆,并未这些同心圆填充上不同颜色?
from turtle import *
from random import *
for i in range(4):
begin_fill()
penup()
goto(0, 30*(i+1)) # 从里面最小的一个圆的底部,慢慢变大
fillcolor((random(), random(), random()))
pendown()
circle(150-30*(i+1))
end_fill()
mainloop()