网站首页 网站地图
网站首页 > 娱乐人生 > 编程代码怎么画圆

编程代码怎么画圆

时间:2026-03-17 16:33:13

1. 使用Python的matplotlib库

```python

import matplotlib.pyplot as plt

import numpy as np

def plot_circle(center, radius):

theta = np.linspace(0, 2*np.pi, 100)

x = center + radius * np.cos(theta)

y = center + radius * np.sin(theta)

plt.plot(x, y)

plt.axis('equal') 设置x轴和y轴的比例相等,使圆不会被拉伸

plt.show()

示例:画一个半径为5的圆,圆心坐标为(0, 0)

center = (0, 0)

radius = 5

plot_circle(center, radius)

```

2. 使用Python的turtle库

```python

import turtle

def draw_circle(radius):

turtle.circle(radius)

turtle.done()

示例:画一个半径为50的圆

draw_circle(50)

```

3. 使用JavaScript和HTML5 Canvas

```html

Draw Circle