Posts

A man walking in the rain.

Image
# include <stdio.h> # include <dos.h> # include <conio.h> # include <graphics.h> # include <stdlib.h> void rain( int x1, int y1, int x2, int y2) { int s,dx,dy,m,c= 0 ,t= 1 ; float xi,yi,x,y; dx=x2-x1; dy=y2-y1; if (abs(dx)>abs(dy)) s=abs(dx); else s=abs(dy); xi=dx/( float )s; yi=dy/( float )s; x=x1; y=y1; putpixel(x1+ 0 .5 ,y1+ 0 .5 , 9 ); for (m= 0 ;m<s;m++) { c++; x+=xi; y+=yi; if (getpixel(x,y)== 4 ) break ; if (c% 10 == 0 ) t++; putpixel(x+ 0 .5 ,y+ 0 .5 , 0 ); if (t% 2 == 0 ) putpixel(x+ 0 .5 ,y+ 0 .5 , 9 ); } } void main() { int gd=DETECT,gm=DETECT,c=- 200 ,i= 0 ,x= 40 ,l= 15 ,h= 15 ,ht= 0 ; initgraph(&gd,&gm, "" ); cleardevice(); setcolor(BROWN); line( 0 , 201 , 600 , 201 ); cont: ...

Car Movement

#include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> int scan,ascii; void getkey() { union REGS ii,oo; ii.h.ah= 0 ; int86( 22 ,&ii,&oo); scan=oo.h.ah; ascii=oo.h.al; } void car( int x, int c) { setcolor(c); line(x+ 150 , 100 ,x+ 242 , 100 ); ellipse(x+ 242 , 105 , 0 , 90 , 10 , 5 ); line(x+ 150 , 100 ,x+ 120 , 150 ); line(x+ 252 , 105 ,x+ 280 , 150 ); line(x+ 100 , 150 ,x+ 320 , 150 ); line(x+ 100 , 150 ,x+ 100 , 200 ); line(x+ 320 , 150 ,x+ 320 , 200 ); line(x+ 100 , 200 ,x+ 110 , 200 ); line(x+ 320 , 200 ,x+ 310 , 200 ); arc(x+ 130 , 200 , 0 , 180 , 20 ); arc(x+ 290 , 200 , 0 , 180 , 20 ); line(x+ 270 , 200 ,x+ 150 , 200 ); circle(x+ 130 , 200 , 17 ); circle(x+ 290 , 200 , 17 ); } void main() { int gd=DETECT,gm=DETECT,i= 0 ,c= 1 ,prev= 80 ; initgraph(&gd,&gm, "" ); cleardevice...

Car movement during Traffic Signal

#include<conio.h> #include<dos.h> #include<graphics.h> void car( int x, int c) { setcolor(c); line(x+ 150 , 100 ,x+ 242 , 100 ); ellipse(x+ 242 , 105 , 0 , 90 , 10 , 5 ); line(x+ 150 , 100 ,x+ 120 , 150 ); line(x+ 252 , 105 ,x+ 280 , 150 ); line(x+ 100 , 150 ,x+ 320 , 150 ); line(x+ 100 , 150 ,x+ 100 , 200 ); line(x+ 320 , 150 ,x+ 320 , 200 ); line(x+ 100 , 200 ,x+ 110 , 200 ); line(x+ 320 , 200 ,x+ 310 , 200 ); arc(x+ 130 , 200 , 0 , 180 , 20 ); arc(x+ 290 , 200 , 0 , 180 , 20 ); line(x+ 270 , 200 ,x+ 150 , 200 ); circle(x+ 130 , 200 , 17 ); circle(x+ 290 , 200 , 17 ); } void main() { int gd=DETECT,gm=DETECT,i=- 200 ; int ch= 'g' ; initgraph(&gd,&gm, "" ); line( 0 , 70 , 300 , 70 ); line( 450 , 70 , 630 , 70 ); line( 300 , 70 , 300 , 0 ); line( 450 , 70 , 450 , 0 ); line( 0 , 230 ...

Bouncing Ball

# include <stdio.h> # include <conio.h> # include <graphics.h> # include <dos.h> void main() { int gd=DETECT,gm=DETECT; int x,y= 0 ,j,t= 400 ,c= 1 ; initgraph(&gd,&gm, "" ); setcolor(RED); setfillstyle(SOLID_FILL,RED); for (x= 40 ;x< 602 ;x++) { cleardevice(); circle(x,y, 30 ); floodfill(x,y,RED); delay( 40 ); if (y>= 400 ) { c= 0 ; t-= 20 ; } if (y<=( 400 -t)) c= 1 ; y=y+(c? 15 :- 15 ); } getch(); }

Boundary Fill

The boundary fill algorithm fills a region with the given fill color until the given boundary color is found. Here i have used the 8-point technique to color a region. The program is using a recurssive function. The function return when the pixel to be colored is the boundary color or is already the fill color. # include <stdio.h> # include <conio.h> # include <graphics.h> void boundary_fill( int x, int y, int fcolor, int bcolor) { if ((getpixel(x,y) != fcolor) && (getpixel(x,y) != bcolor)) { putpixel(x,y,fcolor); boundary_fill(x+ 1 ,y,fcolor,bcolor); boundary_fill(x- 1 ,y,fcolor,bcolor); boundary_fill(x,y- 1 ,fcolor,bcolor); boundary_fill(x,y+ 1 ,fcolor,bcolor); boundary_fill(x+ 1 ,y- 1 ,fcolor,bcolor); boundary_fill(x+ 1 ,y+ 1 ,fcolor,bcolor); boundary_fill(x- 1 ,y- 1 ,fcolor,bcolor); boundary_fill(x- 1 ,y+ 1 ,fcolor,bcolor); } } void main() ...

Flood Fill

The flood fill algorithm replaces a current color with a new color.Here i have used the 8-point technique to color a region. The program is using a recurssive function. The function return when the pixel to be replaced is not the given old color. #include<stdio.h> #include<conio.h> #include<graphics.h> void flood_fill( int x, int y, int ncolor, int ocolor) { if (getpixel(x,y) == ocolor) { putpixel(x,y,ncolor); flood_fill(x+1,y,ncolor,ocolor); flood_fill(x+1,y-1,ncolor,ocolor); flood_fill(x+1,y+1,ncolor,ocolor); flood_fill(x,y-1,ncolor,ocolor); flood_fill(x,y+1,ncolor,ocolor); flood_fill(x-1,y,ncolor,ocolor); flood_fill(x-1,y-1,ncolor,ocolor); flood_fill(x-1,y+1,ncolor,ocolor); } } void main() { int x,y,ncolor,ocolor; clrscr(); printf( "Enter the seed point\n" ); scanf( "%d%d" ,&x,&y); printf( "Ent...

Ellipse

# include <graphics.h> # include <conio.h> # include <stdio.h> void plotpoints( int cx, int cy, int x, int y) { putpixel(cx + x, cy + y, 4 ); putpixel(cx - x, cy + y, 4 ); putpixel(cx + x, cy - y, 4 ); putpixel(cx - x, cy - y, 4 ); } void main() { int cx,cy,rx,ry; printf( "Enter the center " ); scanf( "%d%d" ,&cx,&cy); printf( "x radius : " ); scanf( "%d" ,&rx); printf( "y radius : " ); scanf( "%d" ,&ry); long rx2 = ( long )rx*rx; long ry2 = ( long )ry*ry; long trx2 = 2 *rx2; long try2 = 2 *ry2; long p,x= 0 , y=ry; long px= 0 ; long py = trx2 * y; p = ( long ) ( ( ry2 - (rx2 * ry) + ( 0 .25 * rx2) ) + 0 .5 ); int gd=DETECT,gm=DETECT; initgraph(&gd,&gm, "" ); cleardevice(); putpixel(cx,cy, 15 ); while (px<py) { ...