Top Advertisement

Your Ad Here

Sunday, August 15, 2010

Turbo C Graphics... BASICS

Now I'll teach you how to use graphics in turbo c...

First You have to open it up go to OPTIONS -> LINKER -> CLICK THE GRAPHICS YOU SHOULD see a mark x
look for the BGI folder in TURBO C then copy all of its content... to BIN
now we are ready to use the graphics library of the turbo c... I'll teach you some reserved words in graphics



cleardevice(); // is the clrscr() of the graphics mode...
outtextxy(); // works like printf ex. outextxy(100,100"Louie"); can only print string...
getmaxx(); // returns the maximum x pixel of the screen
getmaxy(); // returns the maximum y pixel of the screen
setcolor(); // sets the color of the next text; LIGHTBLUE search in google for values can be integer 0-14
settextstyle(); // sets the style of the next text ex. settextstyle(2,HORIZ_DIR,4); params font,direction,size
settextjustify();

// justify the text via x,y ex. settextjustify(CENTER_TEXT,CENTER_TEXT);

alright to start let me show you a simple code...


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

int gdriver=DETECT,gmode,errorcode,x,y;
int color=0,size=1,font=1;
char name[20] = "Your Lovers Name";


void main(){
initgraph(&gdriver,&gmode,"");// initialize the graphics mode...

settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(getmaxx()/2,30,"I LOVE YOU...");

settextstyle(2,HORIZ_DIR,4);
outtextxy(getmaxx()/2,60,"I LOVE YOU...");

setcolor(RED);
outtextxy(getmaxx()/2,90,"I LOVE YOU...");

settextstyle(9,HORIZ_DIR,1);
outtextxy(getmaxx()/2,120,"PRESS ANY KEY TO CONTINUE...");
getch();
cleardevice();
settextstyle(2,HORIZ_DIR,4);
outtextxy(getmaxx()/2,60,"PRESS ENTER TO SEE THIS IS MY LIFE!!");
while(!kbhit()){
   delay(10);
   x = random(800);
   y = random(300);
   settextstyle(font,HORIZ_DIR,size);
   setcolor(color);
   outtextxy(x,y,name);
   color++;
   font++;
   size++;
   if(color == 15) color=0;
   if(size == 5) size=1;
   if(font == 9) font=1;
}
getch();
}



we included the stdlib.h to use the random function. graphics.h to use all necessary reserved words for graphics.. conio.h for the getch, dos.h for the delay... you find a lot of things from these header files... just know how to search there is also a help file included in turbo c.. it can save you a lot of time searching the internet... ^___^

Why Don't you try this one... and study... how about the moving car? can you do it now?

ON MY NEXT BLOG... hmmm... PHP PROGRAMMING... MY FAVORITE... ^___^

1 comment:

  1. nice sir.. thanks for this... but can you make a simple program graphics na yung mga sentences ay may mga kulay at gumagalaw.. gusto ko sanang program yung may nakasulat na I LOVE YOU MARY JOY tapos may kulay at gumagalaw-galaw.. can you teach me pls? ^^ thanks a lot..

    ReplyDelete