/* Graphics lecture for C++ {under construction} First of all: you must ALWAYS #include when using any of the graphics routines. In order to use the graphics utilitles you must first initialize the drivers. If there are any errors exit to dos. At the end of your program you must always close the graphics driver using closegraph() See the sample: */ #include #include #include #include int main(void) { int gdriver = DETECT, gmode, errorcode; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); /* an error occurred */ if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } closegraph(); return 0; } /* Once you have initialized the graphics drivers you may begin to draw. First you must move to the position you want to draw at. Use the following routines to find the size of the screen, the position of the cursor, and to move the cursor. */ x = getmaxx(); y = getmaxy(); to get the size of the screen x = getx(); y = gety(); to get the current position. and MoveTo( x, y); to change the cursor position. /* some useful procedures: */ RestoreCrtMode - Switches back to text mode. SetgraphMode(GraphMode) - Switches back to graphics mode, and resets all defaults. clearviewport - Clears the screen in graphics mode. cleardevice - Also clears screen Putpixel(x, y, color) - Plots a pixel at coordinate x, y with color color. Getpixel(x,y) - Gets the color of the pixel at x, y. Line(x1, y1, x2, y2) - draws a line from the coordinates x1, y1 to x2, y2. Setlinestyle(LineStyle, Pattern, Thickness) - sets the current line style. Circle(x, y, radius) - draws a circle at x, y with a radius radius. Exp: circle(150,200,10); Setcolor(color) - sets the current drawing color. getcolor - returns the current drawing color. Setbkcolor(color) - sets the current background color. Getbkcolor - returns the current background color. Setfillstyle (Pattern, Color) - sets the fill pattern and color. Floodfill(x, y, border) - fills an enclosed region with the current fill style, where border is the color of the border to fill between. Rectangle(x1,y1,x2,y2) - Draws the border of a rectangle. Bar(x1, y1, x2, y2) - Draws a bar with the current fill style and color. Bar3d(x1, y1, x2, y2, Depth, Top) - Draws a three dimentional bar. DrawPoly(Numpoints, PolyPoints) - Draws a polygon. FillPoly(Numpoints, Polypoints) - Fills a polygon. Ellipse(x, y, StartAngle, EndAngle, Xradius, Yradius) - Draws an ellipse. FillEllipse(x, y, Xradius, Yradius) - Fills an ellipse. Arc(x, y, Startangle, Endangle, Radius) - draws an arc. PieSlice(x, y, Startangle, Endangle, Radius) - Draws a pieslice. Sector(x, y, Startangle, Endangle, xradius, yradius) - Draws a sector of an ellipse. outtext(string) - displays text in graphics mode at the current pointer. outtextxy(x, y, string) - displays text at x, y. Settextstyle(font, direction, Charsize) - Sets the style for text output. Settextjustify(horiz, Vert) - sets text justify for outtext. Getfillsettings(fillinfo : fillsettingstype); getimage(x1, y1, x2, y2, p^) - gets an image and puts it in video memory. getmaxcolor - returns the highest possible color. gettextsettings(textinfo : textsettingstype) - gets settings for text output in graphics mode. imagesize(x1, y1, x2, y2) - returns the size of a rectangular region for use with getimage. lineto(x,y) - draws a line from the current pointer to x,y. textheight(string) - returns the height of a string in graphics(in pixels). textwidth(string) - returns the width of a string in graphics(in pixels). (*****************************************************************) Color constants 0 - Background color 1 - blue 2 - green 3 - cyan 4 - red 5 - magenta 6 - brown 7 - lightgray 8 - darkgray 9 - lightblue 10 - lightgreen 11 - lightcyan 12 - lightred 13 - lightmagenta 14 - yellow 15 - white