Implement path drawing effect

This commit is contained in:
Quinn
2021-12-27 12:35:44 -08:00
parent 56942461e7
commit 7bab9c56f9
3 changed files with 34 additions and 16 deletions
+7 -2
View File
@@ -2,6 +2,7 @@ ball = {
__count = 0, __count = 0,
id = nil, id = nil,
pos = vec2:new(0,0), pos = vec2:new(0,0),
last_pos = vec2:new(0,0),
vel = vec2:new(0,0), vel = vec2:new(0,0),
rad = 1, rad = 1,
col = 7, col = 7,
@@ -10,11 +11,15 @@ ball = {
return self.rad return self.rad
end, end,
draw = function(self) draw = function(self, shadow)
if (shadow == true) then
circfill(self.last_pos.x, self.last_pos.y, self.rad, self.col + 8)
end
circfill(self.pos.x, self.pos.y, self.rad, self.col) circfill(self.pos.x, self.pos.y, self.rad, self.col)
end, end,
move = function(self) move = function(self)
self.last_pos = self.pos
self.pos += self.vel self.pos += self.vel
end, end,
@@ -53,7 +58,7 @@ function ball:new(o)
ball.__count += 1 ball.__count += 1
local o = o or {} local o = o or {}
o.id = ball.__count o.id = ball.__count
o.col = o.col or o.id % 16 o.col = o.col or o.id % 8
setmetatable(o, self) setmetatable(o, self)
o.__index = self o.__index = self
return o return o
+10 -6
View File
@@ -1,14 +1,18 @@
ball_count = 10 pal()
max_radius = 8 cls()
ball_count = 16
max_radius = 16
function _init() function _init()
balls = {} pal({9,10,11,12,13,2,15,136,137,138,139,140,141,130,143,8},1)
balls = {}
collisions = {} collisions = {}
for i=1,ball_count do for i=1,ball_count do
add(balls, ball:new({ add(balls, ball:new({
pos=vec2:new(rnd(127),rnd(127)), pos=vec2:new(rnd(127),rnd(127)),
vel=vec2:new(rnd(2)-1,rnd(2)-1):normal(), vel=vec2:new(rnd(2)-1,rnd(2)-1):normal(),
rad=2+flr(rnd(max_radius)), rad = i < max_radius and i or max_radius,
})) }))
end end
end end
@@ -26,9 +30,9 @@ function _update60()
end end
function _draw() function _draw()
cls() -- cls()
for b in all(balls) do for b in all(balls) do
b:draw() b:draw(true)
end end
end end
+17 -8
View File
@@ -59,6 +59,7 @@ ball = {
__count = 0, __count = 0,
id = nil, id = nil,
pos = vec2:new(0,0), pos = vec2:new(0,0),
last_pos = vec2:new(0,0),
vel = vec2:new(0,0), vel = vec2:new(0,0),
rad = 1, rad = 1,
col = 7, col = 7,
@@ -67,11 +68,15 @@ ball = {
return self.rad return self.rad
end, end,
draw = function(self) draw = function(self, shadow)
if (shadow == true) then
circfill(self.last_pos.x, self.last_pos.y, self.rad, self.col + 8)
end
circfill(self.pos.x, self.pos.y, self.rad, self.col) circfill(self.pos.x, self.pos.y, self.rad, self.col)
end, end,
move = function(self) move = function(self)
self.last_pos = self.pos
self.pos += self.vel self.pos += self.vel
end, end,
@@ -110,24 +115,28 @@ function ball:new(o)
ball.__count += 1 ball.__count += 1
local o = o or {} local o = o or {}
o.id = ball.__count o.id = ball.__count
o.col = o.col or o.id % 16 o.col = o.col or o.id % 8
setmetatable(o, self) setmetatable(o, self)
o.__index = self o.__index = self
return o return o
end end
-->8 -->8
ball_count = 10 pal()
max_radius = 8 cls()
ball_count = 16
max_radius = 16
function _init() function _init()
balls = {} pal({9,10,11,12,13,2,15,136,137,138,139,140,141,130,143,8},1)
balls = {}
collisions = {} collisions = {}
for i=1,ball_count do for i=1,ball_count do
add(balls, ball:new({ add(balls, ball:new({
pos=vec2:new(rnd(127),rnd(127)), pos=vec2:new(rnd(127),rnd(127)),
vel=vec2:new(rnd(2)-1,rnd(2)-1):normal(), vel=vec2:new(rnd(2)-1,rnd(2)-1):normal(),
rad=2+flr(rnd(max_radius)), rad = i < max_radius and i or max_radius,
})) }))
end end
end end
@@ -145,9 +154,9 @@ function _update60()
end end
function _draw() function _draw()
cls() -- cls()
for b in all(balls) do for b in all(balls) do
b:draw() b:draw(true)
end end
end end