Hi, I am having trouble trying to use the time_handler to basically spawn a ball every second. I have made a newBalls list where I will append each balls object into the list but the newBalls list is always empty and I have no idea why. Here is the code so for if anybody could explain to me how I would be able to spawn ball(circles) every second using the timer.
Code
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
import random
from Vector import Vector
CANVAS_WIDTH = 600
CANVAS_HEIGHT = 300
totalBalls = 10
newBalls = []
class Ball:
def __init__(self, pos, vel, radius, color):
self.pos = pos
self.vel = vel
self.radius = radius
self.color = color
self.border = 1
def draw(self, canvas):
if(self.radius != 10):
self.radius -= 1
canvas.draw_circle(self.pos.get_p(), self.radius, self.border, self.color, self.color)
def update(self):
self.pos.add(self.vel)
class Interaction:
def __init__(self, ball):
self.ball = ball
def update(self):
for balls in self.ball:
balls.update()
def draw(self, canvas):
self.update()
for balls in self.ball:
balls.draw(canvas)
def randCol():
r = random.randrange (0, 256)
g = random.randrange (0, 256)
b = random.randrange (0, 256)
return 'rgb('+str(r)+ ','+str(g)+ ','+str(b)+ ')'
def randRad():
rad = random.randint(10, 51)
return rad
def randVel():
vel = random.randint(-5, 6)
return vel
def randBall():
randBall = Ball(Vector(CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2), Vector(randVel(),randVel()), randRad(), randCol())
return randBall
#balls = []
balls = [ randBall() for i in range(totalBalls) ]
def time_handler():
global newBalls, balls
for x in range(totalBalls):
newBalls.append(balls[x])
interaction = Interaction(balls)
frame = simplegui.create_frame("Test", CANVAS_WIDTH, CANVAS_HEIGHT)
timer = simplegui.create_timer(1000, time_handler)
frame.set_draw_handler(interaction.draw)
frame.start()
timer.start()




![[Image: Iu0EfTL.gif]](https://i.imgur.com/Iu0EfTL.gif)