pxt-calliope/docs/reference/input/on-gesture.md

46 lines
983 B
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# On Gesture
2016-04-13 17:27:45 +02:00
Register an [event handler](/reference/event-handler) that will execute whenever the user executes a gesture withthe BBC micro:bit.
2016-03-26 00:47:20 +01:00
```sig
input.onGesture(Gesture.Shake,() => {
})
```
## Gestures
### Example: random number
The following example displays a number from 0-9 on the screen when you shake the BBC micro:bit.
```blocks
input.onGesture(Gesture.Shake,() => {
let x = Math.random(10)
basic.showNumber(x, 100)
})
```
### Example: rock, paper, scissors
The following example shows one of three images (rock, paper, or scissors) when you shake the BBC micro:bit.
```blocks
input.onGesture(Gesture.Shake,() => {
let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
img.showFrame(Math.random(3))
})
```
### Lessons
2016-04-13 17:27:45 +02:00
[bounce image](/lessons/bounce-image), [rock paper scissors](/lessons/rock-paper-scissors)
2016-03-26 00:47:20 +01:00