im a beginner in python, and i just started to learn pygame. im making a drawing that draws a spirograph and moves the circles away from the center by each color group. What i mean is, since there are 7 colors, and each color has 5 circles, i want to move all of the circles away from the center starting with all the red circles, then blue, then green etc. But the catch is, all 5 circles per color group has to move away from the center AT ONCE, then when the first group is done moving, continue moving the other groups one by one until it draws almost a bracelet-like drawing.
I want to know how i can move the circles diagonally, like in turtle. I also need to know how to move the circles in a group, one by one. Do i make a list and store the circles in the list? I honestly have no idea. I've basically almost given up trying to do this lol. Below is my current code, and if you run it you can see that i can only move the entire spirpograph, and not the circles. Any help would be appreciated.
import pygame
import math
import time
#setting colors
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
ORANGE = (255, 127, 0)
YELLOW = (255, 255, 0)
PURPLE = (160, 32, 240)
#setting what order the colors go in
listCircleColor = (RED, BLUE, GREEN, ORANGE, YELLOW, PURPLE, WHITE)
#how many circles per color
intGroup = 5
#the space between each circle
turnangle = 360/35
#width of screen
width = 600
#height of screen
height = 600
#radius of circles
radius = 100
#making the screen
screen = pygame.display.set_mode((width, height))
#if the code is running, then continue
running = True
##.draw.circle(screen, BLUE, (0, 0), radius, width=2)
circles = []
circles_rect = []
#draw
alpha = turnangle
for i in range(intGroup):
for cl in listCircleColor:
surfacetemp = pygame.Surface((width, height))
surfacetemp = surfacetemp.convert_alpha()
surfacetemp.fill((0, 0, 0, 0))
##circlerect = pygame.rect
if alpha > 0 and alpha < 90:
circlerect = pygame.draw.circle(surfacetemp, cl, (300 + radius * math.cos(math.radians(alpha)), 300 + radius * math.sin(math.radians(alpha))), radius, width=2)
# second quarter of circles
if alpha > 90 and alpha < 180:
circlerect = pygame.draw.circle(surfacetemp, cl, (300 - radius * math.cos(math.radians(180 - alpha)), 300 + radius * math.sin(math.radians(180 - alpha))), radius, width=2)
# third quarter of circles
if alpha > 180 and alpha < 270:
circlerect = pygame.draw.circle(surfacetemp, cl, (300 - radius * math.cos(math.radians(270 - alpha)), 300 - radius * math.sin(math.radians(270 - alpha))), radius, width=2)
# last quarter of circles
if alpha > 270 and alpha < 360:
circlerect = pygame.draw.circle(surfacetemp, cl, (300 + radius * math.cos(math.radians(360 - alpha)), 300 - radius * math.sin(math.radians(360 - alpha))), radius, width=2)
alpha = alpha + turnangle
##circles.append(circlerect)
circles.append(surfacetemp)
circles_rect.append(surfacetemp.get_rect())
# move"
#exit only when user clicks on exit button
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
screen.fill((0, 0, 0))
for crect, ret in zip(circles, circles_rect):
ret.right += 5
ret.left += 5
screen.blit(crect, ret)
pygame.display.flip()
clock.tick(20)