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 100thibela(-20, 0, 100)is 0thibela(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.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
boleng | palo | The number to hold. |
kwaTlase | palo | The lower limit. |
kwaGodimo | palo | The upper limit. |
Examples
Section titled “Examples”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);
}
}