Skip to main content

Lesson 1: Draw a Square

The move command 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.

Art Canvas Playground with a black square drawn on it. The VR robot is positioned in the center of the Playground, at the bottom left corner of the square.

 

  • The new text project template begins with a drive_for command. Remove that command, and drag in, type or copy the move command to begin your project.
def main():
	pen.move(DOWN)

 

For Your Information

The move command can be used to pick up and put down the Pen tool on a VR Robot.

VEXcode VR Python Pen command written twice to show the different parameters. The first line reads pen dot move with Down in parentheses. The second line reads pen dot move with Up in parentheses.
  • Drag in, type or copy the drive_for command and place it below the move command. Set the parameters of the drive_for command to drive forward 600 millimeters (mm).
def main():
	pen.move(DOWN)
	drivetrain.drive_for(FORWARD, 600, MM)

Your project should appear as above.

  • Next, drag in, type or copy the turn_for command and place it after the drive_for command. Set the parameters of the turn_for command to turn right 90 degrees.
def main():
	pen.move(DOWN)
	drivetrain.drive_for(FORWARD, 600, MM)
	drivetrain.turn_for(RIGHT, 90, DEGREES)

Your project should appear as above.

  • To draw the second side of the square, copy the drive_for and turn_for command. To copy, highlight the drive_for and turn_for commands. Right click or long press on the commands, and Select "Copy". Then right click or long press under the commands and select "Paste."
    The project from this Lesson is shown to the left, with the context menu open. The options read, Add Line Comment, Remove Line Comment, Toggle Line Comment, Cut, Copy, Paste. The Copy option is highlighted with a red box.
  • Additional drive_for and turn_for commands are now added to the stack. This creates the first two sides of the square.
    Project to drive the first two sides of the square reading: Line one def main open parenthesis close parenthesis colon Line two is indented and reads pen dot move open parenthesis down close parenthesis Line three reads drivetrain dot drive underscore for open parenthesis forward comma six hundred comma mm close parenthesis Line four reads drivetrain dot turn underscore for open parenthesis right comma ninety comma degrees close parenthesis Line five reads drivetrain dot drive underscore for open parenthesis forward comma six hundred comma mm close parenthesis Line six reads drivetrain dot turn underscore for open parenthesis right, 90, degrees close parenthesis.
  • To draw the last two sides of the square, copy the drive_for and turn_for commands. Highlight all four commands, then right click or long press, and Select "Copy." Right click or long press under the highlighted commands and select "Paste."
    The project from above is shown on the left, with the last four drivetrain commands highlighted. On the right is the open context menu, with the copy option highlighted with a red box.
  • The commands will then be duplicated and create the last two sides of the square.
    The project to draw a square as described above, with the last two lines of code added. They read drivetrain dot drive underscore for open parenthesis forward comma 600 comma mm and drivetrain dot turn underscore for open parenthesis right comma ninety, degrees close parenthesis.
  • Select the “Open Playground” button to open the Playground Window, if it is not already open.
    VEXcode VR toolbar with the Open Playground button at the top right highlighted. Open Playground is the second option, between select playground and start.
  • Be sure the Art Canvas Playground opens.
    Art canvas playground in VEXcode VR.
  • Select the “Start” button to test the project.
    VEXcode VR toolbar with the start button in the upper right corer highlighted. The start button is the third option form the left, after select playground and open playground.
  • 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.Art Canvas Playground with a black square drawn on it. The VR robot is positioned in the center of the Playground, at the bottom left corner of the square.
  • Select the “Reset” button to reset the Playground and move the VR Robot back to the starting position. VEXcode VR Art Canvas Playground with the robot at the center of the Playground, and a black square drawn. At the bottom left corner of the Playground Window is the reset button, which has an arrow pointing in a counterclockwise circular direction. This button is highlighted with a red box.

For Your Information

The set_pen_color command can be used to change the colors of the pen. The pen can be set to one of four colors: Black, Blue, Green, or Red.

 set pen color comment with parameters open showing the four color options.

Select the Next button to continue with the rest of this Lesson.