Add WinBGI Graphics to your Console

vegaseat 1 Tallied Votes 560 Views Share

The WinBGI package allows you to do some of the Borland BGI graphics in a specially created window form. So don't throw out the old Borland manuals, you can still use them to do some fancy graphing! Yes, you can gotoxy() again! This code was modified for Dev-C++, a real workhorse come to think of it. Thanks free_eagle for getting this started!

// do some graphics using the WinBgi package from:
// http://csci.biola.edu/csci105/using_winbgi.html
//
// for Dev-C++ you need to fix graphics2.h and WinBgi2.cpp
// do change  unsigned int getpixel() to  int getpixel()
// 
// have WinBgi2.cpp in the working folder and add to project
// have graphics2.h in the working folder
// link with libgdi32.a
// this Dev-C++ project is a Console Application

#include <cstdio>
#include <cmath>
#include "graphics2.h"

using namespace std;

int main()
{
 	int GraphDriver = 0, GraphMode = 0;
 	// create graph window frame
	initgraph(&GraphDriver, &GraphMode, "", 640, 480); 

	// first draw two ellipses and a line ...
  setcolor(CYAN);
	setlinestyle(SOLID_LINE, 0, 2);  // 2 pixels wide
	//** ellipse(int x,int y,int sa,int ea,int rx,int ry)
  //**   center = x, y 
  //**   sa = start of arc  (0 to 360 degrees)
  //**   ea = end of arc
  //**   rx = length of horizontal axis (radius)
  //**   ry = length of vertical axis (radius)
	ellipse(320, 150, 0, 360, 150, 20);
	
	setcolor(LIGHTGREEN);
	setlinestyle(SOLID_LINE, 0, 3);  // 3 pixels wide
	ellipse(320, 150, 0, 360, 40, 90);
	
	setcolor(LIGHTRED);
	setlinestyle(SOLID_LINE, 0, 2);
             // line(int x1, int y1, int x2, int y2)
	line(20, 300, 600, 300);
	
	setcolor(YELLOW);
	settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
	outtextxy(20, 320, "Press any key ... ");
	getch();  // wait

	// now draw some fancy lines ...
  int x, y;
	int spokes = 6;  // triangle = 3,  more complex > 3
	double radians;
  	
	setcolor(GREEN);
	radians = 360 / (spokes * 57.29578);
	for (x = 1; x <= spokes; x++) 
  {
		for (y = x; y <= spokes; y++) 
    {
			line((int)(sin(y * radians) * 225 + 320),(int)(cos(y * radians) * 145 + 150),
		  (int)(sin(x * radians) * 225 + 320),(int)(cos(x * radians) * 145 + 150));
		}
	}
	outtextxy(20,320,"Press any key ... ");
	getch();  // wait
	
	closegraph();
	
  return 0;
}