Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Translate, Rotate, Scale > Example 7-20: Combining Transformations

Example 7-20: Combining Transformations

When translate() and rotate() are combined, the order in which they appear affects the result. The following example is identical to Example 7-19: Rotation, except that translate() and rotate() are reversed. The shape now rotates around the upper-left corner of the display window, with the distance from the corner set by translate():

image with no caption
float angle = 0.0;

void setup() {
  size(120, 120);
  smooth();
}

void draw() {
  rotate(angle);
  translate(mouseX, mouseY);
  rect(-15, -15, 30, 30);
  angle += 0.1;
}

Note

You can also use the rectMode(), ellipseMode(), imageMode(), and shapeMode() functions to make it easier to draw shapes from their center.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint