Digital Rain

My celebration of text in Codea 1.3

http://www.youtube.com/watch?v=fvasomUVUyU&feature=youtube_gdata_player

pic.twitter.com/dcjIJa7K

--matrix digital rain
function setup()
    displayMode(FULLSCREEN)
    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 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

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

The Kano characters at the end confuse the codea editor a bit.

What was funny about making this is that it is so commonly reproduced in every environment, it’s about impossible to find a link to the orginal movie. I had to put in the DVD. This similuates the screens in the film not the neo or opening credit effects.

AWSOME! LOVE IT!

Nicely done!

When using a non-Kano set, those j*3 and the + around them may need removed or changed. Emoji may be 2 long instead of 3 or a mixture. The easiest is to put them all in a table, the string is just more compact.

To remove the random set self.t = kano() or just put your string right there. Also in drip, change the random test to > 101

Emoji don’t work even when I change the font to the emoji font. :frowning: Nor can I spell out “Codea 1.3 rocks!”. It gets all jumbled. I know that’s what you want, but it would be awesome if it could rain strings. :smiley:

Alright. Thanks.

Really cool.

thx

I liked it, you can use it as screensaver :slight_smile:

can you just copy and paste the conde in to codea (sorry i am new to codea)

@Fr0st yep just put everything in the main

yay it works awesome!

How do I copy paste this code

On your iPad, hold your finger down on a bit of the code until the selection bars come up and then select all the code, tap copy.

Open Codea, tap add new project, hold your finger down on a word of the default code, tap select all when the pop up comes up and then select paste!

I’m trying to change the font to English. If I just change just 1 letter in the function lane ( ), I get an error msg…I would like to change the fonts to emogis…

Here’s a version using English characters. Not sure why the emoji font doesn’t work.

function setup()
    displayMode(FULLSCREEN)
    font("MarkerFelt-Wide")
    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 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

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())//1))
    return string.sub(kano(),1+(r),(r)+1)   
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),(self.s)+1),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
        text(string.sub(self.t,1+(j),(j)+1),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)
        local nt = string.sub(self.t,1,(r))
        nt = nt .. self.randchar()
        nt = nt .. string.sub(self.t,(r))
        self.t = nt 
    end
    --check for reset
    if self.s > (self.n + self.tl) then self:reset() end
end
 
function kano()
    return "QSSXERFCVFTYHBNNMKKPOOIUNHTTFFEESAQZZwqazcerfvgtyunmjkopkk321456790865"
end

Thanks…

Is there a way I could get access to some of the PGM’s from 2016 ? My previous I-cloud acct becamed locked and I can’t retrieve them from there, I had to make a new gmail acct and buy codea all over again…I learned a lot from Fuze programming so it wasn’t a total waste, but I’ll be back here from now on…

You have access to any program posted in this forum. You can go back to Sept 2013 using the page numbers at the bottom of each discussion list. You can also go back to about Sept 2011 if you know what to search for.

I seem to be getting error msg’s…