编程实心圆形怎么编

时间:2025-01-25 03:51:37 网络游戏

Python

方法一:使用turtle库

```python

import turtle

def draw_circle(radius):

turtle.speed(10) 设置画笔速度

turtle.begin_fill() 开始填充形状

turtle.circle(radius) 绘制圆形

turtle.end_fill() 结束填充形状

if __name__ == "__main__":

radius = int(input("请输入圆的半径: "))

draw_circle(radius)

turtle.done() 结束绘图

```

方法二:使用turtle库,设置画笔颜色和填充颜色

```python

import turtle

window = turtle.Screen()

pen = turtle.Turtle()

pen.color("black")

pen.fillcolor("red")

pen.speed(2)

pen.shape("turtle")

radius = 100

pen.begin_fill()

pen.circle(radius)

pen.end_fill()

pen.hideturtle()

window.mainloop()

```

方法三:使用turtle库的dot()函数

```python

import turtle

def draw_circle(size, color):

pen = turtle.Turtle()

pen.penup()

pen.dot(size, color)

pen.forward(size)

pen.goto(-200, 0)

draw_circle(20, 'red')

draw_circle(40, 'green')

draw_circle(60, 'blue')

turtle.done()

```

JavaScript

使用HTML5的Canvas API绘制实心圆:

```html

Draw Solid Circle