用编程怎么做圆盘

时间:2025-01-26 02:03:26 网络游戏

使用Pygame库制作圆盘

Pygame是一个Python库,用于制作视频游戏。以下是一个使用Pygame制作圆盘的示例代码:

```python

import pygame

import sys

初始化Pygame和创建屏幕

pygame.init()

width, height = 800, 600

screen = pygame.display.set_mode((width, height))

定义颜色

WHITE = (255, 255, 255)

BLACK = (0, 0, 0)

绘制圆盘背景

def draw_background():

screen.fill(WHITE)

pygame.draw.circle(screen, BLACK, (width // 2, height // 2), 200)

绘制数字

def draw_number(number):

font = pygame.font.Font(None, 100)

text = font.render(str(number), True, BLACK)

text_rect = text.get_rect(center=(width // 2, height // 2))

screen.blit(text, text_rect)

主循环

while True:

for event in pygame.event.get():

if event.type == pygame.QUIT:

pygame.quit()

sys.exit()

draw_background()

draw_number(42) 在圆盘上绘制数字42

pygame.display.flip()

```

使用HTML和CSS制作圆盘

```html

Circle Disk with Text

42