COMPUTER GRAPHICS Prepared by S MAHALAKSHMI Asst ProfSr
COMPUTER GRAPHICS Prepared by S. MAHALAKSHMI Asst. Prof(Sr) / SCSE VIT University
Programming in SRGP
INTRO Advantages of Raster Displays Fill areas with uniform color or repeated pattern with 2 or more colors. Stores images which allows manipulation @ fine level : individual pixels can be read or written and arbitrary portions can be copied or moved.
SRGP(Simple Raster Graphics Package) Device independent Graphics package Similar to Macintosh Quick. Draw Raster package and Xlib package of Windows system
SRGP (Continued. . ) Drawing with SRGP Basic Interaction Handling Raster Graphics Features Limitations of SRGP
1. Drawing with SRGP u 1. 1 Specification of Graphics Primitives u 1. 2 Attributes u 1. 3 Filled primitives and attributes u 1. 4 Saving and Restoring Attributes u 1. 5 Text
1. 1 Specification of Graphics Primitives Drawing in integer graphics package such as SRGP is like plotting graphs on graph paper with very fine grid Grid varies from 80 -120 points per inch to 300 or more on high resolution displays (0, 0)--> bottom left of the screen. +ve x increases towards right and +ve Y increases towards top
1. 1 continued. . . SRGP supports basic collections of primitives a)Lines b)Polygons c) Circles d)Ellipses e)Text
Lines and Poly lines Void SRGP_line. Coord(int x 1, int y 1, int x 2, int y 2); eg: SRGP_line. Coord(0, 0, 100, 300) (or) void SRGP_line(point pt 1, point pt 2); Point is a defined type, a record holding 2 integer x, y values typedef struct {int x, y; }point;
Lines and Poly lines A sequence of lines connecting successive vertices is called polyline. There are 2 polyline procedures. These take array as parameter. Void SRGP_poly. Line. Coord (int vertexcount, int*x. Array, int*y. Array); Void SRGP_poly. Line(int vertexcount, point *vertices);
continued. . /* plot the axes*/ SRGP_line. Coord(175, 200, 320, 200); SRGP_line. Coord(200, 140, 200, 280); /*plot the data*/ SRGP_poly. Line. Coord (12 , months, balance. Of. Trade); SRGP_poly. Line(7, bowtie. Array);
contiued. . Markers and polymarkers It is convenient to place markers(dots, asterisks or circles) at the data points on graphs. Void SRGP_marker. Coord(intx, inty); Void SRGP_marker(point pt) Void SRGP_poly. Marker. Coord (int vertexcount, int*x. Array, int*y. Array); Void SRGP_poly. Marker(int vertexcount, point *vertices);
continued. . . Polygons and Rectangles --> To draw an outline polygon, we can either specify a polyline on itself by making the first and last vertices identical (or) we can use void SRGP_polygon(int vertex. Count, point *vertices) Now bowtie. Array is of only 6 points it automatically closes the figure.
Continued Any rectangle can be specified as a polygon having 4 vertices. Uses only 2 primitives(lower left & upper right) Void SRGP_rectangle. Coord(int leftx, intbottom. Y, int right. X, int top. Y); Void SRGP_rectangle. Pt(point bottom. Left, point top. Right); void SRGP_rectangle(rectangle rect); typedef struct{ point bottom. Left, top. Right; }rectangle;
Rectangles continued. . Point SRGP_def. Point(intx, int y); Rectangle SRGP_def. Rectangle(int left. X, int bottom. Y, int right. X, int top. Y);
Circles and Ellipses • • Circles are Special types of ellipses. The term ellipse arc used for circular, elliptical, closed or partial arcs. It is easy to specify arcs via upright rectangles (bounding boxes or extents) Void SRGP_ellipse. Arc(rectangle extent. Rect, float start. Angle, float end. Angle);
Circles and ellipses u Relationship between rectangular and circular angle is u Rectangular angle=arctan(circularangle). width/height)+ u adjust u u where the angles are in radians and adjust = 0, for 0<= circular angle<∏/2 adjust = ∏/2 , for ∏/2 <=circular angle < 3∏/2 adjust = 2∏, for 3∏/2<= circular angle < 2∏
1. 2 Attributes • • • Ø Ø The specification of a primitive can be controlled by specification of its attributes Line style and Line width Color Penstyle Attributes are global state variables that retain their values until they are changed explicitly Void SRGP_set. Line. Style(line. Style CONTINUOUS / DASHED /DOTTED/…. ); Void SRGP_set. Line. Width(int width. Value);
Attributes. . • • Each attribute has a default. . Eg. , default for linestyle is CONTINUOUS that for line width is 1. Line style can be represented as bit mask and it is scan converted by SRGP. For eg. . Contimuous all 1’s DASHED 1111001111…. .
Attributes for marker primitive Void SRGP_set. Marker. Size(int size. Value); u Void SRGP_set. Marker. Style(marker. Style MARKER_CIRCLE / MARKER_SQUARE/…); u The default is circle style u COLOR u bilevel system the color value is 0 and 1. u u u -1 black, 0 white for black on white devices 1 green, 0 black for green on black devices
Attribute-color • • The integer color attribute is an index to SRGP; s color table. Each entry defines color or gray scale value. There are 2 d entries and d is the depth of frame buffer 2 methods to specify colors 1. use integers 0 and 1 directly 2. use color names supported by SRGP We can also select color by calling Void SRGP_set. Color(int color. Index)
1. 3 Filled Primitives and Their Attributes Primitives can be drawn in 2 ways u Outline u Filled u SRGP’s filled versions of area defining primitives draw the interior pixels with no outline u
Code for creating filled Primitives
Output for the previous code
Odd Parity rule u u u 1. 2. 3. 4. u We need a rule for specifying which regions are interior, and thus should be filled and which is exterior This can done in SRGP through odd parity rule. To check whether the region lies inside/ outside Choose a test point Choose a ray that starts at the test point extends indefinitely in any direction and does not pass any vertices. If this ray intersect the polygon outline an odd no of times ->interior else exterior
Fill style and fill pattern for areas u 4 ways u Void SRGP_set. Fill. Style(draw. Style SOLID/ BITMAP_PATTERN_OPAQUE / BITMAP_PATTERN_TRANSPARENT/ PIXMAP_PATTERN); u There is no distinction in opaque & transparent in pix map patterns
Application screen background Background color 0 bits in bitmap patterns used in opaque mode. u Suppose user expects the uniform screen background pattern the application should set up the background in desired pattern. Default solid color 0 u Erase primitive is done by redraw them in the application background pattern. (Quick & dirty technique). This yield damaged image if primitives overlaps. u Damage repair is done by respecifying primitives in application data u
1. 4 Saving and restoring Attributes can be saved for later restoration. u It does not affect the global attribute state. u SRGP does this attribute group via u u void SRGP_inquire. Attributes(attribute. Group * group); u void SRGP_set. Attributes(attribute. Group * group);
1. 5 Text Specifying and implementing text drawing is always complex in graphics package. (style, font, bold, italic, width, spacing) u In SRGP text is horizontally aligned and character widths vary, but space b/w characters is constant. u High quality documents need specialized packages that offer more ctrl. u Eg. Post script u Text in SRGP is generated by u void SRGP_text(point origin, char *text); u
1. 5 Text continued. . The location of text is ctrlled by specification of its origin/Anchor point u Text primitive’s appearance is determined by only 2 attributes (color and font) u u void SRGP_set. Font(int value. Index) Each character in the font is defined as rectangular bitmap. u SRGP draws a character by filling a rectangle using character bitmap as pattern in transparent mode. u
Formatting text u Void SRGP_inquire. Text. Extent(Char*text, int *width, int * height, int *descent);
Code formatting text
2. Basic Interaction Handling Topics to be discussed u Human Factors u Logical Input Devices u Sampling versus Event driven Processing u Sample mode u Event mode u Pick correlation for Interaction Handling u Setting Device Measure and Attributes u
2. 1 Human Factors u Interaction style(look and feel) Ease of learning and use u Guidelines for user computer interaction 1. Provide simple and Consistent interaction sequence Do not overload the user with too many different options Show the available options clearly Give appropriate feedback Allow the user ti recover gracefully from mistakes. u 2. 3. 4. 5.
2. 2 Logical Input Devices Device types in SRGP u 2 logical input devices supported by SRGP u a) Locator u b) Keyboard • SRGP maps the logical devices to physical devices(eg locator to mouse, joystick, tablet…. ) • SRGP provides only one logical locator and one keyboard device u
2. 3 Sampling versus Event driven Processing
- Slides: 37