setPixel method

void setPixel(
  1. int px,
  2. int py,
  3. bool value, {
  4. bool antiAliased = false,
  5. Style? cellStyle,
})

Sets pixel at (px, py) relative to canvas coordinates.

px ranges from 0 to width * 2 - 1. py ranges from 0 to height * 4 - 1.

Implementation

void setPixel(
  int px,
  int py,
  bool value, {
  bool antiAliased = false,
  Style? cellStyle,
}) {
  if (px < 0 || py < 0 || px >= width * 2 || py >= height * 4) return;

  final cx = px ~/ 2;
  final cy = py ~/ 4;

  final dx = px % 2;
  final dy = py % 4;
  final mask = _dotMasks[(dy << 1) | dx];

  final idx = cy * width + cx;
  if (value) {
    _grid[idx] |= mask;
  } else {
    _grid[idx] &= ~mask;
  }

  if (antiAliased) {
    _antiAliased[idx] = 1;
  }

  if (cellStyle != null) {
    _styles[idx] = cellStyle;
  }
}