you can always randomize a new position and radius and check if the new point is far enough from all the earlier points one by one. if yes, good, if not, randomize another point and radius.
Just make the radius of the circles more than what it really is then check for circle collision.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Nice idea @SinisterSoft ! Make several randomly sized circles with box2d, let them fall in place, then fetch the position of each circle and use a smaller radius when rendering
I like the Box2D variant. Probably won't work with too many circles though. Ideally I'd like to avoid a two dimensional array, because it would take time to process and create. I'd like to solve it with perlin noise or another formula which is infinite. But I'm probably dreaming!
Maybe the best thing to do is to create the map offline, then just save the coordinates and radiuses of each circle. Then load that massive file on startup.
Don't bother with box2d, circle collision is fairly easy.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
That's true. Would probably take quite a while to calculate many circles (because each circle needs to check all other circles at least once), but if I create a "circle creator" app separate to the game it doesn't really matter.
A circle won't need to be checked for collision if it's already done it's collision check loop, as it would already have been checked. It might be faster than you think. You could also somehow divide them into integer rows and columns - so you know to not bother doing collision if there is a 2 column or 2 row gap?
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
I meant all already existing circles, so only the last circle placed would need to check through all circles (minus itself). But yeah, that's probably the way to go!
WORLD_WIDTH =2048
WORLD_HEIGHT =2048
NUMCIRCLES =256
MINRADIUS =16
MAXRADIUS =64local bump =require("bump").newWorld(32)localrandom=math.random-- create n circlesfor i =1, NUMCIRCLES dolocal r =random(MINRADIUS, MAXRADIUS)local placed =falserepeatlocal x =random(MAXRADIUS, WORLD_WIDTH - MAXRADIUS)local y =random(MAXRADIUS, WORLD_HEIGHT - MAXRADIUS)local items, len = bump:queryRect(x - r, y - r, r *2, r *2)-- check for overlapif len ==0then
bump:add({}, x, y, r *2, r *2)-- do your object placing here
placed =trueenduntil placed
end-- cleanuplocal items, len = bump:queryRect(0, 0, WORLD_WIDTH, WORLD_HEIGHT)for i =1, len do
bump:remove(items[i])end
Of course there is a chance of infinite recursion built in but it is highly unlikely that it would happen :d
Or you could opt to use a grid system to place objects. Whilst this could possibly look a little griddy it is guaranteed to never recurse and of course never overlap
WORLD_WIDTH =2048
WORLD_HEIGHT =2048
NUMCIRCLES =256
MINRADIUS =16
MAXRADIUS =64localrandom, remove=math.random, table.remove-- generate a grid of equal sized cellslocal rows ={}for r =1, WORLD_HEIGHT / MAXRADIUS dolocal row ={}for c =1, WORLD_WIDTH / MAXRADIUS do
row[#row + 1]={x = c - 1, y - r - 1}end
rows[#rows + 1]= row -- save rowend-- generate a list of unallocated cellslocal free ={}for i =1, #rows do
free[#free + 1]= i
end-- place objectsfor i =1, #NUMCIRCLES dolocal c =remove(free[random(1, #free)])-- get a random cell numberlocal cell = rows[c]local x, y = cell.x, cell.y
-- place your object into your world hereend
@totebo, you use squares because it's faster and more efficient, then plop your circle in the center of the rectangle
If you want to allow things to be a bit closer than rectangle bounds you can query the rectangle and check for circle overlaps between any items returned by the query. Here is a messy example that may or may not work (untested but you should get the gist of it)
WORLD_WIDTH =2048
WORLD_HEIGHT =2048
NUMCIRCLES =256
MINRADIUS =16
MAXRADIUS =64local bump =require("bump").newWorld(32)localrandom=math.random-- create n circlesfor i =1, NUMCIRCLES dolocal r =random(MINRADIUS, MAXRADIUS)local xA, yA, rA, xB, yB, rB
local placed =falserepeatlocal x =random(MAXRADIUS, WORLD_WIDTH - MAXRADIUS)local y =random(MAXRADIUS, WORLD_HEIGHT - MAXRADIUS)local items, len = bump:queryRect(x - r, y - r, r *2, r *2)-- check for overlapif len ==0then-- -- no overlap so you are good to add your circle to the world--
bump:add({x = x, y = y, r = r}, x, y, r *2, r *2)
placed =trueelselocal overlap =falsefor i =1, len dolocalfunction overlaps()local r = rA + rB local dx, dy = xA - xB, yA - yB return r * r >(dx * dx + dy * dy)endlocal other = items[i]
xA, yA, rA, mA = other.x + other.r, other.y + other.r, other.r
xB, yB, rB, mB = x, y, r
if overlaps()then
overlap =trueendendifnot overlap then-- -- no overlap so you are good to add your circle to the world--
bump:add({x = x, y = y, r = r}, x, y, r *2, r *2)
placed =trueendenduntil placed
end-- cleanuplocal items, len = bump:queryRect(0, 0, WORLD_WIDTH, WORLD_HEIGHT)for i =1, len do
bump:remove(items[i])end
Comments
put a point, with the help of "line"
randomly increase the point
randomly move point
variant 2
http://docs.giderosmobile.com/reference/gideros/Particles#Particles
grab the required area
http://docs.giderosmobile.com/reference/gideros/Viewport#Viewport
variant 3
Make 10 Random Tiles with Cargues and a Transparent Background
Randomly arrange tiles with overlapping each other 10-20 pixels
ps/ English is not my language
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://deluxepixel.com
Likes: SinisterSoft
I like the Box2D variant. Probably won't work with too many circles though. Ideally I'd like to avoid a two dimensional array, because it would take time to process and create. I'd like to solve it with perlin noise or another formula which is infinite. But I'm probably dreaming!
Maybe the best thing to do is to create the map offline, then just save the coordinates and radiuses of each circle. Then load that massive file on startup.
https://deluxepixel.com
https://deluxepixel.com
The beauty of a perlin noise solution would be that no pre-generation would be needed and the map of circles would in theory be infinite.
Likes: antix
If you want to allow things to be a bit closer than rectangle bounds you can query the rectangle and check for circle overlaps between any items returned by the query. Here is a messy example that may or may not work (untested but you should get the gist of it)
Likes: MoKaLux