sábado, 28 de enero de 2012

Introduccion


 En el modo gráfico existe una enorme cantidad de funciones que realizan desde la tarea mas sencilla como es pintar un píxel, hasta la tarea mas compleja como pudiera ser dibujar un carácter por medio de trazos.

Para trabajar el modo gráfico es necesario incluir la librería graphics.h como hacer uso de la BGI (Borlan Graphics Interphase)

Para usar cualquier función es necesario colocar el adaptador de video en modo grafico y esto se logra a través de la función initgraph(); y al terminares necesario regresar al modo original a través de la función closegraph();

Para iniciar un programa en ambiente gráfico es recomendable correr una subrutina de inicialización de gráficos y detección de errores.

Algunos ejemplos de las funciones que se pueden encontrar en la librería de gráphics.h son:
Line(); circle(); arc(); elipse();rectangle(); ottextxy(); putpixel();
Para saber mas de las funciones de la librería de gráficos lo pueden buscar en el índice de turbo c

NOTA: Para dar de alta en tu computadora el modo de gráficos tienes que hacer los siguientes pasos: OPTIONS ->LINKER->LIBRARIE->seleccionar GRAPHICS LIBRARY
EJEMPLO:
#include<graphics.h>
#include<conio.h>
#include<math.h>
int main(void)
{
 clrscr();

 double fx;
 int graphdriver=DETECT,graphmode;
 initgraph(&graphdriver,&graphmode,"..\\bgi");
 outtextxy(30,30,”GRAFICACION DE SENO “);
 setbkcolor(RED);
 for (int x=0;x<=90;x++)
 {
   fx=(1+sin(x))*40+200;
  putpixel(x*15,fx,YELLOW);
  }
  setcolor(BLUE);
 line(310,100,310,400);
 line(100,240,500,240);
  getch();
  closegraph();
 return 0;
}





ESTRUCTURA DEL PROGRAMA

#include <graphics.h>  
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
   VARIABLES PARA INICIALIZAR MODO GRAFICO
   int gdriver = DETECT, gmode, errorcode;

   INICIALIZAR MODO GRAFICO
   initgraph(&gdriver, &gmode, "");

  DETECTA SI HAY ALGUN ERROR PARA USAR MODO GRAFICO
   errorcode = graphresult();
  
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }

   line(0, 0, 50,50 ); DIBUJA UNA LINEA

   getch();
   closegraph(); CERRAR MODO GRAFICO
   return 0;
}

FUNCIONES PARA DIBUJAR

cleardevice(void); LIMPIA LA PANTALLA

setcolor(int color); COLOR DE LINEA

setbkcolor(int color); COLOR DE FONDO (PANTALLA)







TAMAÑO O RESOLUCION DE LA PANTALLA  640X480 PIXELS

line(int x1, int y1, int x2, int y2); DIBUJA UNA LINEA

rectangle(int left, int top, int right, int bottom); DIBUJA UN RECTANGULO
rectangle(izqierda,arriba,derecha,abajo);

putpixel(int x, int y, int color); PINTA UN PIXEL

outtextxy(int x, int y, char far *textstring); DIBUJA TEXTO
outtextxy(100,100,”Programa 1”);

settextstyle(int font, int direction, int charsize); TIPO DE LETRA A USAR
settextstyle(tipo letra, direccion, tamaño letra);

TIPOS DE LETRA (FONT)

0   DEFAULT_FONT       
1   TRIPLEX_FONT        
2   SMALL_FONT            
3   SANS_SERIF_FONT  
4   GOTHIC_FONT           

DIRECTION

0   HORIZ_DIR   
1   VERT_DIR    

settextjustify(int horiz, int vert); JUSTIFICAR TEXTO

HORIZ  

0   LEFT_TEXT     IZQUIERDA
1   CENTER_TEXT   CENTRADO
2   RIGHT_TEXT   DERECHA

VERT   

0   BOTTOM_TEXT  ABAJO
1   CENTER_TEXT   CENTRADO
2   TOP_TEXT      ARRIBA

RELLENADO DE FIGURAS

floodfill(int x, int y, int border); RELLENAR FIGURA

setfillstyle(int pattern, int color); TIPO DE RELLENO Y COLOR A USAR

TIPOS DE RELLENADO(FILL PATTERNS)

0   EMPTY_FILL       
1   SOLID_FILL       
2   LINE_FILL        
3   LTSLASH_FILL     
4   SLASH_FILL       
5   BKSLASH_FILL     
6   LTBKSLASH_FILL   
7   HATCH_FILL       
8   XHATCH_FILL      
9   INTERLEAVE_FILL  
10 WIDE_DOT_FILL   
11 CLOSE_DOT_FILL  
12 USER_FILL       

COLORES

0   BLACK         
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         
128  BLINK       

No hay comentarios:

Publicar un comentario