Digital Rain
  • Ipad41001Ipad41001 January 30

    My celebration of text in Codea 1.3

    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.

  • ZoytZoyt January 30

    AWSOME! LOVE IT!

  • HerwigHerwig January 31

    Nicely done!

  • ZoytZoyt January 31

    Emoji don't work even when I change the font to the emoji font. :-( 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. :-D

  • Ipad41001Ipad41001 January 31

    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

  • ZoytZoyt January 31

    Alright. Thanks.

  • tstedttstedt February 21

    Really cool.

  • Ipad41001Ipad41001 February 21

    thx

  • juaxixjuaxix February 22

    I liked it, you can use it as screensaver :-)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID Sign In with Google

Sign In Apply for Membership

In this Discussion

Tagged