How do I light up any pixel with render2D

I am trying to create an “Electronic Minora” pattern (lighted candles in a 2d 32x8 matrix).
Here is a mapping functions which works as expected:

// Mapping for the 8x32 Matrix
// with vertical zigzagging
function (pixelCount)
{
  width  = 32  // Info, this value is not used
  height =  8

  var map = []

  for (i = 0; i < pixelCount; i++)
  {
    x = Math.floor(i / height) 
    y = (i % height)

    // y adjustment for vertical zigzag wiring
    y = (x % 2) == 1 ? (height - 1 - y) : y
    map.push([x, y])
  }

  return map
}

And here is my very simple test pattern:

export function beforeRender(delta) {
  t1 = time(.1)
}

export function render2D(index, x, y)
{
  h = 0.05
  s = 1
  
  if ((x == 0) && (y == 0))
  {
    v = 1
  }
  else
  {
    v = 0
  }
  hsv(h, s, v)
}

I can turn on only pixel with x = 0 and y = 0 coordinates.
Changing x and/or y to something other than 0 does not light up any led at all.
I assume, for the 32x8 matrix and mapping as shown above the x range is 32 (0:31) and y range is 8 (0:7) but this is not working as expected. If I use Index instead of x,y I can light up any led as expected.
What I am missing?

1 Like

Hi Vitaliy,

Mapped (x,y) coordinates passed as parameters to render2D (also z in 3D) are normalized to the range 0.0 to 1.0, so patterns will work regardless of the specific underlying display.

If you know the height and width of your display, floor(x * width) and floor(y * height) will get you the original coordinate values.

Thank you for the advice.
I was thinking about x,y are normalized but did not figure out how to use this normalized values.