Workshop › Missile Command-style Defense › Step 17 of 35
Draw the explosions
What we are doing
Each explosion is a filled circle of its current radius. It flickers between yellow and orange every three frames.
```js
for (const b of blasts) {
ctx.fillStyle = b.age % 6 < 3 ? '#fde047' : '#fb923c'
ctx.beginPath()
ctx.arc(b.x, b.y, radius(b), 0, Math.PI * 2)
ctx.fill()
}
```
What it means
% is the remainder: b.age % 6 counts 0 to 5 again and again, so the color changes every 3 frames.
arc(x, y, r, 0, Math.PI * 2) describes a full circle; fill() paints it.
Your turn
In draw, under the interceptor lines loop, write the explosion loop.
Skills: Drawing on a canvas
← Explode on arrival Impacts explode too →
All steps
- Six cities to protect
- Your missile base
- Draw again and again
- Cities that can fall
- Rubble
- Move towards a point
- Launch an enemy missile
- One missile a second
- Missiles on their way
- Smoke trails
- Impact
- Fire an interceptor
- Click the sky
- Interceptors fly
- An explosion that grows and shrinks
- Explode on arrival
- Draw the explosions
- Impacts explode too
- Caught in the blast
- Chain reactions
- Only your explosions count
- Points for every missile
- Show the score
- Limited ammo
- Waves
- Each wave is harder
- The end of a wave
- The end
- Play again
- Wave, ammo and messages
- Launch from anywhere
- Some missiles will split
- Split into three
- A high score
- Build it yourself: a crosshair