Using the GEM display window
All graphics we are going to create reside in a separate window with the main patch window. It is often called the GEM display window. We use the gemwin
object to create the window. With different input messages, we can customize the properties of the display window.
Create a new Pd patch. Save it to your folder with name gem001.pd
. Clear the console window by choosing Edit | Clear console.
Put the object gemwin
onto your patch window, together with two messages and one toggle box. Connect all the messages and toggle boxes to the inlet of the gemwin
object:
The gemwin
object manages the graphics window. In this simple example, it receives two input messages:
create
: This message creates a new window for graphics displaydestroy
: This message closes the graphics window
Also note the toggle box that sends the number, either 0
or 1
to the gemwin
object. It is the rendering switch. Turning on the toggle will start graphics rendering within the window. Turning it off will stop it. When we work on animation by the end of this chapter, you will notice that the render switch will start/stop the playback of the animation.
Now switch to the Run mode. First, click on the create
message box and then on the toggle box. You will notice a square window appearing with black background. The default title of the window is GEM. And the default size of the window is 500 x 500 pixels, as shown in the following screenshot:
To close the window, switch off the render toggle and click on the destroy
message box. If you right-click or simultaneously press Ctrl and click on the gemwin
object and display the help menu, you can click on more items to check out the detailed operations of window management in GEM. We'll try out a few more options before we start drawing on the window.
To change the size of the window, we use the dimension message. The correct form is dimen 640 480
to change the size to 640 x 480 pixels. The first number is the width and the second one is the height. Both are measured in pixels. Also bear in mind that you have to first click on the dimen
message before clicking on the create
message and toggle:
To change the window title, we use the title
message. Note that the title text cannot have space characters. Otherwise, it just takes the first word. Again, you need to first click on the title
message before clicking on the create
message:
To change the background color, of course, we use the color
message. It is a bit tricky because we have to understand how we can specify color in GEM. You may have known that digital display color can be represented by the three primitive colors: red, green, and blue. All other colors are different combinations of the three primitive colors. GEM uses three numbers to denote the red (R), green (G), and blue (B) colors. The range of the numbers is from 0
to 1
. For example, a red color is 1
, 0
, and 0
; a yellow color is 1
, 1
, and 0
. The first number is red, the second is green, and the third is blue. You can also have decimal numbers for the color values, such as 0.5
, 0.1
, and 0.1
. The following example changes the window background to white, with the color combination as 1
, 1
, and 1
:
To resume the system default of the window properties, a reset
message will do: