Created
June 12, 2013 22:00
-
-
Save briarfox/5769511 to your computer and use it in GitHub Desktop.
Matrix Release v1.0.0 -Matrix Demos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Matrix Tab Order | |
------------------------------ | |
This file should not be included in the Codea project. | |
#Main | |
#mpilgrem | |
#Zoyt | |
#IPad41001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--matrix digital rain | |
IPad41001 = class() | |
function IPad41001:init() | |
output.clear() | |
print("IPad41001's Matrix Demo") | |
font("Futura-CondensedExtraBold") | |
fontSize(24) | |
c = ElapsedTime | |
ns = (math.ceil(WIDTH/fontSize())+1) --num of streams | |
st = {} --stream table | |
for i = 1,ns do st[i] = RainStream(i,fontSize()) end | |
end | |
function IPad41001:draw() | |
if ElapsedTime > c + .2 then | |
c = ElapsedTime | |
for i = 1,ns do st[i]:drip() end | |
end | |
background(0,0,0,255) | |
for i = 1,ns do st[i]:draw() end | |
end | |
function IPad41001:touched(t) | |
end | |
RainStream = class() | |
function RainStream:init(c,f) | |
--column, fontSize | |
self.f = f --fontsize | |
--number of characters from top to bottom of screen | |
self.n = (math.ceil(HEIGHT/self.f)+1) | |
self.x = WIDTH - (c*self.f) --x of column | |
self:reset() | |
self.s = math.random(self.n) --start | |
end | |
function RainStream:reset() | |
self.t = kano() --text | |
local i | |
self.t = "" | |
for i = 1,self.n do self.t = self.t .. self:randchar() end | |
self.tl = math.random(self.n) --tail length | |
self.s = 0 | |
end | |
function RainStream:randchar() | |
local r, c | |
r = math.random((string.len(kano())/3)) | |
return string.sub(kano(),1+(r*3),(r*3)+3) | |
end | |
function RainStream:draw() | |
local dt --draw tail to here | |
fill(0, 255, 0 , 255) --bright | |
if self.s <= self.n then | |
text(string.sub(self.t,1+(self.s*3),(self.s*3)+3),self.x,HEIGHT - (self.s*self.f)) | |
end | |
fill(0, 255, 0 , 128) --dim | |
if self.s - self.tl < 0 then | |
dt = 0 --draw to top of screen | |
else | |
dt = self.s - self.tl | |
end | |
local j | |
for j = (self.s-1),dt,-1 do --draw dim chracters going up | |
--kano characters are a length of 2 in a string | |
--don't know why, they just are | |
text(string.sub(self.t,1+(j*3),(j*3)+3),self.x,HEIGHT - (j*self.f)) | |
end | |
end | |
function RainStream:drip() | |
self.s = self.s + 1 --move drip down | |
if math.random(100) > 50 then | |
--rand a chracter | |
local r = math.random(self.n-6)+3 | |
local nt = string.sub(self.t,1,(r*3)) | |
nt = nt .. self.randchar() | |
nt = nt .. string.sub(self.t,(r*3)+4) | |
self.t = nt | |
end | |
--check for reset | |
if self.s > (self.n + self.tl) then self:reset() end | |
end | |
function kano() | |
--these aren't the true chracters, just ones I found | |
return "あかさたないきしちにうくすつぬえけせてねおこそとのはまやらわひみりをふむゆるんへめれ" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Various Matrix demos from the forums | |
function setup() | |
menuSelect = 1 | |
menu = {mpilgrem,IPad41001,Zoyt} | |
parameter.integer("Select_Matrix",1,#menu,1,callback) | |
currentMenu = menu[menuSelect]() | |
end | |
function draw() | |
currentMenu:draw() | |
end | |
function touched (touch) | |
currentMenu:touched(touch) | |
end | |
function callback() | |
menuSelect = Select_Matrix | |
currentMenu = menu[menuSelect]() | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Raining Kana v2 | |
-- | |
mpilgrem = class() | |
function mpilgrem:init() | |
output.clear() | |
print("mpilgrem's Matrix Demo") | |
backingMode(RETAINED) | |
fontSize(28) | |
n = math.floor(WIDTH/40) | |
y = {} | |
for i = 0, n do | |
y[i] = {} | |
for j = 1, 3 do | |
y[i][j] = math.random(0, HEIGHT) | |
end | |
end | |
kana = {} | |
for i = 1, 0x5B do | |
local k = 0x30A0 + (i - 1) | |
kana[i] = kanaUnicode2UTF8(k) | |
end | |
nKana = #kana | |
rectMode(CORNER) | |
lastTime = ElapsedTime | |
end | |
function mpilgrem:draw() | |
if (ElapsedTime - lastTime) < 1/20 then return end | |
lastTime = ElapsedTime | |
fill(0, 30) | |
rect(0, 0, WIDTH, HEIGHT) | |
fill(35, 184, 40) | |
for i = 0, n do | |
for j = 1, 3 do | |
text(kana[math.random(1, nKana)], i*WIDTH/n, y[i][j]) | |
y[i][j] = y[i][j] - math.random(5, 30) | |
if y[i][j] < 0 then y[i][j] = HEIGHT end | |
end | |
end | |
end | |
function kanaUnicode2UTF8(u) -- Three-byte UTF-8 format | |
return string.char( | |
math.floor(u/0x1000) + 0xE0, | |
math.floor(u/0x40) % 0x40 + 0x80, | |
u % 0x40 + 0x80 | |
) | |
end | |
function mpilgrem:touched(t) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Zoyt = class() | |
function Zoyt:init(x) | |
backingMode(RETAINED) | |
output.clear() | |
print("Zoyt's Matrix Demo") | |
print("Touch the screen") | |
characters = {"き","ま","ほ","を","あ","年","分","ひ","や","゛","こ","そ","せ","を","い"} | |
objects = {} | |
ground = physics.body(EDGE,vec2(0,0),vec2(WIDTH,0)) | |
fontSize(30) | |
frameCount = 0 | |
end | |
function Zoyt:draw() | |
-- Codea does not automatically call this method | |
fill(0, 0, 0, 30) | |
rect(0,0,WIDTH,HEIGHT) | |
--background(0,0,0,255) | |
frameCount = frameCount + 1 | |
if frameCount >= 20 then | |
changeChar = true | |
frameCount = 0 | |
else | |
changeChar = false | |
end | |
fill(0, 255, 6, 255) | |
for i,v in ipairs(objects) do | |
if changeChar == true then | |
v.info = characters[math.ceil(math.random(1,#characters))] | |
end | |
pushMatrix() | |
translate(v.x,v.y) | |
rotate(v.angle) | |
text(v.info,0,0) | |
popMatrix() | |
end | |
end | |
function Zoyt:touched(t) | |
-- Codea does not automatically call this method | |
table.insert(objects,physics.body(CIRCLE,fontSize()/2)) | |
objects[#objects].x = t.x | |
objects[#objects].y = t.y | |
objects[#objects].restitution = .9 | |
objects[#objects].info = characters[math.ceil(math.random(1,#characters))] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment