Computer Graphics Prepared By: Bahram Taheri Sept. 2006 Amirkabir University of Technology & Birmingham University.

Slides:



Advertisements
Similar presentations
 putpixel function plots a pixel at location (x, y) of specified color.  Declaration :- void putpixel(int x, int y, int color);
Advertisements

Chapter 4 Euclidean Vector Spaces
COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin.
DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphicsIntroduction Dr. Eng. Farag Elnagahy
Introduction to Computer Graphics
CAP4730: Computational Structures in Computer Graphics
1 Computer Graphics Week7 -2D Rotation. 3-Rotation A shape can be rotated about any of the three axes. A rotation about the z-axis will actually rotate.
Title of project: pendulum waves. Pendulums Waves Pendulums Waves.
Creating a MagicInfo Pro Screen Template
Interactive Input Methods & Graphical User Input
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
CGMB214: Introduction to Computer Graphics
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Transformation & Projection Feng Yu Proseminar Computer Graphics :
2D Transformation of Graphics
Computer Graphics Raster Devices Transformations Areg Sarkissian.
Computational Biology, Part E Basic Principles of Computer Graphics Robert F. Murphy Copyright  1996, 1999, 2000, All rights reserved.
Two Dimensional Viewing
Lecture 3 Transformations.
GRAPHICS AND MOUSE PROGRAMMING IN C. Turbo C has a good collection of graphics libraries. If you know the basics of C, you can easily learn graphics programming.
Geometric Transformations
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Introduction to computer vision Chapter 2: Image.
Acute angle An angle with a measure less than 90 degrees.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Vectors and the Geometry of Space 9. Three-Dimensional Coordinate Systems 9.1.
Text-Mode Programming Question #1 What are the three levels of access to the video display when writing characters on the screen in text mode?
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Chapter 11: Block References and Attributes. After completing this Chapter, you will be able to use the following features: Create and insert block references.
Digital Image Processing Lecture4: Fundamentals. Digital Image Representation An image can be defined as a two- dimensional function, f(x,y), where x.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 1 1.
Chapter 5 Working with Multiple Worksheets and Workbooks
Daniel A. Keim, Hans-Peter Kriegel Institute for Computer Science, University of Munich 3/23/ VisDB: Database exploration using Multidimensional.
Geometric Transformations
Lecture 3 Transformations. 2D Object Transformations The functions used for modifying the size, location, and orientation of objects or of the camera.
12/24/2015 A.Aruna/Assistant professor/IT/SNSCE 1.
Data Representation. What is data? Data is information that has been translated into a form that is more convenient to process As information take different.
2D Geometric Transformation Translation A translation is applied to an object by repositioning it along a straight-line path from one coordinate location.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
REVIEW. To graph ordered pairs (x,y), we need two number lines, one for each variable. The two number lines are drawn as shown below. The horizontal number.
CS552: Computer Graphics Lecture 6: Viewing in 2D.
VECTORS AND THE GEOMETRY OF SPACE 10. VECTORS AND THE GEOMETRY OF SPACE In this chapter, we introduce vectors and coordinate systems for three-dimensional.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
Coordinates and Design. What You Will Learn: To use ordered pairs to plot points on a Cartesian plane To draw designs on a Cartesian plane To identify.
1 Teaching Innovation - Entrepreneurial - Global The Centre for Technology enabled Teaching & Learning, N Y S S, India DTEL DTEL (Department for Technology.
Lecture 11 Text mode video
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Chun-Yuan Lin Coordinate Reference Frames 2016/6/22 1 CG.
Final Project Virtual Slot Machine. By: Bander Alrogi Khaled Al Nuaimi Mohammed Almajhad Metaib Al-Enzai Course Title: ECE 2552 Instructor: Dr Kepuska.
Computer Graphics Lecture 04 Point Taqdees A. Siddiqi
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Line and Character Attributes 2-D Transformation
Microprocessor and Assembly Language
WINDOWING AND CLIPPING
Ch2: Data Representation
WINDOWING AND CLIPPING
Graphics Systems Lecture-2
Multimedia System Image
Presentation transcript:

Computer Graphics Prepared By: Bahram Taheri Sept Amirkabir University of Technology & Birmingham University

Geometric Transformations 2D and 3D Transformations 2D and 3D Transformations Translation (Deals with position) Translation (Deals with position) Scaling (Deals with size) Scaling (Deals with size) Rotation (Deals with orientation) Rotation (Deals with orientation)

2D Transformation Translating Points in the (x, y) Plane Translating Points in the (x, y) Plane Moving point p(x,y) to p’(x’,y’) so that Moving point p(x,y) to p’(x’,y’) so that Consider the following column vectors:

Example of Translation Translate the following figure by T(3, -4) Translate the following figure by T(3, -4) A B C x y This can be simply shown as A’=A+T

Translation Translated Figure 5 3 A B C x 8

Scaling Points Can be Stretched or Shrunken into New Points along the x and y directions by the Following Multiplications: Points Can be Stretched or Shrunken into New Points along the x and y directions by the Following Multiplications:

Scaling Scaling is about the size as well as distance from the Origin Scaling is about the size as well as distance from the Origin If the Scaling Factors Are Smaller than 1 then the Figure will become Smaller as Well as Closer to the Origin If the Scaling Factors Are Smaller than 1 then the Figure will become Smaller as Well as Closer to the Origin If the Scaling Factor is Larger than One, then the Figure will become Larger and Further from the Origin. If the Scaling Factor is Larger than One, then the Figure will become Larger and Further from the Origin.

Scaling Let’s scale the following triangle by ½ in x direction and by 1/3 in y direction. Let’s scale the following triangle by ½ in x direction and by 1/3 in y direction A B C x y 3.5

Matrix Transformation of a Scaled Figure

Scaled Shape A B C x y

Some Points About Scaling Scaling Can be Performed around a Point Other than the Origin Scaling Can be Performed around a Point Other than the Origin In Differential Scaling, In Differential Scaling, In Uniform Scaling, In Uniform Scaling,

Study on origin of 2 methods of scaling Prepared By: Hadi Khayyamian Vala Namdarpour Mechanical Eng. 1 st Year Birmingham-AUT Feb. 2008

First method : Scaling with identical proportionality Here, x-axis coefficient ( s 1 ) & y-axis coefficient ( s 2 ) are the same. d1d1 d2d2 d3d3 a1a1 c1c1 b1b1 a1a1 c1c1 b1b1 a2a2 b2b2 c2c2 a2a2 b2b2 c2c2

And point via intersecting d 1 and d 2,when s 1 = s 2,is: origin (0, 0) point via intersecting d 3 and d 2,when s 1 = s 2,is: origin (0, 0) point via intersecting d 1 and d 3,when s 1 = s 2,is: origin (0, 0) So they have common origins

second method : differential scaling ( S 1 ≠ S 2 ) (x 2,y 2 ) (x 3,y 3 ) (x 1,y 1 )

In this case you can see that x 1 ≠ x 2 ≠ x 3 so their points are different. In this case you can see that x 1 ≠ x 2 ≠ x 3 so their points are different. So they have different origins

Rotation of A Figure A Figure Can Be Usually Rotated About a Point Through an Angle in a Specific Direction A Figure Can Be Usually Rotated About a Point Through an Angle in a Specific Direction The Mathematical Definition of Rotation is: The Mathematical Definition of Rotation is:

Rotation The Given Rotation Formulas Are About the Origin The Given Rotation Formulas Are About the Origin Rotation Can be About Any Arbitrary Point Rotation Can be About Any Arbitrary Point Counterclockwise Rotations Are Positive Counterclockwise Rotations Are Positive Clockwise Rotations Are Negative Clockwise Rotations Are Negative

Deriving the Rotation Equation

Homogeneous Coordinates and Matrix Representation of 2D Transformations The matrix representation for translation, scaling and rotation are: The matrix representation for translation, scaling and rotation are: P’ = T+P P’ = S*P P’ = R*P If we express the points in homogeneous coordinates, then we can treat all three transformations as multiplication. In homogeneous coordinates we represent a point by a triple (x,y,W) rather than a pair (x,y).

Homogeneous Coordinates Continued We say that two sets of triples (x,y,W) and (x’,y’,W’) are the same points, if and only if one set is a multiple of the other set. For example, (2,3,5) and (4,6,10) represent the same points. We say that two sets of triples (x,y,W) and (x’,y’,W’) are the same points, if and only if one set is a multiple of the other set. For example, (2,3,5) and (4,6,10) represent the same points. At least one of the homogeneous coordinates must be nonzero. At least one of the homogeneous coordinates must be nonzero. (0,0,0) is not allowed. (0,0,0) is not allowed. If W coordinate is nonzero, we can divide the other coordinates by W to obtain the Cartesian coordinates of the point: If W coordinate is nonzero, we can divide the other coordinates by W to obtain the Cartesian coordinates of the point: (x,y,W)  (x/W, y/W,1)  The Cartesian coordinates! Points with W=0 are called points at infinity. Points with W=0 are called points at infinity.

The Plane Represented by W=1 Each triple is usually used to show a point in 3-D space. However, here we use it to represent points in 2-D space. Each homogeneous point, by all its representations, creates a line in the xyW coordinates. Here, W=1 represents the Cartesian representation of the homogenized points: Each triple is usually used to show a point in 3-D space. However, here we use it to represent points in 2-D space. Each homogeneous point, by all its representations, creates a line in the xyW coordinates. Here, W=1 represents the Cartesian representation of the homogenized points: Y X W P W=1 Plane The line representing Homogenized points (x,y,W)

Translation in Homogenous Coordinates The new equation becomes: The new equation becomes: Where the translation matrix is:

Translation + Translation in Homogeneous Coordinates

Composition of Scalings in Homogeneous Coordinates

Combination of Scalings

Rotation in Homogeneous Coordinates The rotation equation is:

Successive Rotations

Borland Graphics Video Adapters: Video Adapters: Monochrome Display Adapter (MDA) for text display only Monochrome Display Adapter (MDA) for text display only Color/Graphics Adapter (CGA) Color/Graphics Adapter (CGA) Enhanced Graphics Adapter (EGA) Enhanced Graphics Adapter (EGA) Video Graphics Array adapter (VGA) Video Graphics Array adapter (VGA) Each adapter can operate in a variety of modes: Each adapter can operate in a variety of modes: Screen display of 40 or 80 columns (text mode only) Screen display of 40 or 80 columns (text mode only) Display resolution (Graphics mode only) Display resolution (Graphics mode only) Display type (Color or black & white) Display type (Color or black & white)

Screen Mode The screen operating mode is defined when your program calls one of the mode- defining functions The screen operating mode is defined when your program calls one of the mode- defining functions Textmode Textmode Initgraph Initgraph setgraphmode setgraphmode

Text mode: Screen is divided into 40 or 80 columns (wide) and 25, 43, or 50 lines (high). Text mode: Screen is divided into 40 or 80 columns (wide) and 25, 43, or 50 lines (high). Each cell will consist of an attribute and a character. The character will be the displayed ASCII character; the attribute specifies how the character is displayed (its color, intensity, …). The top left corner of the display screen is position (1,1), Each cell will consist of an attribute and a character. The character will be the displayed ASCII character; the attribute specifies how the character is displayed (its color, intensity, …). The top left corner of the display screen is position (1,1), x-coordinate increasing from left to right x-coordinate increasing from left to right Y-coordinate increasing from top to bottom Y-coordinate increasing from top to bottom

Graphics Mode: Screen is divided into pixels (what’s a pixel anyway?) Graphics Mode: Screen is divided into pixels (what’s a pixel anyway?) Each pixel displays a dot onscreen. Each pixel displays a dot onscreen. The number of pixels (the resolution) depends on the type of video adapter connected to your system and the mode that adapter is in. The number of pixels (the resolution) depends on the type of video adapter connected to your system and the mode that adapter is in. You can control the color of each pixel. You can control the color of each pixel. The top left corner of the screen is position (1,1). With x-coordinate increasing from left to right and the y-coordinate increasing from top to bottom. The top left corner of the screen is position (1,1). With x-coordinate increasing from left to right and the y-coordinate increasing from top to bottom.

Windows and Viewports Borland provides functions for creating and managing windows on your screen in the text mode. Borland provides functions for creating and managing windows on your screen in the text mode. It also provides the same for managing viewports in the graphics mode. It also provides the same for managing viewports in the graphics mode.

What is a Window? A window is a rectangular area defined on your computer’s video screen while it is in the text mode. A window is a rectangular area defined on your computer’s video screen while it is in the text mode. When your program writes to the screen, its output is restricted to the active window. The rest of the screen (outside the window) remains untouched. When your program writes to the screen, its output is restricted to the active window. The rest of the screen (outside the window) remains untouched. The default window is a full-screen text window. However, we may create smaller windows (with a call to window function) This function specifies the window’s position in terms of screen coordinates. The default window is a full-screen text window. However, we may create smaller windows (with a call to window function) This function specifies the window’s position in terms of screen coordinates.

What is a View Port? In graphics mode, we can define a rectangular area on the computer’s video screen, which is called a viewport. In graphics mode, we can define a rectangular area on the computer’s video screen, which is called a viewport. The graphic output of our programs will be displayed on the viewport as a virtual screen. The graphic output of our programs will be displayed on the viewport as a virtual screen. The rest of the screen remains untouched (outside the viewport) The rest of the screen remains untouched (outside the viewport) We may define a viewport in terms of the screen coordinates with a call to setviewport function. We may define a viewport in terms of the screen coordinates with a call to setviewport function.

Important! Only for defining the windows or viewports we will refer to the main screen’s coordinates! Only for defining the windows or viewports we will refer to the main screen’s coordinates! Otherwise for every other application we will refer relative to the window’s (texts) or viewport’s (graphics) coordinates. Otherwise for every other application we will refer relative to the window’s (texts) or viewport’s (graphics) coordinates.

Programming in the text mode The modes available on your system depend on the type of video adapter and monitor you have. You can specify the current text mode with a call to textmode function. The modes available on your system depend on the type of video adapter and monitor you have. You can specify the current text mode with a call to textmode function. Text mode functions are divided into five separate groups: Text mode functions are divided into five separate groups: Text output and manipulation Text output and manipulation Window and mode control Window and mode control Attribute control Attribute control State query State query Cursor shape Cursor shape

Text output and manipulation functions cprintfSends formatted output to the screen cprintfSends formatted output to the screen cputsSends a string to the screen cputsSends a string to the screen getcheReads a char and echoes it to the scr. getcheReads a char and echoes it to the scr. putchSends a single char to the screen putchSends a single char to the screen clreolClears from the cursor to the end of the line clreolClears from the cursor to the end of the line clrscrClears the text window clrscrClears the text window dellineDeletes the line where the cursor rests dellineDeletes the line where the cursor rests gotoxypositions the cursor gotoxypositions the cursor inslineInserts a blank line below cursor inslineInserts a blank line below cursor movetextCopies text from an area onscreen to another movetextCopies text from an area onscreen to another gettextCopies text from an area onscreen to memory gettextCopies text from an area onscreen to memory puttextCopies text from memory to an area onscreen puttextCopies text from memory to an area onscreen

Window and mode control functions textmodesets the screen to a text mode textmodesets the screen to a text mode windowdefines a text-mode window windowdefines a text-mode window

Text-mode Attribute Functions textattrSets the background and foreground colors at the same time textattrSets the background and foreground colors at the same time textbackgroundsets the background color textbackgroundsets the background color textcolorSets the foreground color textcolorSets the foreground color highvideoSets text to high intensity highvideoSets text to high intensity lowvideoSets text to low intensity lowvideoSets text to low intensity normvideoSets text to original intensity normvideoSets text to original intensity

Some Points The attribute control function uses an 8- bit value to set the background, foreground and blink attributes. The attribute control function uses an 8- bit value to set the background, foreground and blink attributes. The first 4 lowest bits represent the foreground color, the next 3 bits represent the background color and the 8 th bit (the highest one = 128) is for blinking.

State-Query Functions gettextinfoFills in a text_info structure with information about the current text window gettextinfoFills in a text_info structure with information about the current text window wherexGives the x-coordinate of the cell containing the cursor wherexGives the x-coordinate of the cell containing the cursor whereyGives the y coordinate of the cell containing the cursor whereyGives the y coordinate of the cell containing the cursor

About gettextinfo function This function fills a text_info structure (defined in conio.h) with several details about the text window, including: This function fills a text_info structure (defined in conio.h) with several details about the text window, including: The current video mode The current video mode The window’s position in absolute screen coordinates The window’s position in absolute screen coordinates The window’s dimensions The window’s dimensions The current foreground and background colors The current foreground and background colors The cursor’s current position The cursor’s current position

_setcursortype This function enables you to change the appearance of your cursor. The values are: This function enables you to change the appearance of your cursor. The values are: _NOCURSOR, which turns off the cursor _NOCURSOR, which turns off the cursor _SOLIDCURSOR, which gives you a solid block (large) cursor _SOLIDCURSOR, which gives you a solid block (large) cursor And _NORMALCURSOR, which gives you the normal underscore cursor And _NORMALCURSOR, which gives you the normal underscore cursor

Text Modes Computer may operate in one of the several text modes available on your computer. The enumeration type text_modes, defined in conio.h, enables you to use symbolic names for for the mode argument rather than the raw mode numbers. However, if you use the symbolic constants, you must include conio.h in your source code. Computer may operate in one of the several text modes available on your computer. The enumeration type text_modes, defined in conio.h, enables you to use symbolic names for for the mode argument rather than the raw mode numbers. However, if you use the symbolic constants, you must include conio.h in your source code.

Numeric and Symbolic Values for text_modes Symbolic Constant Numeric Value Video Text Mode LASTMODE Previous text mode enabled BW400 Black and white, 40 columns C color, 40 columns BW802 Black and white 80 columns C color, 80 columns MONO7 Monochrome, 80 columns C EGA, 80X43; VGA, 80X50

Examples of Using Symbolic Constants and Numeric Values Syntax Operating Mode Library Textmode(0) Black and white, 40 columns Textmode(BW80) Black and white, 80 columns conio.h Textmode(C40) 16-color, 40 columns conio.h Textmode(3) 16-color, 80 columns Textmode(7) Monochrome, 80 columns Textmode(C4350) EGA, 80X43; VGA, 80X50 conio.h

Colors Symbolic Constants Numeric Value Foreground or background BLACK0Both BLUE1Both GREEN2Both CYAN3Both RED4Both MAGENTA5Both BROWN6Both LIGHTGRAY7Both DARKGRAY8 Foreground only LIGHTBLUE9 LIGHTGREEN10 LIGHTCYAN11 LIGHTRED12 LIGHTMAGENTA13 YELLOW14 WHITE15 BLINK128

initgraph Syntax Syntax #include #include void initgraph(int *graphdriver, int *graphmode, char *pathtodriver); void initgraph(int *graphdriver, int *graphmode, char *pathtodriver); Description Description initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver), and putting the system into graphics mode. initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver), and putting the system into graphics mode. To start the graphics system, first call the initgraph function. initgraph loads the graphics driver and puts the system into graphics mode. You can tell initgraph to use a particular graphics driver and mode, or to autodetect the attached video adapter at run time and pick the corresponding driver. To start the graphics system, first call the initgraph function. initgraph loads the graphics driver and puts the system into graphics mode. You can tell initgraph to use a particular graphics driver and mode, or to autodetect the attached video adapter at run time and pick the corresponding driver.

initgraph If you tell initgraph to autodetect, it calls detectgraph to select a graphics driver and mode. initgraph also resets all graphics settings to their defaults (current position, palette, color, viewport, and so on) and resets graphresult to 0. If you tell initgraph to autodetect, it calls detectgraph to select a graphics driver and mode. initgraph also resets all graphics settings to their defaults (current position, palette, color, viewport, and so on) and resets graphresult to 0. Normally, initgraph loads a graphics driver by allocating memory for the driver (through _graphgetmem), then loading the appropriate BGI file from disk. As an alternative to this dynamic loading scheme, you can link a graphics driver file (or several of them) directly into your executable program file. Normally, initgraph loads a graphics driver by allocating memory for the driver (through _graphgetmem), then loading the appropriate BGI file from disk. As an alternative to this dynamic loading scheme, you can link a graphics driver file (or several of them) directly into your executable program file. pathtodriver specifies the directory path where initgraph looks for graphics drivers. initgraph first looks in the path specified in pathtodriver, then (if they are not there) in the current directory. Accordingly, if pathtodriver is null, the driver files (*.BGI) must be in the current directory. This is also the path settextstyle searches for the stroked character font files (*.CHR). pathtodriver specifies the directory path where initgraph looks for graphics drivers. initgraph first looks in the path specified in pathtodriver, then (if they are not there) in the current directory. Accordingly, if pathtodriver is null, the driver files (*.BGI) must be in the current directory. This is also the path settextstyle searches for the stroked character font files (*.CHR).

graphdriver *graphdriver is an integer that specifies the graphics driver to be used. You can give it a value using a constant of the graphics_drivers enumeration type, which is defined in graphics.h and listed below. *graphdriver is an integer that specifies the graphics driver to be used. You can give it a value using a constant of the graphics_drivers enumeration type, which is defined in graphics.h and listed below.

Graphics_deiver constants

graphmode *graphmode is an integer that specifies the initial graphics mode (unless *graphdriver equals DETECT; in which case, *graphmode is set by initgraph to the highest resolution available for the detected driver). You can give *graphmode a value using a constant of the graphics_modes enumeration type, which is defined in graphics.h and listed below. *graphmode is an integer that specifies the initial graphics mode (unless *graphdriver equals DETECT; in which case, *graphmode is set by initgraph to the highest resolution available for the detected driver). You can give *graphmode a value using a constant of the graphics_modes enumeration type, which is defined in graphics.h and listed below. graphdriver and graphmode must be set to valid values from the following tables, or you will get unpredictable results. The exception is graphdriver = DETECT. graphdriver and graphmode must be set to valid values from the following tables, or you will get unpredictable results. The exception is graphdriver = DETECT. Palette listings C0, C1, C2, and C3 refer to the four predefined four- color palettes available on CGA (and compatible) systems. You can select the background color (entry #0) in each of these palettes, but the other colors are fixed. Palette listings C0, C1, C2, and C3 refer to the four predefined four- color palettes available on CGA (and compatible) systems. You can select the background color (entry #0) in each of these palettes, but the other colors are fixed.

Pallete Colors

Return Value initgraph always sets the internal error code; on success, it sets the code to 0. If an error occurred, *graphdriver is set to - 2, -3, -4, or -5, and graphresult returns the same value as listed below: initgraph always sets the internal error code; on success, it sets the code to 0. If an error occurred, *graphdriver is set to - 2, -3, -4, or -5, and graphresult returns the same value as listed below:

Error codes

Graph error messages Syntax Syntax #include //In DOS mode #include //In DOS mode char * grapherrormsg(int errorcode); char * grapherrormsg(int errorcode); Description Description grapherrormsg returns a pointer to the error message string associated with errorcode, the value returned by graphresult. grapherrormsg returns a pointer to the error message string associated with errorcode, the value returned by graphresult. Return Value Return Value grapherrormsg returns a pointer to an error message string. grapherrormsg returns a pointer to an error message string.

Set color Syntax Syntax #include #include void setcolor(int color); void setcolor(int color); Description Description setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor. The current drawing color is the value to which pixels are set when lines, and so on are drawn. The drawing colors shown below are available for the CGA and EGA, respectively. setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor. The current drawing color is the value to which pixels are set when lines, and so on are drawn. The drawing colors shown below are available for the CGA and EGA, respectively.