I’m trying to draw 10 balls at random position by using Class, and here’s my code for that:
--In Main
function setup()
myBalls=balls()
end
function draw()
for i=1,10 do
myBalls:draw()
end
end
--In Class balls
balls = class()
function balls:init(x,y,c)
self.x = x or math.random(0,WIDTH)
self.y = y or math.random(0,HEIGHT)
self.c= color(255,0,0)
end
function balls:draw()
background(40,40,50)
fill(self.c)
ellipse(self.x,self.y,100)
end
But it only shows one ball on the screen.
please leave a comment and help me correct my code>_<
Thanks!