Posts

Showing posts with the label cusat6thsemlab

Flying Kite

Image
Program to implement a FLYING KITE using built-in functions available in the library. #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<dos.h> #include<graphics.h> #include<ctype.h> #include<math.h> void main () { int gd=DETECT,gm; int color; int x= 10 ,y= 1 ,inc_x= 10 ,inc_y= 10 ; int poly[ 10 ]; initgraph(&gd,&gm, " " ); while (!kbhit()) { x += inc_x; if (x > 200 ) inc_x = - 5 ; if (x < 0 ) inc_x = 10 ; y += inc_y; if (y > 100 ) inc_y = - 10 ; if (y < 0 ) inc_y = 10 ; cleardevice(); setcolor(WHITE); setbkcolor(BLUE); poly[ 0 ]= 100 +x; poly[ 1 ]= 50 +y; poly[ 2 ]= 140 +x; poly[ 3 ]= 100 +y; poly[ 4 ]= 100 +x; poly[ 5 ]= 155 +y; poly[ 6 ]= 60 +x; poly[ 7 ]= 100 +y; poly[ 8 ]= 100 +x; poly[ 9 ]= 50 +y; drawpoly( 5 ,poly); setfillstyle(SOLID_FILL,RED); fillpoly( 5 ,poly); setlinestyle(SOLID_LINE, 1 , 3 ); line( 100 +x...

Moving Wheel

Image
#include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> #include<dos.h> int l = 1 ; void ddaline ( int x1, int y1, int x2, int y2) { int s,dx,dy,m; 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 , 15 ); for (m = 0 ;m < s;m ++ ) { x += xi; y += yi; putpixel(x + 0.5 ,y + 0.5 , 15 ); } } void plotpoints1 ( int x, int y, int cx, int cy) { putpixel(cx + x,cy + y, 15 ); putpixel(cx - x,cy - y, 15 ); putpixel(cx - y,cy + x, 15 ); putpixel(cx + y,cy - x, 15 ); if (l % 20 == 0 ) { ddaline(cx - x,cy - y,cx + x,cy + y); ddaline(cx - y,cy + x,cx + y,cy - x); } l ++ ; } void plotpoints2 ( int x, int y, int cx, int cy) { putpixel(cx - x,cy + y, 15 ); putpixel(cx + x,cy - y, 15 ); putpixel(cx +...

Fill a bucket with water from a pipe.

# include <conio.h> # include <dos.h> # include <graphics.h> void main() { int gd=DETECT,gm=DETECT,i,j; initgraph(&gd,&gm, "" ); ellipse( 300 , 200 , 0 , 360 , 50 , 25 ); ellipse( 300 , 300 , 0 , 360 , 50 , 25 ); line( 250 , 200 , 250 , 300 ); line( 350 , 200 , 350 , 300 ); ellipse( 300 , 100 , 180 , 360 , 5 , 2 ); line( 295 , 100 , 295 , 80 ); line( 305 , 100 , 305 , 86 ); arc( 300 , 80 , 90 , 180 , 5 ); putpixel( 306 , 85 , 15 ); putpixel( 307 , 84 , 15 ); line( 308 , 84 , 630 , 84 ); line( 300 , 75 , 303 , 75 ); line( 314 , 75 , 630 , 75 ); putpixel( 304 , 74 , 15 ); putpixel( 305 , 73 , 15 ); line( 306 , 72 , 306 , 65 ); line( 311 , 72 , 311 , 65 ); putpixel( 312 , 73 , 15 ); putpixel( 313 , 74 , 15 ); pieslice( 309 , 62 , 0 , 360 , 5 ); setfillstyle(SOLID_FILL,BLUE); setcolor(BLUE); for (i= 0 ;i< 7 ;i++) { ...

To start with graphics programming

Image
Turbo C has a good collection of graphics libraries. If you know the basics of C, you can easily learn graphics programming. To start programming, let us write a small program that displays a circle on the screen. /* simple.c example 1.0 */ #include<graphics.h> #include<conio.h> void main() { int gd=DETECT, gm; initgraph(&gd, &gm, "c:\\tc\\bgi " ); circle(200,100,150); getch(); closegraph(); } To run this program, you need graphics.h header file, graphics.lib library file and Graphics driver (BGI file) in the program folder. These files are part of Turbo C package. In all our programs we used 640x480 VGA monitor. So all the programs are according to that specification. You need to make necessary changes to your programs according to your screen resolution. For VGA monitor, graphics driver used is EGAVGA.BGI. Here, initgraph() function initializes the graphics mode and clears the screen. We will study the difference betwee...

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: ...