wasm4 icon indicating copy to clipboard operation
wasm4 copied to clipboard

[docs] Set compolr in docs and templetes are differ

Open MaxGraey opened this issue 4 years ago • 2 comments
trafficstars

Docs show example which uses 0x42

store<u16>(w4.DRAW_COLORS, 0x42);
w4.rect(10, 10, 32, 32);

But template uses store<u16>(w4.DRAW_COLORS, 2) for this.

Will be great explain what 0x42 mean and how it created. For example: 0x04 << 4 | 0x02. Even better have some util function like:

function encodeColors(xx: u32, yy: u32, zz: u32, ww: u32): u16 {
  return ((xx & 0x3) | (yy & 0x3) << 4 | (zz & 0x3) << 8 | (ww & 0x3) << 12) as u16;
}

MaxGraey avatar Sep 06 '21 06:09 MaxGraey

This is same.

Draw colors said that: 0x[1, 2, 3, 4] remap current palette colors. 4 colors but 5 variants. 0 - transparent. Other lookups is shifted by 1, for handle a transparent. 1 means a 0 palette index etc. This all will be mapped onto framebuffer by lookup table.

0x2 same as 0x0002, this means that you replace a FILL color as 2 of pallete and 0 for stroke.

eXponenta avatar Sep 06 '21 08:09 eXponenta

DRAW_COLORS holds 4 color slots. You can think of each hex digit as a color slot, starting from right (least significant digit). So setting DRAW_COLORS to 0x42 will set the 1st draw color to 2 (the 2nd palette color), and the 2nd draw color 4 (the 4th palette color). A zero digit in any color slot means transparency.

Could this be made clearer in the docs somehow?

aduros avatar Sep 06 '21 23:09 aduros