selekanyo
→ norm()Turns a number in a range into a fraction between 0 and 1.
selekanyo(boleng, simolo, bofelo)selekanyo(boleng, simolo, bofelo) asks one question: where in the range does this value sit?
- At the start, the answer is 0
- At the end, the answer is 1
- Halfway, the answer is 0.5
selekanyo(2, 0, 10) is 0.2.
It is lekanyetsa(boleng, simolo, bofelo, 0, 1) — but shorter, and it says plainly that a fraction is all you wanted.
Numbers between 0 and 1 come up constantly in Bopa: they are what magareng asks for, and what paloKelelo gives back.
A value outside the range returns a number outside 0 and 1; it is not held back.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
boleng | palo | The number to turn into a fraction. |
simolo | palo | The lower bound of the range. |
bofelo | palo | The upper bound of the range. |
Examples
Section titled “Examples”tiro setaLoeto() {
thalaKanefase(400, 400);
bokamorago(245);
tlogelaMothalo();
metlha palo = 24;
gopheta (diri i = 0; i < palo; i = i + 1) {
// i e tswa mo 0..23 go ya go 0..1
metlha tekanyo = selekanyo(i, 0, palo - 1);
diri x = magareng(40, 360, tekanyo);
diri bogolwane = magareng(8, 60, tekanyo);
tlatsaMmala(magareng(240, 40, tekanyo), 110, magareng(80, 220, tekanyo));
thalaSediko(x, 200, bogolwane);
}
}