Skip to content
ExamplesOpen editor ↗

lekanyetsa

→ map()

Takes a number in one range and measures it out onto another.

lekanyetsa(boleng, tlaseYaPele, godimoYaPele, tlaseYaBobedi, godimoYaBobedi, thibelwa)

The value you have is often not on the scale you need. paloKelelo gives 0 to 1, while your canvas is 400 wide. lekanyetsa is what closes that gap.

lekanyetsa(0.5, 0, 1, 0, 400) is 200 — the middle of the first range becomes the middle of the second.

The second range may run backwards: lekanyetsa(0, 0, 100, 400, 0) returns 400. That is how you flip a direction.

A value outside the first range carries on outside the second — lekanyetsa(2, 0, 1, 0, 100) is 200. To hold it at the edge instead, pass nnete as the sixth value, or use thibela.

NameTypeDescription
bolengpaloThe number to re-measure.
tlaseYaPelepaloThe lower bound of the range the number is in now.
godimoYaPelepaloThe upper bound of the range it is in now.
tlaseYaBobedipaloThe lower bound of the range you want.
godimoYaBobedipaloThe upper bound of the range you want.
thibelwa (optional)nnetemaakaWhen nnete, the result is held inside the range you want. Defaults to maaka.
Measuring the flow onto the height of the canvas
tiro setaLoeto() {
  thalaKanefase(400, 400);
  bokamorago(24, 28, 38);
  tlogelaMothalo();

  paloKeleloPeo(12);

  gopheta (diri x = 0; x < 400; x = x + 4) {
    metlha kelelo = paloKelelo(x * 0.012);

    // 0..1 go ya go 40..360
    diri godimo = lekanyetsa(kelelo, 0, 1, 40, 360);

    // Selekanyo se le sengwe se lekanyediwa mo mmaleng
    tlatsaMmala(lekanyetsa(kelelo, 0, 1, 60, 250), 140, 210);
    thalaKhutlonne(x, godimo, 3, 400 - godimo);
  }
}
A range that runs backwards
tiro setaLoeto() {
  thalaKanefase(400, 400);
  bokamorago(240);
  tlogelaMothalo();

  gopheta (diri i = 0; i < 20; i = i + 1) {
    // i e gola, mme bophara bo a fokotsega
    diri bogolwane = lekanyetsa(i, 0, 19, 340, 20);
    diri mmala = lekanyetsa(i, 0, 19, 40, 230);

    tlatsaMmala(mmala, 90, 240 - mmala);
    thalaKhutlonne(200 - bogolwane / 2, i * 20, bogolwane, 16);
  }
}

selekanyo, thibela, magareng, paloKelelo