{{ message }}

Instantly share code, notes, and snippets.

# rxi/tinysquares.lua

Created Apr 24, 2014
 local flux = require "flux" function love.load() text = { x = 350, y = 290, alpha = 0, str = "900 Tiny Squares" } squares = {} -- Title text flux.to(text, 2, { alpha = 1 }):ease("linear") :after(text, 2, { alpha = 0 }):ease("linear"):delay(3) -- Squares local i = 0 for y = 1, 30 do for x = 1, 30 do local square = { x = x * 12 + 210, y = -10, size = 10, alpha = 1 } table.insert(squares, square) -- Drop from top of screen and fade out randomly flux.to(square, 1, { y = y * 12 + 100 }) :ease("backout") :delay(7 + math.random() * 6) :after(square, 1, { alpha = 0 }) :delay(6 + math.random() * 4) -- Fade back in from top to bottom flux.to(square, 2, { alpha = 1 }):delay(25 + .01 * i):ease("linear") -- Resize to single pixel diagonally from top-left to bottom-right flux.to(square, 2, { size = 1 }):delay(29 + .1 * (x + y)) :ease("quintout") -- Form a circle flux.to(square, 2, { x = 400 + math.cos(6.28 / 900 * i) * 250, y = 300 + math.sin(6.28 / 900 * i) * 250 }) :delay(35 + .01 * i) :ease("quadinout") -- Send a pulse around the circle flux.to(square, .04, { size = 8 }) :delay(43 + .005 * i) :after(square, .6, { size = 1 }) -- Form a square flux.to(square, 2, { x = 370 + y * 2, y = 270 + x * 2 }) :delay(46 + .01 * (i % 450)) :ease("quintinout") -- Place randomly and randomise alpha flux.to(square, 2, { x = math.random() * 800, y = math.random() * 600, alpha = math.random() }) :delay(53 + math.random() * 4) :ease("expoinout") -- Fall off the bottom of the screen flux.to(square, 3, { y = 601 }):ease("circin"):delay(59 + i * .01) i = i + 1 end end end function love.update(dt) flux.update(dt) end function love.keypressed(k) if k == "escape" then os.exit() end end function love.draw() for k, square in pairs(squares) do love.graphics.setColor(255, 255, 255, square.alpha * 255) love.graphics.rectangle("fill", square.x, square.y, square.size, square.size) end love.graphics.setColor(255, 255, 255, text.alpha * 255) love.graphics.print(text.str, text.x, text.y) love.graphics.setColor(255, 255, 255, .4 * 255) love.graphics.print("fps: " .. love.timer.getFPS() .. "\n" .. "tweens: " .. #flux.tweens, 20, 20) end

 Wow.