Workshop › Typing Rain › Step 29 of 33
On a phone there is no keyboard, so we will draw one under the ground: the three QWERTY rows, each centred under the
one above. keyRect(row, i) works out where key i of a row goes.
```js
const ROWS = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']
const KEY_W = 44
const KEY_H = 34
const KEYS_Y = 350
// The on-screen keyboard, one row under another, each row centered.
function keyRect(row, i) {
const left = (canvas.width - ROWS[row].length * (KEY_W + 3) + 3) / 2
return { x: left + i * (KEY_W + 3), y: KEYS_Y + row * (KEY_H + 7) }
}
```KEY_W by KEY_H, 3 pixels apart; rows are 7 pixels apart, from KEYS_Y.n keys is n * (KEY_W + 3) - 3 pixels wide; left is half of what is left over, so the row is centred.{ x, y }.FONT write the four keyboard constants.function draw() { write the comment and keyRect, with an empty line after it.Skills: Arrays and objects, Functions
← Your speed at the end Draw the keyboard →