|
|
@@ -6,45 +6,46 @@
|
|
|
proc drawText(x, y: int; text: string; size: int; color: Color)
|
|
|
```
|
|
|
|
|
|
-We pass the following parameters to it:
|
|
|
+Мы передаем в процедуру следующие параметры:
|
|
|
|
|
|
-## x and y
|
|
|
+## x и y
|
|
|
+
|
|
|
+Координаты нижнего левого угла текста, который мы хотим нарисовать
|
|
|
|
|
|
-The coordinates of a bottom-left corner of the text we want to draw
|
|
|
## text
|
|
|
|
|
|
-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".
|
|
|
+Текст, который мы хотим отобразить. Он имеет тип `string`. Мы рассмотрим строки более подробно в следующей главе, а пока достаточно знать, что `string` - это _встроенный_ тип, который примерно представляет собой последовательность символов `char`, и строковый литерал может быть заключен в двойные кавычки, например "примерно вот так".
|
|
|
|
|
|
## size
|
|
|
|
|
|
-This is a height of the text in pixels.
|
|
|
+Это высота текста в пикселях.
|
|
|
|
|
|
## color
|
|
|
|
|
|
-Similarly to the putPixel proc, we can define the color of the text we’re drawing.
|
|
|
+Как и в процедуре `putPixel`, мы можем задать цвет рисуемого текста.
|
|
|
|
|
|
-The simplest way to call this proc is like this:
|
|
|
+Самый простой способ вызвать эту процедуру:
|
|
|
|
|
|
```nim
|
|
|
- drawText 30, 40, "Welcome to Nim!", 10, Yellow
|
|
|
+ drawText 30, 40, "Привет из 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.
|
|
|
+Обратите внимание, что мы не использовали скобки после названия функции для обозначения списка аргументов. Это эквивалентно `drawText(10, 10, "Привет из Nim!", Yellow)`, можно использовать любой стиль.
|
|
|
|
|
|
-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:
|
|
|
+Для следующего, более интересного примера нам понадобится оператор доллара `$`, который может преобразовывать многие типы данных в их строковое представление, и оператор конкатенации `&`, который объединяет («конкатенирует») две строки в одну:
|
|
|
|
|
|
```nim
|
|
|
- $12 == "12" # convert an integer into a string
|
|
|
- "abc" & "def" == "abcdef" # concatenate two strings into one
|
|
|
+$12 == "12" # конвертирует целое ччисло в строку
|
|
|
+"abc" & "def" == "abcdef" # объединяет две строки в одну
|
|
|
```
|
|
|
|
|
|
-The following example produces 3 lines of text:
|
|
|
+В следующем примере выводится 3 строки текста:
|
|
|
|
|
|
```nim
|
|
|
for i in 1..3:
|
|
|
- let texttodraw = "welcome to nim for the " & $i & "th time!" 1
|
|
|
- drawtext 10, i*10, texttodraw, 8, Yellow 2
|
|
|
+ let texttodraw = "Добро пожаловать в Nim for the " & $i & " раз!" # 1
|
|
|
+ drawtext 10, i*10, texttodraw, 8, Yellow # 2
|
|
|
```
|
|
|
|
|
|
-- 1 Creates a string (concatenated from three separate strings) and assigns it to the local variable textToDraw.
|
|
|
-- 2 Renders the text at position (10, i*10) where i is in one of the numbers in the 1..3 range, for each loop iteration.
|
|
|
+- 1 Создает строку (объединенную из трех отдельных строк) и присваивает ее локальной переменной `textToDraw`.
|
|
|
+- 2 Отображает текст в позиции `(10, i*10)`, где `i` — одно из чисел в диапазоне `1..3`, для каждой итерации цикла.
|