Physics 21 Reading List #2
1. More information on the g2 library
First, you must open a graphical device, which could be an X11 window on the screen (X11 is the standard UNIX graphical interface), or just a figure file (either EPS, JPEG, or PNG). While opening devices other than EPS, you must specify their size, which will be measured in pixels.
For the last two, the variables 'g2_gd_jpeg' and 'g2_gd_png' should be typed in literally.
Note that postscript files with bitmapped images tend to be very bulky. It's much better to use JPEG; if an EPS is needed (for instance, for easy inclusion in LaTeX documents), you can convert JPEG to EPS with jpeg2ps (installed in the lab).
Now that you have a handle (the 'dev' that is returned by the g2_open_* functions), you can choose among many drawing options.
As for color management, g2 is a palette-based system, which means that you get to work with a limited number of colors, which you need to define beforehand. Each color that you define is identified by a unique number that you can use for all subsequent operations. You define colors with
where red, green, and blue are values between 0.0 and 1.0 that describe the quantity of each of these primary colors in the color that you are defining. (See below for a reading about this additive color model.) Once you have your colors, you can use a list of colors to define a bitmapped image that you will plot with
g2_image(dev,x,y,x_size,y_size,colid_array)
There are other things you can do too. For example, you can use the g2 line plotting functions, which are all listed and briefly described at their manual page ("relative" functions employ a LOGO-like model). You can modify the lines being plotted with g2_set_line_width(dev,width) and g2_set_dash(dev,N,dashes) with N the number of dash components and dashes their lengths. If you want to draw text: g2_string(dev,x,y,text_string) will draw a string of text at position (x,y), using the font size chosen (in pixels) with g2_set_font_size(dev,size). You can also set the window background color with g2_set_background(dev,colid), and set the pen with g2_pen(dev,colid) (which affects all subsequent g2_plot, g2_line, etc commands).
For the X11 device only,
Want more? g2_clear(dev) will clear a device; g2_flush(dev) will immediately execute all pending graphical operations (which may be queued to minimize execution time). When you're done drawing, don't forget to close your device with g2_close(dev).
2. Colors
We were saying just above that in g2 you define colors by setting their content of red, green, and blue. This model mirrors the way that colors are displayed on CRT and LCD monitors (and indeed, on TVs). The internet offers a wealth of fascinating information about the different ways that color (a subjective experience dependent on our physiology) can be described in mathematics and used in technology. See one or more of the following:
- The beginning of Section 5 (especially Section 5.3) of Grokking the Gimp has a good explanation of RGB and HSV color schemes.
- the RGB and CMYK color models at Mike's Sketchpad.
- color models at Wikipedia;
- Color Conversion Algorithms from Nan Schaller.
- a more extensive tutorial on the use of color in scientific illustration (disregard the exercises).
First, you must open a graphical device, which could be an X11 window on the screen (X11 is the standard UNIX graphical interface), or just a figure file (either EPS, JPEG, or PNG). While opening devices other than EPS, you must specify their size, which will be measured in pixels.
const int dev = g2_open_X11(width_in_pixels,height_in_pixels)
const int dev = g2_open_EPSF(filename)
const int dev = g2_open_gd(filename,width_in_pixels,height_in_pixels,g2_gd_jpeg)
const int dev = g2_open_gd(filename,width_in_pixels,height_in_pixels,g2_gd_png)
For the last two, the variables 'g2_gd_jpeg' and 'g2_gd_png' should be typed in literally.
Note that postscript files with bitmapped images tend to be very bulky. It's much better to use JPEG; if an EPS is needed (for instance, for easy inclusion in LaTeX documents), you can convert JPEG to EPS with jpeg2ps (installed in the lab).
Now that you have a handle (the 'dev' that is returned by the g2_open_* functions), you can choose among many drawing options.
As for color management, g2 is a palette-based system, which means that you get to work with a limited number of colors, which you need to define beforehand. Each color that you define is identified by a unique number that you can use for all subsequent operations. You define colors with
const int colid = g2_ink(dev,red,green,blue)
where red, green, and blue are values between 0.0 and 1.0 that describe the quantity of each of these primary colors in the color that you are defining. (See below for a reading about this additive color model.) Once you have your colors, you can use a list of colors to define a bitmapped image that you will plot with
g2_image(dev,x,y,x_size,y_size,colid_array)
There are other things you can do too. For example, you can use the g2 line plotting functions, which are all listed and briefly described at their manual page ("relative" functions employ a LOGO-like model). You can modify the lines being plotted with g2_set_line_width(dev,width) and g2_set_dash(dev,N,dashes) with N the number of dash components and dashes their lengths. If you want to draw text: g2_string(dev,x,y,text_string) will draw a string of text at position (x,y), using the font size chosen (in pixels) with g2_set_font_size(dev,size). You can also set the window background color with g2_set_background(dev,colid), and set the pen with g2_pen(dev,colid) (which affects all subsequent g2_plot, g2_line, etc commands).
For the X11 device only,
g2_query_pointer(const int dev,double& x,double& y,unsigned int& button)will fill x and y with the position of the mouse pointer, and will fill 'button' with the state of the mouse button (zero for no button, 256 for the left button, 512 for the middle, and 1024 for the right).
Want more? g2_clear(dev) will clear a device; g2_flush(dev) will immediately execute all pending graphical operations (which may be queued to minimize execution time). When you're done drawing, don't forget to close your device with g2_close(dev).
2. Colors
We were saying just above that in g2 you define colors by setting their content of red, green, and blue. This model mirrors the way that colors are displayed on CRT and LCD monitors (and indeed, on TVs). The internet offers a wealth of fascinating information about the different ways that color (a subjective experience dependent on our physiology) can be described in mathematics and used in technology. See one or more of the following:
- The beginning of Section 5 (especially Section 5.3) of Grokking the Gimp has a good explanation of RGB and HSV color schemes.
- the RGB and CMYK color models at Mike's Sketchpad.
- color models at Wikipedia;
- Color Conversion Algorithms from Nan Schaller.
- a more extensive tutorial on the use of color in scientific illustration (disregard the exercises).

0 Comments:
Post a Comment
<< Home