Skip to content
ExamplesOpen editor ↗

thalaMokwalo

→ text()

Draws text on the canvas.

thalaMokwalo(words, x, y) | thalaMokwalo(words, x, y, boxWidth, boxHeight)

It takes a string and a point, and draws the string there. The colour comes from tlatsaMmala, the size from bogoloJwaMokwalo, and where the string sits relative to the point from rulaganyaMokwalo.

Note this distinction: kwala sends words to the console — the coder’s own workspace. thalaMokwalo draws, on the canvas, where everyone can see. That is why its name begins with thala, like thalaSediko and thalaMothalo, rather than with kwala.

You may give it two further numbers — the width and height of a text box. When you do, a long string breaks across several lines, and kgaoloMokwalo chooses where the breaks fall.

NameTypeDescription
mafokomokwaloThe text to draw.
xpaloThe x-coordinate of the point the text is placed at.
ypaloThe y-coordinate of that point.
bopharaLebokoso (optional)paloThe maximum width of the text box. When given, the text breaks into lines.
boleeleLebokoso (optional)paloThe maximum height of the text box.
A Setswana proverb on the canvas
tiro setaLoeto() {
  thalaKanefase(400, 240);
  bokamorago(24, 30, 44);

  tlogelaMothalo();
  tlatsaMmala(245, 232, 210);
  bogoloJwaMokwalo(26);
  rulaganyaMokwalo(BOGARE, BOGARE);

  // Lebokoso le le bophara jwa 320 le kgaoganya mokwalo mo meleng
  sebakaSaMela(34);
  thalaMokwalo('Mmangwana o tshwara thipa ka fa bogaleng.', 200, 120, 320);

  tlhalosa('Seane sa Setswana se se kwadilweng ka mmala o o bosetlha mo bokamoragong jo bontsho.');
}
The point you give is where the text starts
tiro setaLoeto() {
  thalaKanefase(400, 200);
  bokamorago(238);
  bogoloJwaMokwalo(28);

  // Mothalo o o bontshang gore ntlha e kae
  mothaloMmala(220, 60, 90);
  thalaMothalo(60, 40, 60, 160);

  tlogelaMothalo();
  tlatsaMmala(30, 40, 60);
  thalaMokwalo('Dumela', 60, 80);
  thalaMokwalo('lefatshe', 60, 130);

  tlhalosa('Mafoko a mabedi a a simololang mo mothalong o o mokhibidu o o emeng.');
}

bogoloJwaMokwalo, rulaganyaMokwalo, mokgwaWaMokwalo, kgaoloMokwalo, bopharaMokwalo, kwala