------------------------------------------------------------"Learning Lower-Case ABC's" from October, 1989------------------------------------------------------------ For the past few years, most of my spare time has beenoccupied writing BASIC programs, product reviews, andgeneral interest computing articles for ONE THOUSANDmagazine. However, something wonderful happened just a fewweeks ago, and it very easily knocked computing down a fewnotches on my list of priorities. On Sunday, January 15, 1989, my wife Marie gave birth to ababy girl! Our new daughter is named Amy Marie Hawkins, andshe weighed in at 9 pounds. Mother, daughter, and sisterJulie (age five) are doing fine. Today (almost three weekslater), things are finally getting back to normal around ourhouse. As I think about Amy's future, I am certain that computerswill play a big part in her life -- not just in education,but in every phase of her existence. I know she will takecomputers for granted; they will be as commonplace to her ascars, television, and jet airplanes are to you and me. Computers and Julie ------------------- I know her sister, Julie, feels that way. Julie and I havebeen playing and learning with the computer for years. Oneof Julie's favorite programs is called "My ABC's". If youwould like to learn more about this excellent program(available at most software stores for less than $15), seethe review I wrote for the September, 1986, issue of ONETHOUSAND. "My ABC's" has helped Julie to learn the letters of thealphabet, to count, and to become familiar with the computerkeyboard. The program features colorful pictures and plentyof music to make learning fun. My only complaint (and it isa minor one) is that it uses only upper-case letters; theletters' lower-case equivalents are never displayed. As a result, Julie recognizes all of the upper case letters,and knows the "sound" each one makes. However, she findsmost of the lower-case letters baffling. Oh, sure, some ofthe letters (like "c", "j", "s", and "v" for example) lookalmost the same. But other lower-case letters (like "a","d", "e", and "g" for example) look entirely different fromtheir upper-case counterparts. That is where this month's program comes in. Quite simply,it displays one of the twenty-six lower-case letters andwaits for the player to press the corresponding upper-casekey that matches. When the proper key is pressed, a borderis drawn around the lower-case letter using its upper-caseequivalent and a few measures of the "ABC's" song is played. A Typical Month --------------- Although this month's schedule has been a little out of theordinary, I thought you might be interested to find out howthis column is put together each month. I spend about oneweek each month scratching my head thinking about what towrite about. I check the pile of notes I have written tomyself and stuck in the desk drawer; I read letters that youreaders send in containing suggestions; I read messages onthe People Link and PC-LINK telecommunication networks, allin an effort to come up with an idea with wide appeal. Once I decide on a topic, I spend about a week doingresearch. I look up the equations or information needed toimplement the program. I doodle on paper, trying to decidewhat the screen will look like while the program is running.I try to decide which keys the program will use. Mostimportantly, I think about the algorithm -- that is, whatsteps will the program take to arrive at the proper answer. I have never particularly cared for flowcharts, so I do notuse them. However, for a particularly complicated program,I will write down the steps that the program will use; ineffect, I write a "word flowchart". Once I have an idea howto make a program do what I want it to do, I begin to writeit. If I have done my homework correctly, I can write theBASIC program and get it running in one or two nights. Ispend the rest of another week polishing, renumbering, andadding REMark statements. In the remaining week, I write the accompanying article.That is often the most difficult part of the process for me-- I write programs easily, but writing a couple of pages ofentertaining text that explains the inner workings of theprogram is about as much fun as going to the dentist.Nevertheless, somehow I get it done. If I have any timeleft over at the end of the month, I try to write a reviewfor the magazine's "More For Your Money" section, or anarticle on some other general interest topic. How It Works ------------ The "SCREEN 1" command in line 140 tells BASIC that we willbe using the medium-resolution graphic mode. We need to usea graphic mode to draw pictures of the letters. TheRANDOMIZE TIMER command uses the current time (in seconds)to insure that the series of random numbers used in theprogram will be different almost every time it is RUN. Lines 150 through 180 prepare the string variable S$, whichwill contain one of six snippets of the ABC song. Themusical information to play that song are contained in thestrings of characters stored in the DATA statements.Variable M is a counter used to determine which snippet toplay after each correct response. Line 220 uses the random number function RND to pick anumber from 1 to 26 and store it in variable N; that numberN will represent one of the twenty-six letters of thealphabet. The call to subroutine 770 draws three rulerlines on the screen. Look carefully at lines 230 through 260; if you follow thefancy arithmetic, you will find that at the conclusion ofthat section, one of twenty-six different subroutines willhave been called. The variable N is used to decide whichsubroutine to call. When N equals 1, the program calls subroutine 480 whichdraws the lower-case letter "A". When N equals 2,subroutine 490 is called to draw a lower-case "B".Similarly, subroutine 500 draws a "C"; subroutine 510 drawsa "D"; and so on. Once a letter has been drawn, line 300 waits for a key to bestruck. If the ESC key is pressed, line 310 exits theprogram. Line 320 checks to see if the key pressed is theproper one (by translating the value N into its equivalentASCII code); if not, control passes back to line 300 foranother check. If the correct key is pressed, lines 370 through 420 presenta musical and visual reward for the proper response. Line370 plays a snippet of the "ABC's" song, while lines 380through 420 draw a border around the edge of the screencomposed of the corresponding upper-case letter. Line 430causes the program to pause about two seconds beforecontinuing. Line 440 changes the screen colors at random,then jumps back to line 220 to begin the process again. Drawing the Letters ------------------- We have already talked about lines 480 through 730; each onedraws one of the twenty-six letters of the alphabet. Noticethat each one of those subroutines calls one or more of thesubroutines near the end of the program. These utilitysubroutines (from line 820 to the end of the program) draw avariety of shapes that are used to construct the letters. Let's take a look at those utility subroutines. Thesubroutine beginning at 820 draws a circle; it is used tocreate letters such as "b", "d", and "o". The subroutinesbeginning at lines 840 and 870 draw semi-circles. The firstone draws the upper half only; the second, the lower half. Subroutines 930, 940, 950, and 960 draw the full and halfheight "stems" used in letters which have straight sides(like "i", "n", "l", and "h"). Subroutine 1000 draws thedescender tail for letters such as "g" and "y". Subroutine 1050 draws an inverted "u" shape, which is usedto draw characters such as the "h" and "n". Subroutine 1070puts the dot on the "i" and "j", while subroutine 1080 drawsa lowercase "u" shape. Subroutine 1130 draws a diagonal slash used in the "x" and"z" characters. Subroutine 1160 draws a lowercase "v"character. Subroutine 1220 draws a "cross" used for the "t"character. Subroutine 1240 draws the right side of theletter "k" (the crooked part). Subroutine 1310 draws the second hump in the lowercase "m",while subroutine 1330 draws the lowercase "s". The lastthree subroutines, starting in lines 1410, 1510, and 1540,draw the lowercase "w", the descending diagonal in the "x",and the top and bottom bars in the "z". Wrapping Up ----------- That's it for another month. I hope that you and yourpre-school computer partners will enjoy and learn from thisprogram. As always, I encourage you to write to me in careof ONE THOUSAND magazine with your questions, comments, andsuggestions for future columns. See you next month!