init
This commit is contained in:
commit
4cb1cfbae8
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.lua
|
75
src/main.moon
Normal file
75
src/main.moon
Normal file
@ -0,0 +1,75 @@
|
||||
width, height = love.graphics.getDimensions!
|
||||
rng = love.math.newRandomGenerator 0
|
||||
types = 7
|
||||
radius = 4
|
||||
colors = {}
|
||||
interactions = {}
|
||||
universe = {}
|
||||
|
||||
physics = (a, b) ->
|
||||
dx = a.x - b.x
|
||||
dy = a.y - b.y
|
||||
ds = dx * dx + dy * dy
|
||||
theta = math.atan2 dy, dx
|
||||
x = math.cos theta
|
||||
y = math.sin theta
|
||||
|
||||
f = interactions["#{a.n}.#{b.n}"](ds)
|
||||
a.vx += f * x
|
||||
a.vy += f * y
|
||||
|
||||
f = interactions["#{b.n}.#{a.n}"](ds)
|
||||
b.vx += f * x
|
||||
b.vy += f * y
|
||||
|
||||
for a = 1, types
|
||||
for b = 1, types
|
||||
A = rng\randomNormal 0.5, 0
|
||||
aa = rng\randomNormal 5, 10
|
||||
B = rng\randomNormal 0.5, 0
|
||||
bb = rng\randomNormal 5, 10
|
||||
interactions["#{a}.#{b}"] = (ds) ->
|
||||
if ds < radius^0.5
|
||||
return 1 / ds
|
||||
else
|
||||
return A * (ds^0.5 - aa)
|
||||
interactions["#{b}.#{a}"] = (ds) ->
|
||||
if ds < radius^0.5
|
||||
return 1 / ds
|
||||
else
|
||||
return B * (ds^0.5 - bb)
|
||||
|
||||
-- for k,v in pairs interactions
|
||||
-- print k,v
|
||||
|
||||
for a = 1, types
|
||||
colors[a] = { rng\random!, rng\random!, rng\random!, 1 }
|
||||
|
||||
class Particle
|
||||
new: (@n=1, x, y) =>
|
||||
@x = x or love.math.random 0, width
|
||||
@y = y or love.math.random 0, height
|
||||
@vx = 0
|
||||
@vy = 0
|
||||
|
||||
for i=1, 2
|
||||
table.insert universe, Particle(love.math.random 1, types)
|
||||
|
||||
love.update = (dt) ->
|
||||
for a = 1, #universe - 1
|
||||
for b = a + 1, #universe
|
||||
physics(universe[a], universe[b])
|
||||
|
||||
for particle in *universe
|
||||
particle.vx *= 0.01
|
||||
particle.vy *= 0.01
|
||||
particle.x += particle.vx * dt
|
||||
particle.y += particle.vy * dt
|
||||
|
||||
love.draw = ->
|
||||
for particle in *universe
|
||||
love.graphics.setColor colors[particle.n]
|
||||
love.graphics.circle "fill", particle.x, particle.y, radius
|
||||
|
||||
love.keypressed = (key) ->
|
||||
love.event.quit! if key == "escape"
|
Loading…
Reference in New Issue
Block a user