Skip to content
ExamplesOpen editor ↗

balaDiphikisele

→ loadPixels()

Reads every dot of the canvas into the `diphikisele` list.

balaDiphikisele()

A canvas is made of small dots called pixels. balaDiphikisele reads all of them into a list called diphikisele, so you can look at them or change them quickly.

The list is long: each dot takes four places — red, green, blue and transparency. So its length is width × height × 4. Measured on a 200×200 canvas: balaLenaane(diphikisele) is 160000.

Changing numbers in the list does nothing to the canvas until you call ntshwafatsaDiphikisele.

It is not needed before tlhotlha or mmalaWaPhikisele. Those read for themselves. It is needed only when you want the diphikisele list itself.

⚠ It is heavy work. A loop over every pixel of a large canvas can slow the drawing down.

Turn every dot grey
tiro setaLoeto() {
  thalaKanefase(200, 120);
  bokamorago(245);

  diri kgomo = letela tlisaSetshwantsho('kgomo.png');
  thalaSetshwantsho(kgomo, 20, 0, 120, 120);

  balaDiphikisele();
  gopheta (diri i = 0; i < balaLenaane(diphikisele); i = i + 4) {
    diri palogare = (diphikisele[i] + diphikisele[i + 1] + diphikisele[i + 2]) / 3;
    diphikisele[i] = palogare;
    diphikisele[i + 1] = palogare;
    diphikisele[i + 2] = palogare;
  }
  ntshwafatsaDiphikisele();

  tlhalosa('Setshwantsho sa kgomo se se fetotsweng go nna sa boputswa ka go bala ntlha nngwe le nngwe.');
}

ntshwafatsaDiphikisele, diphikisele, mmalaWaPhikisele, tlatsaPhikisele