Lesson 1: Draw a Square
The [Move robot pen] block moves the Pen tool up and down on the VR Robot. This example will have the VR Robot draw a square on the Art Canvas Playground.
- Create a new VEXcode VR project. When prompted, select the Art Canvas Playground.
-
Drag in the [move robot pen] block and attach it beneath the [When started] block.
Using Switch Blocks
You can convert the [move pen] block into a Switch block by selecting, "Convert block to Switch block." You can change the block's parameters by typing "UP" to pick up the Pen, and "DOWN" to put down the Pen.
-
Drag in the [Drive for] block and attach it below the [move robot pen] block. Set the parameters of the [Drive for] block to 600 millimeters (mm).
-
Drag in the [Turn for] block and attach it beneath the [Drive for] block. Set the parameters of the [Turn for] block to turn right 90 degrees.
-
To draw the second side of the square, duplicate the [Drive for] and [Turn for] blocks. To duplicate, right click or long press on the [Drive for] block.
-
Additional [Drive for] and [Turn for] blocks are now added to the stack.
-
To draw the last two sides of the square, duplicate the [Drive for] and [Turn for] blocks. Right click or long press on the first [Drive for] block in the stack.
-
The stack of blocks will then be duplicated.
- Select the “Start” button to test the project.
-
The VR Robot will drive forward for 600 millimeters (mm) and then turn right for 90 degrees, while drawing with the Pen tool. The VR Robot will repeat these behaviors four times to draw all four sides of the square.
-
Select the “Reset” button to reset the Playground and move the VR Robot back to the starting position.
For Your Information
The [Set Pen color] block can be used to change the colors of the pen.
This is the Switch [Set pen color] block. Change the color by simply typing in your color of choice within the parentheses.
Select the Next button to continue with the rest of this Lesson.