Skip to content

Instantly share code, notes, and snippets.

@skopp
Created March 31, 2013 19:25
Show Gist options
  • Save skopp/5281692 to your computer and use it in GitHub Desktop.
Save skopp/5281692 to your computer and use it in GitHub Desktop.
--animated matrix rain by joão colombo: http://joaocolombo.com using corona sdk: http://www.anscamobile.com/corona/
display.setStatusBar(display.HiddenStatusBar) --hide status bar
--make a black background
local background = display.newRect(0,0,display.contentWidth,display.contentHeight);
background:setFillColor(0,0,0);
--function to generate a number
function generateNumber()
local i = {0,1,2,3,4,5,6,7,8,9};
return i[math.random(1, (table.getn(i)))];
end
--function to create a line
function createLine()
--line variables
local line = display.newGroup(); --create the line
local numberSize = math.random(10,60); --the font size of the number
local maxOfNumbers = display.contentHeight/numberSize; --max of numbers of a line
local numberOfNumbers = math.random(7,maxOfNumbers); --number of number of the line
--add numbers to the group with a loop
local i = 0;
local numberY = 0; --the y of the last number
local numberColor = {0, math.random(0,150), 0} --create a random color
while (i <= numberOfNumbers) do --insert the number in the line
local number = display.newText(generateNumber(),0, numberY, native.systemFont, numberSize);
if i == numberOfNumbers then --if is the last letter make it shine
number:setTextColor(0, 230, 0);
else --else use the random color
number:setTextColor(numberColor[1], numberColor[2], numberColor[3]);
end
line:insert(number);
numberY = numberY + numberSize;
i = i + 1;
end
--animate line
line.x = math.random(0, display.contentWidth);
line.y = 0 - line.contentHeight;
transition.to( line, {time=math.random(300,1000), alpha=0, y=display.contentHeight, onComplete=removeLine});
--remove the line after transition
function removeLine()
line:removeSelf();
end
--create another line
timer.performWithDelay(1, createLine);
end
--let's create the first line
createLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment