Liberty BASIC Community Forum
Liberty BASIC Programming Discussions >> Liberty BASIC Code >> JR codes ( thread jump from QR codes)

JR codes ( thread jump from QR codes)
Post by tenochtitlanuk on Aug 30th, 2016, 2:50pm

It is quite fun creating a SIMPLE image-based coding system.
Creating the code is the easy part. Reading it is MUCH harder.

Here's my quick attempt at the easy bit -
User Image
It's coded with


    WindowWidth  =440
    WindowHeight =440

    open "JR code" for graphics_nsb as #wg

    #wg "trapclose [quit]"
    #wg "size 1 ; fill white ; color 210 210 210"

    message$    ="jzdjcj 1946 cxmvmvbmxm  ngf xyzzzy plugh foobar digame!"
    n           =1

    for i =0 to 24^2 -1 step 8
        c$          =mid$( message$, n, 1)
        a           =asc( c$)
        pAscBin$    =dec2bin$( a)
        n           =n +1
        x           =i mod 24
        y           =int( i /24)
        for j =1 to 8
            if mid$( pAscBin$, j, 1) ="1" then col$ ="red": #wg "color red" else col$ ="white": #wg "color white"
            #wg "backcolor "; col$
            #wg "up ; goto "; 80 +x*10 +j *10; " "; 80 +y *10; " ; down"
            #wg "boxfilled "; 90 +x*10 +j *10; " "; 90 +y *10
        next j

    next i

    #wg "backcolor cyan ; color cyan"
    #wg "up ; goto  50  40 ; down ; boxfilled  90  80"
    #wg "up ; goto 330  40 ; down ; boxfilled 370  80"
    #wg "up ; goto  50 320 ; down ; boxfilled  90 360"

    #wg "getbmp scr 0 0 430 410"
    bmpsave "scr", "JR.bmp"

    close #wg

function dec2bin$( num)
   if num =0 then dec2bin$ ="00000000": exit function
    while num >0
        dec2bin$    =str$( num mod 2) +dec2bin$
        num=        int( num/2)
    dec2bin$ =right$( "00000000" +dec2bin$, 8)
end function

However the line I encoded is different from the message$ shown.
You can decode it quite easily by eye. Can you program it? ( change the gif to a bmp so LB can load it if you aren't used to making LB load gifs...

Of course in real life the image may be at different distances/sizes. May be blurred, rotated, trapezium-distorted. And no error correction is built in.
Even DETECTING that a code is in view is not trivial.
User Image

User Image What did this line read to produce the JR code above?
PS It just struck me that I ought to make it circular-symmetric- then orientation is not a problem....