Workshop › Battleship › Step 27 of 35
It is fun to see what the computer is thinking. When showHeat is on, your small sea is painted orange: the hotter a
square, the brighter.
```js
let showHeat
showHeat = false
function drawSea(origin, size, shotsGrid, fleet, showShips, heat) {
const max = heat ? Math.max(1, ...heat.flat()) : 1
// The heat map: brighter where the computer thinks a ship is more likely.
if (heat && heat[r][c] > 0) ctx.fillStyle = `rgba(249, 115, 22, ${(0.15 + (0.85 * heat[r][c]) / max).toFixed(2)})`
drawSea(SEA, BIG, myShots, enemyFleet, false, null)
drawSea(HOME, SMALL, theirShots, myFleet, true, showHeat ? heatMap() : null)
```heat is a heat map or null (no colors). max is the hottest value, at least 1.heat / max is between 0 and 1.${...} puts a value inside the text.let shots, write let showHeat; in reset, under shots = 0, write showHeat = false.drawSea, add the heat parameter, the max line and the two heat lines.null for the enemy's sea and showHeat ? heatMap() : null for yours.Skills: Drawing on a canvas
← Hunt around a hit H for heat →