alessandrocuzzocrea/chip-8-emulator-js

View on GitHub
src/renderer.js

Summary

Maintainability
A
25 mins
Test Coverage
const c = require("./consts");

const SCALE = 8;

function render(chip, canvas) {
  const ctx = canvas.getContext("2d");
  ctx.fillStyle = "#1abc9c";
  ctx.fillRect(0, 0, canvas.width, canvas.height);

  ctx.fillStyle = "#2c3e50";

  for (let y = 0; y < c.screenHeight; y++) {
    for (let x = 0; x < c.screenWidth; x++) {
      if (chip.display[x + y * c.screenWidth] !== 0x0) {
        ctx.fillRect(x * SCALE, y * SCALE, SCALE, SCALE);
      }
    }
  }
}

module.exports = { render };