Библиотека pixels может не только вызывать putPixel: она также предлагает минимальную процедуру drawText для вывода букв и слов на экран. Ее объявление выглядит так:
proc drawText(x, y: int; text: string; size: int; color: Color)
We pass the following parameters to it:
The coordinates of a bottom-left corner of the text we want to draw
The text we want to render. It is of type string. We will look at strings in more depth in the next chapter, for now it is enough to know that string is a builtin type that is roughly a sequence of char, and a string literal can be written in double quotes, for example "like this".
This is a height of the text in pixels.
Similarly to the putPixel proc, we can define the color of the text we’re drawing.
The simplest way to call this proc is like this:
drawText 30, 40, "Welcome to Nim!", 10, Yellow
Notice that we didn’t use the parentheses after the name of the function to enclose the list of arguments. This is equivalent to drawText(10, 10, "Welcome to Nim!", Yellow), either style can be used.
For the next more interesting example we need the dollar operator $ which can turn many types into its string representation, and the concatenation operator & which combines (“concatenates”) two strings into one:
$12 == "12" # convert an integer into a string
"abc" & "def" == "abcdef" # concatenate two strings into one
The following example produces 3 lines of text:
for i in 1..3:
let texttodraw = "welcome to nim for the " & $i & "th time!" 1
drawtext 10, i*10, texttodraw, 8, Yellow 2