Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMPUTER GRAPHICS Prepared by S.MAHALAKSHMI Asst. Prof(Sr) / SCSE VIT University.

Similar presentations


Presentation on theme: "COMPUTER GRAPHICS Prepared by S.MAHALAKSHMI Asst. Prof(Sr) / SCSE VIT University."— Presentation transcript:

1 COMPUTER GRAPHICS Prepared by S.MAHALAKSHMI Asst. Prof(Sr) / SCSE VIT University

2 Programming in SRGP

3 INTRO Advantages of Raster Displays Advantages of Raster Displays Fill areas with uniform color or repeated pattern with 2 or more colors. 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. Stores images which allows manipulation @ fine level : individual pixels can be read or written and arbitrary portions can be copied or moved.

4 SRGP(Simple Raster Graphics Package) Device independent Graphics package Device independent Graphics package Similar to Macintosh QuickDraw Raster package and Xlib package of Windows system Similar to Macintosh QuickDraw Raster package and Xlib package of Windows system

5 SRGP (Continued..) Drawing with SRGP Drawing with SRGP Basic Interaction Handling Basic Interaction Handling Raster Graphics Features Raster Graphics Features Limitations of SRGP Limitations of SRGP

6 1.Drawing with SRGP  1.1 Specification of Graphics Primitives  1.2 Attributes  1.3 Filled primitives and attributes  1.4 Saving and Restoring Attributes  1.5Text

7 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 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 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 (0,0)--> bottom left of the screen. +ve x increases towards right and +ve Y increases towards top

8 1.1 continued... SRGP supports basic collections of primitives SRGP supports basic collections of primitives a) Lines b) Polygons c) Circles d) Ellipses e) Text

9 Lines and Poly lines Void SRGP_lineCoord(int x1, int y1, int x2, int y2); Void SRGP_lineCoord(int x1, int y1, int x2, int y2); eg: eg: SRGP_lineCoord(0,0,100,300) SRGP_lineCoord(0,0,100,300) (or) (or) void SRGP_line(point pt1,point pt2); void SRGP_line(point pt1,point pt2); Point is a defined type, a record holding 2 integer x,y values Point is a defined type, a record holding 2 integer x,y values typedef struct typedef struct {int x,y; {int x,y; }point; }point;

10 Lines and Poly lines A sequence of lines connecting successive vertices is called polyline. A sequence of lines connecting successive vertices is called polyline. There are 2 polyline procedures. These take array as parameter. There are 2 polyline procedures. These take array as parameter. Void SRGP_polyLineCoord (int vertexcount, Void SRGP_polyLineCoord (int vertexcount, int*xArray, int*yArray); int*xArray, int*yArray); Void SRGP_polyLine(int vertexcount, point Void SRGP_polyLine(int vertexcount, point *vertices); *vertices);

11 continued.. /* plot the axes*/ /* plot the axes*/ SRGP_lineCoord(175,200,320,200); SRGP_lineCoord(175,200,320,200); SRGP_lineCoord(200,140,200,280); SRGP_lineCoord(200,140,200,280); /*plot the data*/ /*plot the data*/ SRGP_polyLineCoord (12,months, balanceOfTrade); SRGP_polyLineCoord (12,months, balanceOfTrade); SRGP_polyLine(7, bowtieArray); SRGP_polyLine(7, bowtieArray);

12 contiued.. Markers and polymarkers Markers and polymarkers It is convenient to place markers(dots,asterisks or circles) at the data points on graphs. It is convenient to place markers(dots,asterisks or circles) at the data points on graphs. Void SRGP_markerCoord(intx,inty); Void SRGP_markerCoord(intx,inty); Void SRGP_marker(point pt) Void SRGP_marker(point pt) Void SRGP_polyMarkerCoord (int vertexcount, int*xArray, int*yArray); Void SRGP_polyMarkerCoord (int vertexcount, int*xArray, int*yArray); Void SRGP_polyMarker(int vertexcount, point *vertices); Void SRGP_polyMarker(int vertexcount, point *vertices);

13 continued... Polygons and Rectangles 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 --> 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 vertexCount, point *vertices) void SRGP_polygon(int vertexCount, point *vertices) Now bowtieArray is of only 6 points it automatically closes the figure. Now bowtieArray is of only 6 points it automatically closes the figure.

14 Continued Any rectangle can be specified as a polygon having 4 vertices. Any rectangle can be specified as a polygon having 4 vertices. Uses only 2 primitives(lower left & upper right) Uses only 2 primitives(lower left & upper right) Void SRGP_rectangleCoord(int leftx, intbottomY,int rightX, int topY); Void SRGP_rectangleCoord(int leftx, intbottomY,int rightX, int topY); Void SRGP_rectanglePt(point bottomLeft, point topRight); Void SRGP_rectanglePt(point bottomLeft, point topRight); void SRGP_rectangle(rectangle rect); void SRGP_rectangle(rectangle rect); typedef struct{ point bottomLeft,topRight; typedef struct{ point bottomLeft,topRight; }rectangle; }rectangle;

15 Rectangles continued.. Point SRGP_defPoint(intx,int y); Point SRGP_defPoint(intx,int y); Rectangle SRGP_defRectangle(int leftX,int bottomY,int rightX, int topY); Rectangle SRGP_defRectangle(int leftX,int bottomY,int rightX, int topY);

16 Circles and Ellipses Circles are Special types of ellipses. Circles are Special types of ellipses. The term ellipse arc used for circular,elliptical,closed or partial arcs. 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) It is easy to specify arcs via upright rectangles (bounding boxes or extents) Void SRGP_ellipseArc(rectangle extentRect, float startAngle, float endAngle); Void SRGP_ellipseArc(rectangle extentRect, float startAngle, float endAngle);

17 Circles and ellipses  Relationship between rectangular and circular angle is  Rectangular angle=arctan(tan(circularangle).width/height)+  adjust  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∏

18 1.2 Attributes The specification of a primitive can be controlled by specification of its attributes The specification of a primitive can be controlled by specification of its attributes Line style and Line width Line style and Line width Color Color Penstyle Penstyle Attributes are global state variables that retain their values until they are changed explicitly Attributes are global state variables that retain their values until they are changed explicitly  Void SRGP_setLineStyle(lineStyle CONTINUOUS / DASHED /DOTTED/….);  Void SRGP_setLineWidth(int widthValue);

19 Attributes.. Each attribute has a default.. Eg., default for linestyle is CONTINUOUS that for line width is 1. 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. Line style can be represented as bit mask and it is scan converted by SRGP. For eg.. Contimuous all 1’s For eg.. Contimuous all 1’s DASHED 1111001111001111….. DASHED 1111001111001111…..

20 Attributes for marker primitive  Void SRGP_setMarkerSize(int sizeValue);  Void SRGP_setMarkerStyle(markerStyle MARKER_CIRCLE / MARKER_SQUARE/…);  The default is circle style  COLOR  bilevel system the color value is 0 and 1.  -1 black, 0 white for black on white devices  1 green, 0 black for green on black devices

21 Attribute-color The integer color attribute is an index to SRGP;s color table. Each entry defines color or gray scale value. The integer color attribute is an index to SRGP;s color table. Each entry defines color or gray scale value. There are 2d entries and d is the depth of frame buffer There are 2d entries and d is the depth of frame buffer 2 methods to specify colors 2 methods to specify colors 1. use integers 0 and 1 directly 1. use integers 0 and 1 directly 2. use color names supported by SRGP 2. use color names supported by SRGP We can also select color by calling We can also select color by calling Void SRGP_setColor(int colorIndex) Void SRGP_setColor(int colorIndex)

22 1.3 Filled Primitives and Their Attributes  Primitives can be drawn in 2 ways  Outline  Filled  SRGP’s filled versions of area defining primitives draw the interior pixels with no outline

23 Code for creating filled Primitives

24 Output for the previous code

25 Odd Parity rule  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 1. Choose a test point 2. Choose a ray that starts at the test point extends indefinitely in any direction and does not pass any vertices. 3. If this ray intersect the polygon outline an odd no of times ->interior 4. else exterior

26 Fill style and fill pattern for areas  4 ways  Void SRGP_setFillStyle(drawStyle SOLID/ BITMAP_PATTERN_OPAQUE / BITMAP_PATTERN_TRANSPARENT/ PIXMAP_PATTERN);  There is no distinction in opaque & transparent in pix map patterns

27 Application screen background  Background color  0 bits in bitmap patterns used in opaque mode.  Suppose user expects the uniform screen background pattern then the application should set up the background in desired pattern. Default  solid color 0  Erase primitive  is done by redraw them in the application background pattern.(Quick & dirty technique). This yield damaged image if primitives overlaps.  Damage repair is done by respecifying primitives in application data

28 1.4 Saving and restoring Attributes  Attributes can be saved for later restoration.  It does not affect the global attribute state.  SRGP does this attribute group via  void SRGP_inquireAttributes(attributeGroup * group);  void SRGP_setAttributes(attributeGroup * group);

29 1.5 Text  Specifying and implementing text drawing is always complex in graphics package. (style,font,bold,italic,width,spacing)  In SRGP text is horizontally aligned and character widths vary, but space b/w characters is constant.  High quality documents need specialized packages that offer more ctrl.  Eg. Post script  Text in SRGP is generated by  void SRGP_text(point origin, char *text);

30 1.5 Text continued..  The location of text is ctrlled by specification of its origin/Anchor point  Text primitive’s appearance is determined by only 2 attributes (color and font)  void SRGP_setFont(int valueIndex)  Each character in the font is defined as rectangular bitmap.  SRGP draws a character by filling a rectangle using character bitmap as pattern in transparent mode.

31 Formatting text  Void SRGP_inquireTextExtent(Char*text, int *width, int * height, int *descent);

32 Code for formatting text

33 2.Basic Interaction Handling  Topics to be discussed  Human Factors  Logical Input Devices  Sampling versus Event driven Processing  Sample mode  Event mode  Pick correlation for Interaction Handling  Setting Device Measure and Attributes

34 2.1 Human Factors  Interaction style(look and feel)  Ease of learning and use  Guidelines for user computer interaction 1. Provide simple and Consistent interaction sequence 2. Do not overload the user with too many different options 3. Show the available options clearly 4. Give appropriate feedback 5. Allow the user ti recover gracefully from mistakes.

35 2.2 Logical Input Devices  Device types in SRGP  2 logical input devices supported by SRGP  a) Locator  b) Keyboard SRGP maps the logical devices to physical devices(eg locator to mouse, joystick, tablet….) SRGP maps the logical devices to physical devices(eg locator to mouse, joystick, tablet….) SRGP provides only one logical locator and one keyboard device SRGP provides only one logical locator and one keyboard device

36 2.3 Sampling versus Event driven Processing

37


Download ppt "COMPUTER GRAPHICS Prepared by S.MAHALAKSHMI Asst. Prof(Sr) / SCSE VIT University."

Similar presentations


Ads by Google