Add WinBGI Graphics to your Console

vegaseat vegaseat is offline Offline Feb 1st, 2005, 3:25 pm |
0
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!
Quick reply to this message  
C++ Syntax
  1. // do some graphics using the WinBgi package from:
  2. // http://csci.biola.edu/csci105/using_winbgi.html
  3. //
  4. // for Dev-C++ you need to fix graphics2.h and WinBgi2.cpp
  5. // do change unsigned int getpixel() to int getpixel()
  6. //
  7. // have WinBgi2.cpp in the working folder and add to project
  8. // have graphics2.h in the working folder
  9. // link with libgdi32.a
  10. // this Dev-C++ project is a Console Application
  11.  
  12. #include <cstdio>
  13. #include <cmath>
  14. #include "graphics2.h"
  15.  
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20. int GraphDriver = 0, GraphMode = 0;
  21. // create graph window frame
  22. initgraph(&GraphDriver, &GraphMode, "", 640, 480);
  23.  
  24. // first draw two ellipses and a line ...
  25. setcolor(CYAN);
  26. setlinestyle(SOLID_LINE, 0, 2); // 2 pixels wide
  27. //** ellipse(int x,int y,int sa,int ea,int rx,int ry)
  28. //** center = x, y
  29. //** sa = start of arc (0 to 360 degrees)
  30. //** ea = end of arc
  31. //** rx = length of horizontal axis (radius)
  32. //** ry = length of vertical axis (radius)
  33. ellipse(320, 150, 0, 360, 150, 20);
  34.  
  35. setcolor(LIGHTGREEN);
  36. setlinestyle(SOLID_LINE, 0, 3); // 3 pixels wide
  37. ellipse(320, 150, 0, 360, 40, 90);
  38.  
  39. setcolor(LIGHTRED);
  40. setlinestyle(SOLID_LINE, 0, 2);
  41. // line(int x1, int y1, int x2, int y2)
  42. line(20, 300, 600, 300);
  43.  
  44. setcolor(YELLOW);
  45. settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
  46. outtextxy(20, 320, "Press any key ... ");
  47. getch(); // wait
  48.  
  49. // now draw some fancy lines ...
  50. int x, y;
  51. int spokes = 6; // triangle = 3, more complex > 3
  52. double radians;
  53.  
  54. setcolor(GREEN);
  55. radians = 360 / (spokes * 57.29578);
  56. for (x = 1; x <= spokes; x++)
  57. {
  58. for (y = x; y <= spokes; y++)
  59. {
  60. line((int)(sin(y * radians) * 225 + 320),(int)(cos(y * radians) * 145 + 150),
  61. (int)(sin(x * radians) * 225 + 320),(int)(cos(x * radians) * 145 + 150));
  62. }
  63. }
  64. outtextxy(20,320,"Press any key ... ");
  65. getch(); // wait
  66.  
  67. closegraph();
  68.  
  69. return 0;
  70. }
  71.  

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC