#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# I need to spawn random ellipses

edited July 2017 Posts: 8

Hey guys id like to spawn random circles but if i use math.random the balls keep moving around the screen and i want them to be still.

``````-- Table

-- Use this function to perform your initial setup
function setup()
palla={}
vx=WIDTH/2
vy=HEIGHT/2
u=0
o=0
end

-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(0, 0, 0, 255)
fill(255, 255, 255, 255)
ball(WIDTH/2,HEIGHT/2,64)
for i=0,10 do
palla[i]=ball(math.random(WIDTH),math.random(HEIGHT),16)
end

end
function ball(vx,vy,r)
fill(255, 255, 255, 255)
ellipse(vx,vy,r*2,r*2)

end
``````

## Comments

• Mod
Posts: 6,876

@Drea You were recreating the table every draw cycle. The draw function gets called 60 times every second. To create random ellipses that stay in one place, you need to create the table with the x,y values only once in setup and then in the draw function, you draw the ellipses based on the information in the table.

``````-- Table
function setup()
palla={}
for i=0,10 do
palla[i]=vec2(math.random(WIDTH),math.random(HEIGHT))
end
end

function draw()
background(0, 0, 0, 255)
fill(255, 255, 255, 255)
for a,b in pairs(palla) do
ellipse(b.x,b.y,16)
end
end
``````
• Posts: 8

You are always helpful dave. Thank you

Sign In or Register to comment.