Page 164 - Hacking Roomba
P. 164

Chapter 7 — Making RoombaView                 145












                             FIGURE 7-5: On-screen
                             virtual Roomba



                               Listing 7-5: Drawing Virtual Roomba

                               void drawRoombaStatus(float posx, float posy, float angle) {
                                 pushMatrix();
                                 translate((int)posx,(int)posy);
                                 rotate(angle);
                                 smooth();
                                 textFont(fontA, 10);
                                 textAlign(CENTER);
                                 fill(cBack); strokeWeight(2); stroke(100);
                                 ellipseMode(CENTER_RADIUS);
                                 ellipse(0,0, 50,50);
                                 fill(0); stroke(cTxt); strokeWeight(4);
                                 text(“cliff”, 0, -30);
                                 if( roombacomm.cliffLeft()       ) stroke(cOn);
                                 else stroke(cOff);
                                 line(-35,-25, -40,-15);
                                 if( roombacomm.cliffRight()      ) stroke(cOn);
                                 else stroke(cOff);
                                 line( 35,-25,  40,-15);

                                 if( roombacomm.cliffFrontLeft()  ) stroke(cOn);
                                 else stroke(cOff);
                                 line(-30,-30, -20,-30);
                                 if( roombacomm.cliffFrontRight() ) stroke(cOn);
                                 else stroke(cOff);
                                 line( 30,-30,  20,-30);
                                 stroke(cTxt);  strokeWeight(7);
                                 text(“bump”, 0,-17);
                                 if( roombacomm.bumpLeft()  ) stroke(cOn);
                                 else stroke(cOff);
                                 line(-25,-20, -20,-20);
                                 if( roombacomm.bumpRight() ) stroke(cOn);
                                 else stroke(cOff);
                                                                                              Continued
   159   160   161   162   163   164   165   166   167   168   169