moving turtle examples
This commit is contained in:
parent
e27232667d
commit
fe444a8371
@ -76,24 +76,3 @@ Here are some fun programs for your @boardname@!
|
|||||||
"cardType": "example"
|
"cardType": "example"
|
||||||
}]
|
}]
|
||||||
```
|
```
|
||||||
|
|
||||||
## 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": "Scan down the screen",
|
|
||||||
"url": "/examples/turtle-scanner",
|
|
||||||
"cardType": "example"
|
|
||||||
}]
|
|
||||||
```
|
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
# Turtle Square
|
|
||||||
|
|
||||||
A turtle that traces a square pattern.
|
|
||||||
|
|
||||||
```blocks
|
|
||||||
turtle.setPosition(0, 0)
|
|
||||||
turtle.turnRight()
|
|
||||||
turtle.setSpeed(29)
|
|
||||||
basic.forever(() => {
|
|
||||||
turtle.forward(4)
|
|
||||||
turtle.turnRight()
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
```package
|
|
||||||
microturtle=github:Microsoft/pxt-microturtle#master
|
|
||||||
```
|
|
@ -1,5 +1,17 @@
|
|||||||
# Turtle Scanner
|
# Turtle Scanner
|
||||||
|
|
||||||
|
## Setting up your project
|
||||||
|
|
||||||
|
This project uses an **microturtle** Extension. You'll need to add it to your project to make it work.
|
||||||
|
|
||||||
|
* create a new project
|
||||||
|
* click on the gearwheel menu and click **Extensions**
|
||||||
|
* select the **microturtle** extension
|
||||||
|
|
||||||
|
After the project reloads, you should see the **turtle** category in the blocks.
|
||||||
|
|
||||||
|
## Code
|
||||||
|
|
||||||
The turtle scans the display over and over again.
|
The turtle scans the display over and over again.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
@ -1,5 +1,17 @@
|
|||||||
# Turtle Spiral
|
# Turtle Spiral
|
||||||
|
|
||||||
|
## Setting up your project
|
||||||
|
|
||||||
|
This project uses an **microturtle** Extension. You'll need to add it to your project to make it work.
|
||||||
|
|
||||||
|
* create a new project
|
||||||
|
* click on the gearwheel menu and click **Extensions**
|
||||||
|
* select the **microturtle** extension
|
||||||
|
|
||||||
|
After the project reloads, you should see the **turtle** category in the blocks.
|
||||||
|
|
||||||
|
## Code
|
||||||
|
|
||||||
A turtle that spirals into the center of the display and back out again.
|
A turtle that spirals into the center of the display and back out again.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
37
docs/projects/turtle-square.md
Normal file
37
docs/projects/turtle-square.md
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# Turtle Square
|
||||||
|
|
||||||
|
## Setting up your project
|
||||||
|
|
||||||
|
This project uses an **microturtle** Extension. You'll need to add it to your project to make it work.
|
||||||
|
|
||||||
|
* create a new project
|
||||||
|
* click on the gearwheel menu and click **Extensions**
|
||||||
|
* select the **microturtle** extension
|
||||||
|
|
||||||
|
After the project reloads, you should see the **turtle** category in the blocks.
|
||||||
|
|
||||||
|
## Moving the turtle
|
||||||
|
|
||||||
|
Imagine that a virtual turtle, as big as an LED, that you can control with commands. It starts in the center of the screen facing up.
|
||||||
|
|
||||||
|
You can use the ``||turtle:forward||`` and ``||turtle::turnRight||`` to move and turn the turtle.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
turtle.forward(2)
|
||||||
|
turtle.turnRight()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Drawing a square
|
||||||
|
|
||||||
|
Drawing a square can be decomposed into a sequence of moves and turns. Since this is quite repetitive, you can use a **for** loop to repeat code.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
turtle.forward(2)
|
||||||
|
turtle.turnRight()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```package
|
||||||
|
microturtle=github:Microsoft/pxt-microturtle#master
|
||||||
|
```
|
21
docs/projects/turtle.md
Normal file
21
docs/projects/turtle.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Turtle
|
||||||
|
|
||||||
|
Turtle graphics on your @boardname@ screen!
|
||||||
|
|
||||||
|
## Turtle graphics
|
||||||
|
|
||||||
|
```codecard
|
||||||
|
[{
|
||||||
|
"name": "Square",
|
||||||
|
"description": "Move in a square",
|
||||||
|
"url": "/projects/turtle-square"
|
||||||
|
}, {
|
||||||
|
"name": "Spiral",
|
||||||
|
"description": "Move in a spiral",
|
||||||
|
"url": "/projects/turtle-spiral"
|
||||||
|
}, {
|
||||||
|
"name": "Scanner",
|
||||||
|
"description": "Scan down the screen",
|
||||||
|
"url": "/projects/turtle-scanner"
|
||||||
|
}]
|
||||||
|
```
|
@ -36,7 +36,8 @@
|
|||||||
"dexterind/pxt-gigglebot"
|
"dexterind/pxt-gigglebot"
|
||||||
],
|
],
|
||||||
"preferredRepos": [
|
"preferredRepos": [
|
||||||
"Microsoft/pxt-neopixel"
|
"Microsoft/pxt-neopixel",
|
||||||
|
"Microsoft/pxt-microturtle"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"languages": [
|
"languages": [
|
||||||
@ -74,6 +75,7 @@
|
|||||||
"Music": "projects/music",
|
"Music": "projects/music",
|
||||||
"Toys": "projects/toys",
|
"Toys": "projects/toys",
|
||||||
"Science": "projects/science",
|
"Science": "projects/science",
|
||||||
|
"Turtle": "projects/turtle",
|
||||||
"Examples": "examples"
|
"Examples": "examples"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user