Page 165 - Hacking Roomba
P. 165
146 Part II — Fun Things to Do
Listing 7-5 Continued
line( 25,-20, 20,-20);
stroke(cTxt);
text(“wheeldrop”, 0,3);
if( roombacomm.wheelDropLeft() ) stroke(cOn);
else stroke(cWhl);
line(-35,8, -20, 8);
if( roombacomm.wheelDropRight() ) stroke(cOn);
else stroke(cWhl);
line( 35,8, 20, 8);
if( roombacomm.wheelDropCenter()) stroke(cOn);
else stroke(cWhl);
line(-2,-8, 2,-8);
stroke(cTxt); strokeWeight(5);
text(“over”,0,18);
if( roombacomm.motorOvercurrentDriveLeft() ) stroke(cOn);
else stroke(cOff);
line(-30,16, -20, 16);
if( roombacomm.motorOvercurrentDriveRight() ) stroke(cOn);
else stroke(cOff);
line( 30,16, 20, 16);
stroke(cTxt); strokeWeight(7);
text(“dirt”,0,42);
if( roombacomm.dirtLeft()>0 )
stroke(40,40,roombacomm.dirtLeft());
else stroke(cOff);
line(-22,40,-18,40);
if( roombacomm.dirtRight()>0 )
stroke(40,40,roombacomm.dirtRight());
else stroke(cOff);
line( 22,40, 18,40);
popMatrix();
}
Drawing with Rotation and Translation
Normally drawing things at any arbitrary position and rotation would be very painful. Imagine
trying to draw the virtual Roomba at any arbitrary location: every line() command would
need to be modified. Processing includes a few tools to make it easier. One of these is the
transformation matrix, which can be used to contain a set of drawing commands that are to
undergo translation and rotation. This transformation matrix is saved and restored with the
pushMatrix() and popMatrix() commands. You can see them in Listing 7-5.