Author Topic: is it possible to use the "borland's graphic mode"??  (Read 4638 times)

xeckthor

  • Guest
is it possible to use the "borland's graphic mode"??
« on: November 25, 2008, 06:58:55 am »
hi all!!!

i have a problem with my notebook, its a toshiba, the video card is intel and i have windows...vista and xp, but i`ve been usin code blocks since 5 or 6 moths ago, programin' in C, everything was great...but...i have a teacher that ask us to make something in "graphic mode" and i found that with borland is possible to do that, then i learned how to configure CB to use the borland compiler...but i have a problem, the driver from borland isnt supported under any of my windows, so i think that the problem is with the video card...anyway...how can i make this code with gcc?...or with borland...?....always on CB...?

i know its comments are in spanish, but the code in english is the same =D

the code solves the hanoi tower's thing xDDD

Code
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<dos.h>

/// FUNCION DE LA SOLUCION LOGICA DE LOS MOVIMIENTOS ///

void Hanoi( int numDiscos, char origen, char auxiliar, char destino )
{
  if( numDiscos==1 )
  cout << origen << " --> " << destino << endl;
else
{
Hanoi( numDiscos-1, origen, destino, auxiliar );
cout << origen << " --> " << destino << endl;
Hanoi( numDiscos-1, auxiliar, origen, destino );
}
}

///// FUNCION DE GRAFICACION INICIAL DE LOS DISCOS /////

void grafini(int Num)
{

for(int i=1; i<=Num ; i++)
    {
     setcolor(i);
     circle(160,350,15 + i*15);
    }
    setcolor(4);
    outtextxy(155,345,"A");
    outtextxy(315,115,"B");
    outtextxy(475,345,"C");

}

///// FUNCION DE GRAFICACION FINAL DE LOS DISCOS /////

void graffin(int Num)
{

for(int i=1; i<=Num ; i++)
    {
     setcolor(i);
     circle(480,350,15 + i*15);
    }
    setcolor(4);
    outtextxy(155,345,"A");
    outtextxy(315,115,"B");
    outtextxy(475,345,"C");

}


///// FUNCION DE ANIMACION DE MOVIMIENTOS DE LOS DISCOS ////

void grafimov(int Numd,char origen, char destino)

{

switch (origen)
   {
    case 'A':

   switch(destino)
   {
   case 'B':
   for( double t=0.00; t<1.00; t=t+0.01 )
      {
      setcolor(0);
      circle(160 +160*t,350-230*t, 15+Numd*15);
      setcolor(Numd);
      circle(160 +160*(t+0.01),350-230*(t+0.01),15+Numd*15);
      setcolor(4);
      outtextxy(155,345,"A");
      outtextxy(315,115,"B");
      outtextxy(475,345,"C");
      delay(50);
      }
      setcolor(0);
      circle(160 +160*t,350-230*t, 15+Numd*15);
      setcolor(Numd);
      circle(160 +160,350-230, 15+Numd*15);
   break;
   case 'C':
   for(t=0.00; t<1.00; t= t+0.01 )
      {
      setcolor(0);
      circle(160 + 320*t,350, 15+Numd*15);
      setcolor(Numd);
      circle(160 +320*(t+0.01),350,15+Numd*15);
      setcolor(4);
      outtextxy(155,345,"A");
      outtextxy(315,115,"B");
      outtextxy(475,345,"C");
      delay(50);
      }
      setcolor(0);
      circle(160 +320*t,350, 15+Numd*15);
      setcolor(Numd);
      circle(160 +320,350, 15+Numd*15);
   break;
   }
  break;

    case 'B':

   switch(destino)
   {
   case 'A':
   for(double t=0.00; t<1.00; t= t+0.01 )
      {
      setcolor(0);
      circle(320 -160*t,120+230*t, 15+Numd*15);
      setcolor(Numd);
      circle(320 -160*(t+0.01),120+230*(t+0.01),15+Numd*15);
      setcolor(4);
      outtextxy(155,345,"A");
      outtextxy(315,115,"B");
      outtextxy(475,345,"C");
      delay(50);
      }
      setcolor(0);
      circle(320 -160*t,120+230*t, 15+Numd*15);
      setcolor(Numd);
      circle(320 -160,120+230, 15+Numd*15);
   break;
   case 'C':
   for( t=0.00; t<1.00; t= t+0.01 )
      {
      setcolor(0);
      circle(320 + 160*t,120+230*t, 15+Numd*15);
      setcolor(Numd);
      circle(320 +160*(t+0.01),120+230*(t+0.01),15+Numd*15);
      setcolor(4);
      outtextxy(155,345,"A");
      outtextxy(315,115,"B");
      outtextxy(475,345,"C");
      delay(50);
      }
      setcolor(0);
      circle(320 + 160*t,120+230*t, 15+Numd*15);
      setcolor(Numd);
      circle(320 + 160,120+230, 15+Numd*15);
   break;
   }
    break;

    case 'C':

   switch(destino)
   {
   case 'B':
   for(double t=0.00; t<1.00; t= t+0.01 )
      {
      setcolor(0);
      circle(480 -160*t,350-230*t, 15+Numd*15);
      setcolor(Numd);
      circle(480 -160*(t+0.01),350-230*(t+0.01),15+Numd*15);
      setcolor(4);
      outtextxy(155,345,"A");
      outtextxy(315,115,"B");
      outtextxy(475,345,"C");
      delay(50);
      }
      setcolor(0);
      circle(480 -160*t,350-230*t, 15+Numd*15);
      setcolor(Numd);
      circle(480 -160,350-230, 15+Numd*15);
   break;
   case 'A':
   for( t=0.00; t<1.00; t= t+0.01 )
      {
      setcolor(0);
      circle(480 - 320*t,350, 15+Numd*15);
      setcolor(Numd);
      circle(480 -320*(t+0.01),350,15+Numd*15);
      setcolor(4);
      outtextxy(155,345,"A");
      outtextxy(315,115,"B");
      outtextxy(475,345,"C");
      delay(50);
      }
      setcolor(0);
      circle(480 - 320*t,350, 15+Numd*15);
      setcolor(Numd);
      circle(480 - 320,350, 15+Numd*15);
   break;
   }
    break;

   }

}

///// FUNCION ANIMADORA DE LA SOLUCION COMPLETA ////

void Hanoigraf( int numDiscos, char origen, char auxiliar, char destino )
{
  if( numDiscos==1 )
  grafimov(numDiscos, origen, destino);
else
{

Hanoigraf( numDiscos-1, origen, destino, auxiliar );
grafimov(numDiscos,origen,destino);
Hanoigraf( numDiscos-1, auxiliar, origen, destino );
}
}

///// FUNCION PRINCIPAL ////


  void main()
  {
int NumDiscos;

cout << "Cuantos discos : ";
cin >> NumDiscos;
Hanoi( NumDiscos, 'A', 'B', 'C');
cout<<"YA TERMINE "<<endl;
cout<<"presione una tecla para continuar"<<endl;
getch();
/******  iniciacion del modo grafico  ****/
int driver=DETECT,mode,resgraf;
initgraph(&driver,&mode,"c:\\tc\\bgi");
resgraf=graphresult();
if(resgraf!=grOk)
   {
   cout<<"Ha ocurrido un error en la inicializacion"<<endl;
   cout<<"Presione una tecla para regresar al modo texto"<<endl;
   getch();
   exit(1);
   }

grafini(NumDiscos);
Hanoigraf(NumDiscos,'A','B','C');
clearviewport();
graffin(NumDiscos);
outtextxy(170,445,"EL PROGRAMA DE ANIMACION HANOI TERMINO");
outtextxy(200,455,"Presione una tecla para continuar");
getch();
closegraph();
exit(1);

  }

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: is it possible to use the "borland's graphic mode"??
« Reply #1 on: November 25, 2008, 10:59:37 am »
Well, what's there to say... since you use Borland-specific terminal control functions that are not supported by gcc (or any other compiler) you cannot compile this with any compiler other than Borland, obviously.
If the Borland runtime does not work on your laptop, you'll have little choice but to either use some other API, or use a different computer. I'd suggest using SDL/OpenGL. Not only does it work better, it looks better than ASCII-graphics too.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

nicto

  • Guest
Re: is it possible to use the "borland's graphic mode"??
« Reply #2 on: November 27, 2008, 01:27:39 am »
You can not use the Borland's libraries, but there are some emulators of this lib. Try http://www.uniqueness-template.com/devcpp/.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: is it possible to use the "borland's graphic mode"??
« Reply #3 on: November 27, 2008, 04:49:44 pm »
to: xeckthor

Your code is too old. I have seen this code about 8 years ago, when I was in Ms-Dos, and using Borland C++ or Turbo C++.
Now the world has changed, the these code can't be compiled in modern compilers. And the "Borland graphics mode" is only exist for Dos operation system.

If you are using windows, you can easily use Windows GDI API to draw something on the screen.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.