python五角星代码(python五角星代码红色)

http://www.itjxue.com  2023-02-11 16:31  来源:未知  点击次数: 

请问如何用Python turtle画一个多角星?

一般是要靠算角度的

import turtle

import time

turtle.forward(100)

turtle.right(144)

time.sleep(1)

turtle.forward(100)

turtle.right(144)

time.sleep(1)

turtle.forward(100)

turtle.right(144)

turtle.forward(100)

time.sleep(1)

turtle.right(144)

turtle.forward(100)

time.sleep(3)

你可以写一个子函数通过给定的角的数量用公式计算出角度再代入上述代码的角度参数里就OK了

如何用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中怎么把五角星画在中间

from?turtle?import?*

fillcolor("red")

begin_fill()

while?True:

????forward(200)

????right(144)

????if?abs(pos())??1:

????????break

end_fill()

运行这段代码,会绘制出一个红色五角星图形。

码字不易,望采纳。

如何采用Python语言绘制一个五角星

#!/usr/bin/env python

import turtle

import time

turtle.forward(100)

turtle.right(144)

time.sleep(1)

turtle.forward(100)

turtle.right(144)

time.sleep(1)

turtle.forward(100)

turtle.right(144)

turtle.forward(100)

time.sleep(1)

turtle.right(144)

turtle.forward(100)

time.sleep(3)

如何用python画一个五角星

#!/usr/bin/env python

import turtle

import time

turtle.forward(100)

turtle.right(144)

time.sleep(1)

turtle.forward(100)

turtle.right(144)

time.sleep(1)

turtle.forward(100)

turtle.right(144)

turtle.forward(100)

time.sleep(1)

turtle.right(144)

turtle.forward(100)

time.sleep(3)

python五角星

看不清代码 不过看了下图 应该是画笔起始位置和圆心位置计算错误 计算下画笔起始位置和圆心位置差 定位画笔起始位置画吧 比如你这个五角星应该是从左边中间的角开始话的 那么把这个起点位置调一下 (-185.0)这个改下 主要应该是高度0这个参数

(责任编辑:IT教学网)

更多

推荐java认证文章