我正在处理的作业问题如下:
“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()