Skip to content
ExamplesOpen editor ↗

bokgakalaPalo

→ abs()

Returns how far a number sits from 0 — always as a positive number.

bokgakalaPalo(palo)

On the number line, -5 and 5 both sit five steps away from 0. So bokgakalaPalo(-5) and bokgakalaPalo(5) both return 5.

The result is never below 0.

Use it when you want to know how far, without caring which side: the distance out from the middle of the canvas, the gap between two numbers, or a speed with the direction left out.

It is bokgakala on the number line — bokgakala(x, 0) and bokgakalaPalo(x) return the same number.

NameTypeDescription
palopaloThe number whose distance from zero is wanted.
A ridge rising out of the middle on both sides
tiro setaLoeto() {
  thalaKanefase(400, 400);
  bokamorago(245);
  tlogelaMothalo();

  gopheta (diri x = 0; x < 400; x = x + 8) {
    // Kgakala go tswa fa gare, letlhakore le sa kgathalelwe
    metlha kgakala = bokgakalaPalo(x - 200);

    tlatsaMmala(70 + kgakala / 2, 130, 230 - kgakala / 2);
    thalaKhutlonne(x, 380 - kgakala, 6, kgakala);
  }
}
-5 and 5 are equally far away
tiro setaLoeto() {
  thalaKanefase(400, 400);
  bokamorago(20, 24, 34);

  // Mothalo wa dipalo
  mothaloMmala(150);
  boketeMothalo(2);
  thalaMothalo(40, 200, 360, 200);

  metlha dipalo = [-5, -2, 2, 5];
  tlogelaMothalo();

  gopheta (metlha p mo dipalo) {
    metlha x = 200 + p * 30;
    metlha kgakala = bokgakalaPalo(p);

    // Ntlha mo mothalong wa dipalo
    tlatsaMmala(240, 190, 70);
    thalaSediko(x, 200, 12);

    // Bokgakala go tswa go 0 — bobedi -5 le 5 bo a lekana
    tlatsaMmala(90, 200, 240);
    thalaKhutlonne(x - 5, 230, 10, kgakala * 22);
  }
}

bokgakala, sekgala, palokgolo, atametsa