Pages

Wednesday, March 23, 2011

For greater understanding of pushMatrix() and popMatrix()


http://www.openprocessing.org/visuals/?visualID=10991
   
  I have submitted this sketch because writing it solidified my understanding the pushMatrix()
  and popMatrix() functions.  It also shows the usefulness of nesting push-pop pairs within
  one another.  (At the risk of violating good Java style I have indented code within push-pop
  pairs even though these are not formal code blocks.  This is for the sake of clarity.)
   
  The sketch creates four shapes (rectangles), and also manipulates these shapes as a unit, which
  I will call a figure.
   
  Transformations translate() and rotate() stack so that when you call one, all subsequent items
  that are drawn will appear with those transformations applied.  pushMatrix() and popMatrix()
  are used to put a new set of transformation on the stack, and then remove transformations from
  the stack so that they are not applied to items drawn later.
   
  Using pushMatrix() and popMatrix() is the best way to cleanly position many items on the same
  screen.
 

No comments:

Post a Comment