Skip to content

Instantly share code, notes, and snippets.

@arkadijs
Last active October 18, 2022 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkadijs/5073077 to your computer and use it in GitHub Desktop.
Save arkadijs/5073077 to your computer and use it in GitHub Desktop.
local CHAR_START = 48
local CHAR_END = 94
local letters = {}
local font = nil
function love.load()
love.graphics.setColor(0, 255, 0)
font = love.graphics.newImageFont(
'katakana.png',
'0123456789:;<=>?' ..
'@ABCDEFGHIJKLMNO' ..
'PQRSTUVWXYZ[\\]^'
)
love.graphics.setFont(font)
particle = love.graphics.newImage('particle.png')
fillLetters()
end
function ps()
local ps = love.graphics.newParticleSystem(particle, 60)
ps:setDirection(-math.pi/2)
ps:setEmissionRate(10)
ps:setParticleLifetime(math.random(), 5*math.random()+1)
ps:setSpeed(math.random(70)+10)
ps:setSpread(0.1)
ps:setColors(0,255,0,128,0,255,0,255)
ps:setSizes(0.4,0)
ps:start()
ps:update(10)
return ps
end
function createLetter()
letter = {
x = math.random(love.graphics.getWidth()),
y = math.random(love.graphics.getHeight()),
l = string.char(math.random(CHAR_START, CHAR_END)),
alpha = 32,
speed = 0.5 + 2*math.random()
}
letter.ps = {};
for i=1,5 do
table.insert(letter.ps,ps());
end
return letter
end
function fillLetters()
for i=1,100 do
--letters.insert(i,createLetter())
table.insert(letters, createLetter())
end
end
function love.update(dt) --delta!
x, y = love.mouse.getPosition()
for i,letter in ipairs(letters) do
distance = math.sqrt(
math.pow((x - letter.x), 2) +
math.pow((y - letter.y), 2))
letter.alpha = math.max(0,math.min(255,255-distance/500*255))
letter.y = letter.y + letter.speed
for i,ps in ipairs(letter.ps) do
ps:setColors(0,255,0,letter.alpha/8,0,255,0,0)
ps:update(dt)
end
if letter.y > love.graphics.getHeight()+100 then
letter.y = -font:getHeight()
letter.x = math.random(love.graphics.getWidth())
end
end
end
function love.draw()
for i,letter in ipairs(letters) do
love.graphics.setColor(0, 255, 0, letter.alpha)
love.graphics.print(letter.l, letter.x-font:getHeight()/2, letter.y)
for i,ps in ipairs(letter.ps) do
love.graphics.draw(ps, letter.x-i*2+5, letter.y)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment