Workshop › Flappy-style Bird › Step 14 of 30
Each pipe object becomes two green rectangles: the top one from y = 0 down to gapY, the bottom one from
gapY + GAP down to the ground. A for ... of loop draws every pipe in the array.
```js
ctx.fillStyle = 'green'
for (const pipe of pipes) {
ctx.fillRect(pipe.x, 0, PIPE_WIDTH, pipe.gapY)
ctx.fillRect(pipe.x, pipe.gapY + GAP, PIPE_WIDTH, canvas.height - pipe.gapY - GAP)
}
```for (const pipe of pipes) repeats its body once for each item, calling the current one pipe.gapY tall; the bottom one starts at gapY + GAP and fills the rest of the height.In draw, under the sky's fillRect, leave an empty line and write the pipe lines (before the gold bird lines).
Skills: Drawing on a canvas, Loops
← A pipe as data The world moves, not the bird →