# I'm sorry I KEEP GETTING STUCk

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

#1: I want to make only two circles visible at a time, so once three exist, delete the oldest one.
#2: It does check for overlap correctly. Keep in mind that the circles have a radius of 40. I don't want to just make sure that the centers don't overlap, I want the BORDERS to not overlap. I want it so that all of the borders of all of the circles are at least touching one other border, but make sure that the borders don't go inside of the empty space in another circle.

``````import "CoreLibs/graphics"
import "CoreLibs/object"
import "CoreLibs/sprites"
import "CoreLibs/nineslice"
import "CoreLibs/timer"
import "CoreLibs/frameTimer"

import "config"

import "core/definitions"
import "core/cotton/all"

import "scripts/index"

import "core/lieb/all"
import "core/CoreGame"

bpm = 60
lastX = math.random(80, 320)
lastY = math.random(80, 160)
circles = {}

x = lastX + math.random(-40, 40)
y = lastY + math.random(-40, 40)

-- Check if the new circle would overlap with any existing circles
for i, c in ipairs(circles) do
distance = math.sqrt((x - c.x) ^ 2 + (y - c.y) ^ 2)
if distance < 80 then
x = lastX
y = lastY
break
end
end

if #circles >= 3 then
circles[1]:destroy()
table.remove(circles, 1)
end

circle = playdate.graphics.drawCircleAtPoint(x, y, 40)
table.insert(circles, circle)

lastX = x
lastY = y
end

beatTimer = playdate.timer.performAfterDelay(60000 / bpm, addCircle)
beatTimer.repeats = true

function playdate.update()
input.update()
playdate.timer.updateTimers()
end

``````

So one issue is you aren't clearing the screen. To save power the playdate doesn't clear the screen by default. I'd recommend looking into how sprites work.

As for the overlapping, the function you have to check if they over lap looks right but your extremely unlikely to actually get a point on the edge of the circle. Also if you do find an over lap you aren't trying to find a new point just taking that point and moving on.

You can use transformations to get a point that will always be on the edge

``````bpm = 60
lastX = math.random(80, 320)
lastY = math.random(80, 160)
circles = {}

tf = playdate.geometry.affineTransform.new()

tf:rotate(math.random(360))
x, y = (tf * playdate.geometry.point.new(80, 0)):unpack()
x += lastX
y += lastY

if #circles >= 3 then
circles[1]:destroy()
table.remove(circles, 1)
end

circle = playdate.graphics.drawCircleAtPoint(x, y, 40)
table.insert(circles, circle)

lastX = x
lastY = y
end

beatTimer = playdate.timer.performAfterDelay(60000 / bpm, addCircle)
beatTimer.repeats = true

function playdate.update()
playdate.timer.updateTimers()
end
``````

it worked; thanks so much!