Monday, December 20, 2021

Draw big ascii block letters in vb and cs

I felt the need to draw big ascii letters like this:

'   ▄█▀▀█▄            ██                    
'   █▄▄  ▀▀  ▄█▀▀█▄  ▀██▀  ██  ██  ███▀█▄   
'    ▀▀▀██▄  ██▄▄██   ██   ██  ██  ██  ██   
'  ▀█▄  ▄█▀  ██  ▄▄   ██   ██  ██  ██  ██   
'    ▀▀▀▀     ▀▀▀▀    ▀▀▀   ▀▀▀▀▀  ██▀▀▀    
'                                  ▀▀       

So I wrote a program. The output should be used with a fixed-space font, like the Courier font used above.  

Instead of cluttering up the page with code that does not look good either, the code sections can be found at these links:
https://github.com/johnhaz/MakeBlockText/blob/main/MainPage.xaml
https://github.com/johnhaz/MakeBlockText/blob/main/MainPage.xaml.cs
https://github.com/johnhaz/MakeBlockText/blob/main/MainPage.xaml.vb

The first one is the main page which gets used with either the vb or c-sharp code dependent on project type. There is also a License page that describes the free license to the code. 

Putting it all together, one has a program that looks and operates like this:

It works by first rendering the letters to a bitmap and then taking the alpha bytes from that bitmap and transforming them into half height ascii blocks using math, should they pass a threshold.
 
Discussion:

The combo boxes in my 2022 version of Visual Studio are failing to track the caret. Additionally implementing name changes can have my code jumping 5000 lines, and wipe out the edit marks on the scrollbar as well. Also -- using the back arrow sometimes does not navigate right, skipping over the previous position by one especially if I select the position from a code reference in a window that has been dragged off the main Visual Studio window, like I show below. I also thing using this off-form configuration is the problem that causes that fails, and maybe the creators don't debug it like that. 

The result is getting lost a lot, or writing down every line I go to in 8000 lines. So I made this thing to put big comments inside my code that I could see while scrolling as a navigation aid. 

I also thought why not try making it in C-Sharp while I am having fun. That did take three hours, and yes, there was cursing at the computer and C-Sharp in particular, but I felt like I accomplished something.   

So I grouped all my code into sections, and applied the big green letters. The I wrote down an ordered list of them, so when I find one, I can check the map of 30 headings to see how far away I am from another section that I want to be in. This way I can move pretty fast. 

Notes on the first time I programmed a thing in C-Sharp. 

It's pretty anal. I have to typecast everything. It is unforgivingly and not attempting any match on error case conscious! Procs, when called, have to manually get the parentheses at the end or the thing will throw a strange error. Those braces are hard to track. Arrays are scaled using the actual length of the array, instead of upper bound, but indexed normally. Of course there is a different operator for everything logic. Case is switch -- blah, blah. No Chr or Asc. 

Having online resources sure does help. I relatively sailed through it. Despite the cursing