Sunteți pe pagina 1din 12

Draw a hut and color

...................................

#include<graphics.h>

#include<conio.h>

int main()

int gd=DETECT ,gm;

initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");

setcolor (WHITE);

rectangle(150,180,250,300);

rectangle(250,180,420,300);

rectangle(180,250,220,300);

line(200,100,150,180);

line(200,100,250,180);

line(200,100,370,100);

line(370,100,420,180);

setfillstyle(SOLID_FILL,BROWN);

floodfill(152,182,WHITE);

floodfill(252,182,WHITE);

setfillstyle(SLASH_FILL,BLUE);

floodfill(182,252,WHITE);

setfillstyle(HATCH_FILL,GREEN);

floodfill(200,105,WHITE);

floodfill(210,105,WHITE);

getch();

return 0;

}
Floodfill to fill a circle

..............................

#include<graphics.h>

#include<conio.h>

void main()

int gm, gd=DETECT;

initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");

circle(100,100,50);

setfillstyle(HATCH_FILL,RED);

//Change RED to WHITE.

floodfill(100,100,WHITE);

getch();

DDA

......................................

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

int gd=DETECT,gm,x=25,y=25,font=10;

initgraph(&gd,&gm,"c:\\turbocC3\\BGI");

for(font=0;font<=4;font++)

settextstyle(font,HORIZ_DIR,font+1);

setcolor(font+1);
outtextxy(x,y,"text with deffrent fronts");

y=y+25;

for(font=0;font<=2;font++)

settextstyle(font,VERT_DIR,font+2);

setcolor(font+1);

x=250;

y=100;

outtextxy(x,y,"text in vertical direction");

y=y+25;

getch();

closegraph();

____________________________

Bouncing ball (vertically)

__________________________

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

int main()

int gdriver= DETECT,gmode;

int x,y,i,flag=0;

initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");

x=getmaxx()/2;

y=30;
while(!kbhit())

if(y>=getmaxy()-30||y<=30)

flag=!flag;

setcolor(RED);

setfillstyle(SOLID_FILL,RED);

circle(x,y,30);

floodfill(x,y,RED);

delay(50);

cleardevice();

if(flag)

y=y+5;

else

y=y-5;

closegraph();

return 0;

____________________________

Bouncing ball (horizontally)

__________________________

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>
int main()

int gdriver= DETECT,gmode;

int x,y,i,flag=0;

initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");

x=30;

y=getmaxy()/2;

while(!kbhit())

if(x>=getmaxx()-30||x<=30)

flag=!flag;

setcolor(RED);

setfillstyle(SOLID_FILL,RED);

circle(x,y,30);

floodfill(x,y,RED);

delay(50);

cleardevice();

if(flag)

x=x+20;

else

x=x-20;

closegraph();

return 0;

}
___________________________

Rainbow without method

_____________________________

#include<stdio.h>

#include<graphics.h>

#include<dos.h>

int main()

int gdriver= DETECT,gmode;

int x,y,i;

initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");

x=getmaxx()/2;

y=getmaxy()/2;

for(i=30;i<200;i++)

delay(100);

setcolor(i/10);

arc(x,y,0,180,i-10);

return 0;

_____________________________________________

Rainbow with method

______________________________________________
#include<stdio.h>

#include<graphics.h>

#include<dos.h>

void rainbow()

int gdriver= DETECT,gmode;

int x,y,i;

initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");

x=getmaxx()/2;

y=getmaxy()/2;

for(i=30;i<200;i++)

delay(100);

setcolor(i/10);

arc(x,y,0,180,i-10);

int main()

rainbow();

return 0;

__________________________________

Cosine wave

_________________________________

#include<stdio.h>

#include <math.h>

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

#include<dos.h>

int main()

int gdriver= DETECT,gmode;

int angle=0;

double x,y;

initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");

line(0, getmaxy()/2, getmaxx(), getmaxy()/2 );

for(x =0;x <getmaxx(); x+=3)

y= 50 * sin(angle* 3.141/180);

y= getmaxy()/2 - y;

putpixel(x, y ,15);

delay(100);

angle +=5;

getch();

return 0;

_______________________________

Sine wave

_______________________________

#include<conio.h>

#include<math.h>

#include<graphics.h>

#include<dos.h>
int main(){

int gd=DETECT, gm;

int angle=0;

double x, y;

initgraph(&gd,&gm, "C:\\Turboc3\\BGI");

line(0,getmaxy() /2, getmaxx(), getmaxy() /2);

for(x=0; x < getmaxx(); x+=3){

y=50*sin(angle*3.141/180);

y=getmaxy()/2-y;

putpixel(x,y,25);

delay(50);

angle+=25;

getch();

closegraph();

return 0;

_______________________________

star in night sky

_______________________________

#include<conio.h>

#include<graphics.h>

#include<dos.h>

#include<stdlib.h>

int main(){

int gd=DETECT, gm;

int i, x, y;

initgraph(&gd,&gm, "C:\\Turboc3\\BGI");

while(!kbhit())
{

for(i=0; i<=500; i++)

x=rand()%getmaxx();

y=rand()%getmaxy();

putpixel(x,y,15);

delay(500);

cleardevice();

getch();

closegraph();

return 0;

_______________________________

color star in night sky

_______________________________

#include<conio.h>

#include<graphics.h>

#include<dos.h>

#include<stdlib.h>

int main(){

int gd=DETECT, gm;

int i, x, y;

initgraph(&gd,&gm, "C:\\Turboc3\\BGI");

while(!kbhit())

for(i=0; i<=500; i++)

{
x=rand()%getmaxx();

y=rand()%getmaxy();

putpixel(x,y,RED);

delay(500);

cleardevice();

getch();

closegraph();

return 0;

_______________________________

Digital clock

_______________________________

#include<conio.h>

#include<graphics.h>

#include<dos.h>

#include<time.h>

#include<string.h>

int main()

int gd=DETECT, gm;

int midx,midy;

long current_time;

char timestr[256];

initgraph(&gd,&gm, "C:\\Turboc3\\BGI");

midx=getmaxx()/2;
midy=getmaxy()/2;

while(!kbhit())

cleardevice();

setcolor(WHITE);

setfillstyle(SOLID_FILL,WHITE);

rectangle(midx - 250, midy - 40, midx + 250, midy + 40);

floodfill(midx, midy, WHITE);

current_time = time(NULL);

strcpy(timestr, ctime(&current_time));

setcolor(RED);

settextjustify(CENTER_TEXT, CENTER_TEXT);

settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);

moveto(midx, midy);

outtext(timestr);

delay(1000);

getch();

closegraph();

return 0;

S-ar putea să vă placă și