Page 193 - CodePilot V5.0 C8
P. 193

The explanation of the code is as follows:
                     The program starts when the when started block is triggered.

                     The robot turns right by 90°, moves forward 600 mm, turns left by 90° and moves forward
                    another 600 mm to reach the centre.
                     The pen is set to green and moved down to start drawing.

                     A repeat loop runs 6 times to draw each side of the hexagon. In each iteration, the robot drives
                    forward 400 mm and turns right by 60° to form the hexagon.


                  Program 4 Draw a star on the Grid Map playground.

                 The task is to make the robot draw a five-pointed star shape on the Grid Map playground using
                 the Drawing blocks.

                 The code and output of the given task are as follows:



                  when started


                   turn  right  for  90  degrees

                   drive  forward  for  400  mm

                   turn  left  for  90  degrees

                   drive  forward  for 1000  mm

                  move pen  down

                  set pen to width medium

                   repeat  5

                    drive  forward  for  1200  mm

                    turn  right  for  144  degrees





                  The explanation of the code is as follows:

                     The program starts when the when started block is triggered.
                     The robot turns right by 90°, moves forward 400 mm, turns left 90° and moves forward
                    1000 mm to position itself near the centre.

                     The pen is moved down and set to medium width.
                     The robot turns right by 90° to align for drawing the star.

                     A repeat loop runs 5 times to draw each side of the star:
                    •  The robot drives forward 1200 mm and turns right by 144° after each side to form the star.




                                                                                                                  191
                                                                                 VEXcode VR: Drive, Sense and Create
   188   189   190   191   192   193   194   195   196   197   198