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

Chapter 10    Projects     323




                            case 2: //go down
                              if((totalHeight - randomDistance) > 0)
                                {
                                down(randomDistance);
                                totalHeight -= randomDistance;
                                }
                              break;

                            case 3: //go left
                              if((totalWidth - randomDistance) > 0)
                                {
                                left(randomDistance);
                                totalWidth -= randomDistance;
                                }
                              break;

                            case 4: //go right
                              if((totalWidth + randomDistance) < CANVASWIDTH)
                                {
                                right(randomDistance);
                                totalWidth += randomDistance;
                                }
                              break;
                            case 5: //go upRight
                              if(((totalWidth + randomDistance) < CANVASWIDTH) && ((totalHeight
                     + randomDistance) < CANVASHEIGHT))
                                {
                                upRight(randomDistance);
                                totalWidth += randomDistance;
                                totalHeight += randomDistance;
                                }
                              break;

                            case 6: //go upLeft
                              if(((totalWidth - randomDistance) > 0) && ((totalHeight +
                     randomDistance) < CANVASHEIGHT))
                                {
                                upLeft(randomDistance);
                                totalWidth -= randomDistance;
                                totalHeight += randomDistance;
                                }
                              break;
   341   342   343   344   345   346   347   348   349   350   351