feature/shadows #25
@ -16,32 +16,34 @@ local function makeGradientMesh(w, h, topColor, bottomColor)
|
||||
return mesh
|
||||
end
|
||||
|
||||
local function getFakeShadow(r)
|
||||
--- @param phi number угол, под которым падает свет
|
||||
--- @return boolean, number: рисуем ли тень * её прозрачность
|
||||
local function getFakeShadow(phi)
|
||||
local pi = math.pi
|
||||
|
||||
if r <= pi / 4 then
|
||||
if phi <= pi / 4 then
|
||||
-- 1
|
||||
return false, 1
|
||||
end
|
||||
if r <= pi / 2 then
|
||||
if phi <= pi / 2 then
|
||||
-- 2
|
||||
return true, 1 - (r - pi / 4) / (pi / 4)
|
||||
return true, 1 - (phi - pi / 4) / (pi / 4)
|
||||
end
|
||||
if r <= 3 * pi / 4 then
|
||||
if phi <= 3 * pi / 4 then
|
||||
-- 3
|
||||
return true, (r - pi / 2) / (pi / 4)
|
||||
return true, (phi - pi / 2) / (pi / 4)
|
||||
end
|
||||
if r <= 5 * pi / 4 then
|
||||
if phi <= 5 * pi / 4 then
|
||||
-- 4
|
||||
return false, 1
|
||||
end
|
||||
if r <= 3 * pi / 2 then
|
||||
if phi <= 3 * pi / 2 then
|
||||
-- 5
|
||||
return true, 1 - (r - 5 * pi / 4) / (pi / 4)
|
||||
return true, 1 - (phi - 5 * pi / 4) / (pi / 4)
|
||||
end
|
||||
if r <= 7 * pi / 4 then
|
||||
if phi <= 7 * pi / 4 then
|
||||
-- 6
|
||||
return true, (r - 3 * pi / 2) / (pi / 4)
|
||||
return true, (phi - 3 * pi / 2) / (pi / 4)
|
||||
end
|
||||
-- 1
|
||||
return false, 1
|
||||
@ -67,10 +69,10 @@ function behavior:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local r = love.timer.getTime() % (2 * math.pi)
|
||||
local phi = love.timer.getTime() % (2 * math.pi)
|
||||
|
||||
local drawFakeShadow, opacity = getFakeShadow(r)
|
||||
local nangle = (math.pi + r) % (2 * math.pi)
|
||||
local drawFakeShadow, opacity = getFakeShadow(phi)
|
||||
local nangle = (math.pi + phi) % (2 * math.pi)
|
||||
love.graphics.rotate(nangle)
|
||||
|
||||
love.graphics.setColor(0, 0, 0, math.min(opacity * opacity, 0.5))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user