python随机生成两个数给ab_python-如何在Pygame中随机生成的两个点之间...

这篇博客讲述了如何使用Python的pygame库来生成两个随机位置的半径为10的圆,并在它们之间画出一系列半径为2的小圆。作者遇到了在两点间沿直线路径画小圆的难题,尝试了Bresenham’s line algorithm但觉得过于复杂。提供的代码展示了如何绘制大圆,但尚未实现小圆的绘制功能。
摘要由CSDN通过智能技术生成

我正在处理的作业问题如下:

“Draw two randomly placed radius 10 circles on the screen then draw radius 2 circles every twenty pixels from the center of one to the center of the other.”

我可以轻松地随机生成两个半径为10的圆,但是我不知道如何在它们之间绘制半径为2的圆.

我已经尝试过在它们之间画一条线,如果有办法沿着这条线画我的点,我绝对可以做到.我查找了类似的问题,其中很多提到Bresenham’s line algorithm,但我怀疑这是答案,因为它似乎非常先进.

这是我到目前为止解决该问题的代码:

import pygame

from random import randint

linecolour = 0,0,0

bgcolour = 255, 255, 255

width = 600

height = 600

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

running = 1

x = []

y = []

for i in range (2):

x.append(randint(0,600))

y.append(randint(0,600))

done = False

while not done:

for event in pygame.event.get():

if event.type == pygame.QUIT: # or other types of events

done = True

screen.fill(bgcolour)

for i,j in zip(x,y):

pygame.draw.circle(screen,linecolour,(i,j),10)

pygame.draw.circle(screen,linecolour,(i,j),2)

pygame.display.flip()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值