Grade 1 Braille

General FreeBASIC programming questions.
Post Reply
NorbyDroid
Posts: 70
Joined: May 21, 2016 22:55

Grade 1 Braille

Post by NorbyDroid »

I created a program to show the different Braille symbols based on this video:
https://www.youtube.com/results?search_query=grade+1+braille


The output is as follows:

Code: Select all

   A       B
  ( )( )  ( )( )  
C ( )( )  ( )( )
  ( )( )  ( )( )
A} Special Braille Symbol
B} Normal Braille Symbol
C} Ascii Character

This program really isn't anything, but I thought I would share if anyone finds a use for it.

Code: Select all

Sub Replace(Char1 as String, Char2 as String, Text as String)
  For t as Integer=1 to Len(Text)
    If Mid(Text, t, 1)=Char1 then Mid(Text, t, 1)=Char2
  Next
End Sub

' Converts Braille to Character Data
Function GetChar(iChar as String) as String
  Dim as Integer tAsc
  Dim as String tOut

  Dim Letters as String= _
    "100000101000110000110100100100111000111"+ _
    "100101100011000011100100010101010110010"+ _
    "110110100110111010111110101110011010011"+ _
    "110100011101011110011110111100111011101"
  
  tAsc=Asc(iChar): tOut=""

  ' Special Symbols
  If tAsc=20 then tOut="000101" ' Letter
  If tAsc=21 then tOut="000001" ' Capital Letter
  If tAsc=22 then tOut="010111" ' # Number
  If tAsc=23 then tOut="010001" ' Decimal Point

  If tOut<>"" then tAsc=0
  
  ' Letters
  If tAsc>64 and tAsc<91 then tAsc+=32
  If tAsc>96 and tAsc<123 then tOut=Mid(Letters, 6*(tAsc-97)+1, 6): tAsc=0

  ' Numbers
  If tAsc>47 and tAsc<58 then
    tAsc-=48: If tAsc=0 then tAsc=10
    tOut=Mid(Letters, 6*(tAsc-1)+1, 6): tAsc=0
  EndIf

  ' Punctuation
  ' Note: In Grade 1 Braille question mark and Open quote use the same symbol.
  ' Here I separated them and use the close quote symbol to represent both opan and close quotes.
  If tAsc=32            then tOut="000000" ' Space
  If tAsc=33            then tOut="001110" ' !
  If tAsc=34            then tOut="000111" ' "
  If tAsc=40 or tAsc=41 then tOut="001111" ' ()
  If tAsc=42            then tOut="000110" ' *
  If tAsc=44            then tOut="001000" ' ,
  If tAsc=46            then tOut="001101" ' .
  If tAsc=58            then tOut="001100" ' :
  If tAsc=59            then tOut="001010" ' ;
  If tAsc=63            then tOut="001011" ' ?
  
  ' For Unknown Characters
  If tOut="" then tOut="111111"

  Replace "0", " ", tOut
  Replace "1", "*", tOut

  Return tOut
End Function

Sub DrawChar(xPos as Integer, yPos as integer, CharStr as String)
  Dim as String tChar=GetChar(CharStr)

  For t as Integer=1 to 6
    Dim as Integer tx=(t-1) Mod 2
    Dim as Integer ty=(t-1) \ 2

    Locate ty+yPos, 3*tx+xPos, 0
    Print "("; Mid(tChar, t, 1); ")";
  Next
End Sub

Sub Demo
  ' Demo Text (Includes all Letters, Numbers, Punctuation, and Special Symbols)
  Dim as String Text

  For t as Integer=0 to 25
    Text=Text+Chr(97+t)+Chr(65+t)
    If t<10 then Text=Text+Chr(48+t)
  Next

  Text=Text+Chr(32)+Chr(33)+Chr(34)+Chr(40)+Chr(41)+ _
            Chr(42)+Chr(44)+Chr(46)+Chr(58)+Chr(59)+Chr(63)

  ' Special Symbols Flag
  Dim as Integer Flag

  ' Draw Special Symbol
  DrawChar 4, 2, Chr(20)

  For t as Integer=1 to Len(Text)
    Locate 3, 2, 0: Print Mid$(Text, t, 1);
    
    Dim as Integer tAsc=Asc(Mid(Text, t, 1))

    ' Lower Case Letters
    If tAsc>96 and tAsc<123 then
      If Flag<>0 then Flag=0: DrawChar 4, 2, Chr(20)
    EndIf

    ' Upper Case (Capital Letters)
    If tAsc>64 and tAsc<91 then
      If Flag<>1 then Flag=1: DrawChar 4, 2, Chr(21)
    EndIf
    
    ' Numbers
    If tAsc>47 and tAsc<58 then
      If Flag<>2 then Flag=2: DrawChar 4, 2, Chr(22)
    EndIf
  
    DrawChar 12, 2, Chr(tAsc): Sleep
    If Inkey=Chr(27) then End
  Next
End Sub

CLS
Demo
I tested this in Linux and all characters and symbols are proper as far as I could tell. If there are any gremlins, please let me know and I will correct it.
Post Reply