Skip to content
ExamplesOpen editor ↗

thibela

→ constrain()

Stops a number from going past a lower or an upper limit.

thibela(boleng, kwaTlase, kwaGodimo)

When the number is already between the limits, thibela returns it unchanged. When it goes past the upper limit, that limit is returned; when it falls below the lower one, that is returned.

  • thibela(150, 0, 100) is 100
  • thibela(-20, 0, 100) is 0
  • thibela(45, 0, 100) is 45

This earns its place when a value comes from outside — from the mouse, from paloEpe, or from a sum — and you want to be sure a shape stays on the canvas.

lekanyetsa can do the same thing when you pass it nnete as the sixth value.

NameTypeDescription
bolengpaloThe number to hold.
kwaTlasepaloThe lower limit.
kwaGodimopaloThe upper limit.
Circles that cannot leave the canvas
tiro setaLoeto() {
  thalaKanefase(400, 400);
  bokamorago(238);
  tlogelaMothalo();

  paloEpePeo(21);

  gopheta (diri i = 0; i < 80; i = i + 1) {
    // `paloEpe` e ka ntsha dipalo tse di kwa ntle ga kanefase
    diri x = paloEpeGauss(200, 160);
    diri y = paloEpeGauss(200, 160);

    // `thibela` e di busetsa mo teng
    tlatsaMmala(60, 150, 190);
    thalaSediko(thibela(x, 30, 370), thibela(y, 30, 370), 26);
  }
}

lekanyetsa, selekanyo, paloEpe