init naive attempt
This commit is contained in:
commit
115767daaf
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.lua
|
86
src/main.moon
Normal file
86
src/main.moon
Normal file
@ -0,0 +1,86 @@
|
||||
nodes = {
|
||||
Rose: {
|
||||
edges: {
|
||||
Ky: { "solid" }
|
||||
Luz: { "solid" }
|
||||
Joel: { "solid" }
|
||||
Raven: { "solid" }
|
||||
}
|
||||
}
|
||||
-- Ky: {
|
||||
-- Luz: { "encapsulate" }
|
||||
-- Joel: { "encapsulate" }
|
||||
-- Raven: { "encapsulate" }
|
||||
-- }
|
||||
Luz: {
|
||||
edges: {
|
||||
Joel: { "solid" }
|
||||
Raven: { "dashed" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w, h = love.graphics.getDimensions!
|
||||
centering_force = 0.01
|
||||
annealing = 0.9
|
||||
repelling_force = 0.25
|
||||
|
||||
for self, node in pairs nodes
|
||||
for name, edge_type in pairs node.edges
|
||||
unless nodes[name]
|
||||
nodes[name] = { edges: {} }
|
||||
nodes[name].edges[self] = edge_type
|
||||
|
||||
ordered = {}
|
||||
for _, node in pairs nodes
|
||||
node.x = love.math.random! * w - w / 2
|
||||
node.y = love.math.random! * h - h / 2
|
||||
node.vx = 0
|
||||
node.vy = 0
|
||||
table.insert ordered, node
|
||||
|
||||
repel = (a, b) ->
|
||||
dx = a.x - b.x
|
||||
dy = a.y - b.y
|
||||
d2 = dx * dx + dy * dy
|
||||
if d2 == 0
|
||||
d2 == 0.5
|
||||
|
||||
force = -repelling_force * 10000 / d2
|
||||
direction = math.atan dy, dx
|
||||
dcos = math.cos direction
|
||||
dsin = math.sin direction
|
||||
|
||||
a.vx -= force * dcos
|
||||
a.vy -= force * dsin
|
||||
b.vx += force * dcos
|
||||
b.vy += force * dsin
|
||||
|
||||
love.update = (dt) ->
|
||||
-- centering force
|
||||
for _, node in pairs nodes
|
||||
direction = math.atan2 node.y, node.x
|
||||
node.vx -= math.abs(node.x * centering_force) * math.cos direction
|
||||
node.vy -= math.abs(node.y * centering_force) * math.sin direction
|
||||
|
||||
-- repelling force
|
||||
for i = 1, #ordered - 1, 2
|
||||
for j = i + 1, #ordered
|
||||
repel(ordered[i], ordered[j])
|
||||
|
||||
-- actually apply forces
|
||||
for _, node in pairs nodes
|
||||
node.x += node.vx
|
||||
node.y += node.vy
|
||||
node.vx *= annealing
|
||||
node.vy *= annealing
|
||||
|
||||
love.draw = ->
|
||||
love.graphics.setColor 1, 1, 1, 1
|
||||
love.graphics.translate w / 2, h / 2
|
||||
for _, node in pairs nodes
|
||||
love.graphics.circle "fill", node.x, node.y, 5
|
||||
|
||||
love.keypressed = (key) ->
|
||||
if key == "escape"
|
||||
love.event.quit!
|
Reference in New Issue
Block a user