2/24/2024 0 Comments Red rectangle open in middleFor a simple example like the rectangle, you are correct. You may be thinking that picking up the coordinate system and moving it is a lot more trouble than just adding to coordinates. Later on in this tutorial, you will find out why those functions seem to have such strange names. However, when you start doing more sophisticated operations with the coordinate system, it's easier to use pushMatrix() and popMatrix() to save and restore the status rather than having to undo all your operations. Yes, you could have done a translate(-60, -80) to move the grid back to its original position. Finally, popMatrix() restores the coordinate system to the way it was before you did the translate. Remember, the things you draw don't move-the grid moves instead. ![]() The rect(20, 20, 40, 40) draws the rectangle at the same place it was originally. The translate(60, 80) moves the coordinate system 60 units right and 80 units down. pushMatrix() is a built-in function that saves the current position of the coordinate system. Let's look at the translation code in more detail. draw a translucent blue rectangle by translating the grid draw a translucent red rectangle by changing the coordinates Copy and paste this code into Processing and give it a try. Only the method used to move them has changed. ![]() The rectangles are translucent so that you can see that they are (visually) at the same place. Here is code that draws the rectangle in red by changing its coordinates, then draws it in blue by moving the grid. When you use transformations, the things you draw never change position the coordinate system does. Its upper left corner is still at (20,20). The important thing to notice in the preceding diagram is that, as far as the rectangle is concerned, it hasn't moved at all.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |