diff --git a/docs/examples.md b/docs/examples.md index ec64d259..00c1c934 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -68,6 +68,27 @@ Here are some fun programs for your @boardname@! }] ``` +## Turtle graphics + +```codecard +[{ + "name": "Turtle Square", + "description": "move in a square", + "url":"/examples/turtle-square", + "cardType": "example" +}, { + "name": "Turtle Spiral", + "description": "move in a spiral", + "url":"/examples/turtle-spiral", + "cardType": "example" +}, { + "name": "Turtle Scanner", + "description": "scans the screen down", + "url":"/examples/turtle-scanner", + "cardType": "example" +}] +``` + ## Actuators ```codecard diff --git a/docs/examples/turtle-scanner.md b/docs/examples/turtle-scanner.md new file mode 100644 index 00000000..d938e40e --- /dev/null +++ b/docs/examples/turtle-scanner.md @@ -0,0 +1,23 @@ +# Turtle Scanner + +The turtle keeps on the scanning the screen. + +```blocks +turtle.setPosition(0, 0) +turtle.turnRight() +turtle.setSpeed(20) +basic.forever(() => { + turtle.forward(4) + turtle.turnRight() + turtle.forward(1) + turtle.turnRight() + turtle.forward(4) + turtle.turnLeft() + turtle.forward(1) + turtle.turnLeft() +}) +``` + +```package +microturtle=github:Microsoft/pxt-microturtle#master +``` diff --git a/docs/examples/turtle-spiral.md b/docs/examples/turtle-spiral.md new file mode 100644 index 00000000..3f3494bf --- /dev/null +++ b/docs/examples/turtle-spiral.md @@ -0,0 +1,23 @@ +# Turtle Spiral + +The turtle goes to the center back and forth. + +```blocks +let index = 0 +turtle.setPosition(0, 0) +turtle.turnRight() +basic.forever(() => { + for (let index = 0; index <= 4; index++) { + turtle.forward(4 - index) + turtle.turnRight() + } + for (let index = 0; index <= 4; index++) { + turtle.turnLeft() + turtle.back(index) + } +}) +``` + +```package +microturtle=github:Microsoft/pxt-microturtle#master +``` diff --git a/docs/examples/turtle-square.md b/docs/examples/turtle-square.md new file mode 100644 index 00000000..6d4f0de9 --- /dev/null +++ b/docs/examples/turtle-square.md @@ -0,0 +1,17 @@ +# Turtle Square + +A turtle program that runs in a square. + +```blocks +turtle.setPosition(0, 0) +turtle.turnRight() +turtle.setSpeed(29) +basic.forever(() => { + turtle.forward(4) + turtle.turnRight() +}) +``` + +```package +microturtle=github:Microsoft/pxt-microturtle#master +```