function init()
  cam = FindBody("Cam", true)
    camX = 46
    camY = 26
  pixels = {}
end

function tick()
  t = GetBodyTransform(cam)
  pixels = {}
  for x = 0, camX - 1 do
    for y = 0, camY - 1 do
      local xpos = (x - camX / 2) / 40
      local ypos = (y - camY / 2) / 40
      local dirn = TransformToParentVec(t, Vec(xpos, ypos, - 1))
      local dir = VecNormalize(dirn)
      local origin = VecCopy(t.pos)
      QueryRejectBody(cam)
      local hit, dist, normal, shape = QueryRaycast(origin, dir, 300)
      local endPoint = VecAdd(origin, VecScale(dir, dist))
      -- DrawLine(origin, endPoint, 1, 0, 0)
      local _, r, g, b, a = GetShapeMaterialAtPosition(shape, endPoint)
      table.insert(pixels, {x = x, y = y, r = r, g = g, b = b, a = a })
    end
  end
end

function draw()
  for i = 1, #pixels do
    local pixel = pixels[i]
    UiPush()
    UiTranslate(pixel.x * 10, pixel.y * 10)
    UiColor(pixel.r, pixel.g, pixel.b, pixel.a)
    UiRect(10, 10)
    UiPop()
  end
end