experiments-love2d/genart/main.lua
2024-01-06 18:13:20 -06:00

44 lines
859 B
Lua

Tree = { x = 0, y = 0, r = 100 }
function Tree:create(o)
o.parent = self
return o
end
function Tree:collides(first, other)
print(first.x, first.y, other.x, other.y)
return math.sqrt((first.x - other.x)^2 + (first.y - other.y)^2) < (other.r + first.r)
end
function love.load()
trees = {}
nextNum = 0
r = 100
repeat
t = Tree:create({x=math.random(0, 500), y=math.random(0, 500), r=r})
collides = false
for j=0, nextNum-1 do
if Tree:collides(t, trees[j]) then
collides = true
break
end
end
if not collides then
trees[nextNum] = t
nextNum = nextNum + 1
else
r = r - math.random(0, 10)
end
until nextNum >= 20
end
function love.draw()
love.graphics.setColor(1, 1, 1)
for k, t in pairs(trees) do
love.graphics.circle("line", t.x, t.y, t.r, 100)
end
end