Loeffel-ei-loesung: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 6: | Zeile 6: | ||
<pre id="01"> | <pre id="01"> | ||
let accY = 0 | |||
let accX = 0 | |||
let x = 2 | |||
let y = 2 | |||
basic.forever(function () { | |||
led.plot(x, y) | |||
accX = input.acceleration(Dimension.X) | |||
accY = input.acceleration(Dimension.Y) | |||
if (accX < -150 && x > 0) { | |||
x += -1 | |||
} else if (accX > 150 && x < 4) { | |||
x += 1 | |||
} | } | ||
if (accY < -150 && y > 0) { | |||
y += -1 | |||
} else if (accY > 150 && y < 4) { | |||
y += 1 | |||
} | |||
basic.pause(500) | |||
basic.clearScreen() | |||
}) | }) | ||
</pre> | </pre> | ||
<htmlet>makecode_embed</htmlet> | <htmlet>makecode_embed</htmlet> |
Version vom 17. Januar 2022, 23:21 Uhr
Detailschritte
Die Lösung zu diesem Projekt wird hier in Teilen gezeigt:
- Ereignis "wenn geschüttelt"
- wenn-dann-Verzweigung
let accY = 0 let accX = 0 let x = 2 let y = 2 basic.forever(function () { led.plot(x, y) accX = input.acceleration(Dimension.X) accY = input.acceleration(Dimension.Y) if (accX < -150 && x > 0) { x += -1 } else if (accX > 150 && x < 4) { x += 1 } if (accY < -150 && y > 0) { y += -1 } else if (accY > 150 && y < 4) { y += 1 } basic.pause(500) basic.clearScreen() })