Page 347 - Making things move_ DIY mechanisms for inventors, hobbyists, and artists
P. 347

324        Making Things Move





                            case 7: //go downRight
                              if(((totalWidth + randomDistance) < CANVASWIDTH) && ((totalHeight
                     - randomDistance) > 0))
                                {
                                downRight(randomDistance);
                                totalWidth += randomDistance;
                                totalHeight -= randomDistance;
                                }
                              break;
                            case 8: //go downLeft
                              if(((totalWidth - randomDistance) > 0) && ((totalHeight -
                     randomDistance) > 0))
                                {
                                downLeft(randomDistance);
                                totalWidth -= randomDistance;
                                totalHeight -= randomDistance;
                                }
                              break;

                            default:  //just in case
                              left(0);

                           } //end switch
                       } //end else

                     } //end loop()
                     /*
                     Here are the directional functions.  Loop size = distance.
                     Positive step numbers are clockwise, negative counterclockwise
                     */

                     void up(int distance)
                     {
                       for(i=0;i< distance; i++) {
                         right_motor.step(1);
                         left_motor.step(-1);
                         }
                     }

                     void down(int distance)
                     {
                       for(i=0;i< distance; i++) {
                         right_motor.step(-1);
                         left_motor.step(1);
                         }
                     }
   342   343   344   345   346   347   348   349   350   351   352