GRAF�K

Basit grafik i�lemleri nas�l ger�ekle�tirilir.

Normal �al��ma an�nda text ekranda (25, 80) boyutlar�nda.

Bu fonksiyonlar do�rudan ekrana yazan deyimlere y�neliktir (cprintf, cput)

#include <conio.h>

main()

{

int i;

textbackground(BLACK);

clrscr();

for (i=0; i<=15;i++) {

textcolor(i);

cputs("�SRAF�L BAYRAM\r\n");

}

getch();

}

Grafik �izimi i�in bilgisayar�n grafik modunda olmas� gerekir.

void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);

Grafik sistemini verilen de�erlere g�re ayarlar. Grafik komutlar�n� kullanmadan �nce �al��t�r�lmal�d�r.

Renk kodlar� a�a��daki gibidir:

EGA_BLACK

EGA_BLUE

EGA_GREEN

EGA_CYAN

EGA_RED

EGA_MAGENTA

EGA_LIGHTGRAY

EGA_BROWN

0

1

2

3

4

5

7

20

EGA_DARKGRAY

EGA_LIGHTBLUE

EGA_LIGHTGREEN

EGA_LIGHTCYAN

EGA_LIGHTRED

EGA_LIGHTMAGENTA

EGA_YELLOW

EGA_WHITE

56

57

58

59

60

61

62

63

�rnek:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

main()

{

int gd, gm, hata;

int x, y;

gd = DETECT; /* ekran s�r�c�s�n� otomatik tan� */

/* CGA, HERC, VGA..*/

initgraph(&gd, &gm, "c:\tc\bgi\");

/* gd gm

VGA � VGALO � 0 � 640 x 200 � 16 color� 2

9 � VGAMED � 1 � 640 x 350 � 16 color� 2

� VGAHI � 2 � 640 x 480 � 16 color� 1

*/

hata = graphresult();

if (hata != grOk) /* grOk = 0 tan�ml� */

{

printf("Grafik hatas�: %s\n", grapherrormsg(hata));

getch();

exit(1);

}

x = getmaxx();

y = getmaxy();

setbkcolor(EGA_RED);

setcolor(EGA_YELLOW);

cleardevice();

line(0, 0, 0, y);

line(0, y, x, y);

line(x, y, x, 0);

line(x, 0, 0, 0);

getch();

cleardevice();

moveto(50, 50);

lineto(50, 100);

lineto(100,100);

lineto(100,50);

lineto(50, 50);

getch();

closegraph();

}

�rnek : Fonksiyon �izimi

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <math.h>

double fonk(double x);

double fonk1(double x);

main()

{

int gd, gm, hata;

double x, y;

int orgx, orgy;

gd = DETECT;

initgraph(&gd, &gm, "c:\tc\bgi\");

hata = graphresult();

if (hata != grOk)

{

printf("Grafik hatas�: %s\n", grapherrormsg(hata));

getch();

exit(1);

}

orgx = 20;

orgy = getmaxy() / 2;

line(0, orgy, getmaxx(), orgy); /* x ekseni */

line(20, 0, 20, orgy+50); /* y ekseni */

outtextxy(getmaxx()-50, orgy-10, "Zaman");

outtextxy(22, 0, "Volt");

for (x = 0; x< 6.28; x = x + 0.005) {

y = fonk1(x);

putpixel(orgx + 80*x, orgy - y, 2); /* renk ye�il EGA_GREEN*/

/* -eksenin �zerinde �izmesi i�in */

}

getch();

closegraph();

}

double fonk(double x)

{

double y;

y = 100 * sin(10 * x);

return y;

}

double fonk1(double x)

{

double y;

y = 1 - exp(-x);

return 200*y;

}