19.04.2017 Views

Learn to Program with Small Basic

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

a: 97<br />

b: 98<br />

1: 49<br />

2: 50<br />

Fancy Characters<br />

Let’s explore some characters not used in English. Listing 18-4 shows a<br />

simple program that displays the symbols for 140 Unicode characters, starting<br />

<strong>with</strong> the character whose code point is 9728. You can change this number<br />

<strong>to</strong> explore other Unicode symbols.<br />

1 ' UnicodeDemo.sb<br />

2 GraphicsWindow.BrushColor = "Black"<br />

3 GraphicsWindow.FontSize = 30 ' Makes the font larger<br />

4<br />

5 code = 9728 ' Code point for the first symbol<br />

6 xPos = 0 ' Horizontal position for drawing a symbol<br />

7 yPos = 0 ' Vertical position for drawing a symbol<br />

8 For row = 1 To 7 ' Draws 7 rows<br />

9 xPos = 0 ' For each new row, start at the left edge<br />

10 For col = 1 To 20 ' 20 columns for each row<br />

11 ch = Text.GetCharacter(code) ' Gets a character<br />

12 GraphicsWindow.DrawText(xPos, yPos, ch) ' Draws it<br />

13 code = code + 1 ' Sets <strong>to</strong> next code point<br />

14 xPos = xPos + 30 ' Leaves a horizontal space<br />

15 EndFor<br />

16 yPos = yPos + 30 ' Moves <strong>to</strong> the next row<br />

17 EndFor<br />

Listing 18-4: Demonstrating Unicode characters<br />

The outer For loop runs seven times (line 8). Each time the outer<br />

loop runs, the inner loop displays 20 symbols that are placed 30 pixels<br />

apart (lines 10–15). After drawing a complete row of symbols, we move<br />

the vertical drawing position down 30 pixels <strong>to</strong> draw the next row (line 16).<br />

Figure 18-3 shows the output of this program.<br />

Figure 18-3: The output of UnicodeDemo.sb<br />

Advanced Text Magic 271

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!