We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I got a question: First off: I'm using Python Mode. I'm trying to instantiate an object 10 times, but whatever i do ends up in the ellipses getting a tremendous speed boost. The idea is: Create 10 ellipses all spawning on different locations and with different velocity. Is this possible using lists? Here is the code, creating 1 instance of the object:
from BallTab import Ball def setup(): global myFirstBall size(800, 800) myFirstBall = Ball(random(50, 750), random(50, 750), 2, 3, 100) def draw(): global myFirstBall background(69, 69, 69) myFirstBall.display() myFirstBall.move() if myFirstBall.y > 750: myFirstBall.ys = -2 if myFirstBall.x > 750: myFirstBall.xs = -3 if myFirstBall.y < 50: myFirstBall.ys = 2 if myFirstBall.x < 50: myFirstBall.xs = 3
class Ball(object): def __init__(self, xPos, yPos, xSpeed, ySpeed, radius): self.x = xPos self.y = yPos self.xs = xSpeed self.ys = ySpeed self.r = radius def display(self): ellipse(self.x, self.y, self.r, self.r) def move(self): self.x += self.xs self.y += self.ys