Skip to content

83. A bit of fun – the Matrix effect

June 13, 2013

This little program gives you a Matrix* type version of any image, like this

(*or maybe, I mean dot matrix, for those who remember what that means).

I won’t bother commenting the code, it is pretty simple. Basically, it creates random streaks down a black image, adjusting the intensity of the green for each pixel, to the intensity of the same pixel on the original image.

The original image for the picture above is here

Here is the code

function setup()
    img2=readImage('Planet Cute:Character Princess Girl') --choose your image here
    w,h=img2.width,img2.height
    --create copy, make black background
    img=image(w,h)
    setContext(img)
    fill(0)
    rect(0,0,w,h)
    setContext()
end

function draw()
    background(220)
    sprite(img,WIDTH/2,HEIGHT/2)
    addDrip()
end

function addDrip()
    for k=1,1000 do   --set this smaller to draw slower, for effect
        x,y,n,b=math.random(1,w),math.random(1,h),math.random(2,15),math.random(100,255)
        for i=1,n do
            local yy=y-i if yy0 then break end
            --adjust intensity to original image pixel
            r,g,b,a=img2:get(x,yy)
            local j=.21*r+.71*g+.08*b  --intensity weightings
            img:set(x,yy,0,j*d,0)
        end
    end
end

There are a couple of nice Matrix type dripping text effects on the Codea forum. Like this.

(Incidentally, if you ever search for anything on the forum, don’t use the built in search box, because it only goes back 2 days. Use normal Google instead, which goes back 18 months or more).

Advertisement
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: