0% found this document useful (0 votes)
26 views12 pages

GRAPHICSOUTPUT

The document contains code for 6 graphics programs in C using graphics.h: 1. A program to rotate a triangle by user input angle. 2. A word dropping program that displays a string falling letter by letter. 3. A DDA line drawing algorithm implementation. 4. A program to animate a moving car on screen. 5. A program to simulate a bouncing ball animation. 6. A point clipping program that clips points outside a clipping window.

Uploaded by

renukadevik633
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views12 pages

GRAPHICSOUTPUT

The document contains code for 6 graphics programs in C using graphics.h: 1. A program to rotate a triangle by user input angle. 2. A word dropping program that displays a string falling letter by letter. 3. A DDA line drawing algorithm implementation. 4. A program to animate a moving car on screen. 5. A program to simulate a bouncing ball animation. 6. A point clipping program that clips points outside a clipping window.

Uploaded by

renukadevik633
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

ROTATION
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
intgm;
intgd=DETECT;
int x1,x2,x3,y1,y2,y3,nx1,nx2,nx3,ny1,ny2,ny3,c;
intsx,sy,xt,yt,r;
float t;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\t\t BASIC TRANSFORMATION\n");
printf("\n\t enter the point of triangle:");
setcolor(1);
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
printf("\n enter the angle of rotation:");
scanf("%d",&r);
t=3.14*r/180;
nx1=abs(x1*cos(t)-y1*sin(t));
ny1=abs(x1*sin(t)+y1*cos(t));
nx2=abs(x2*cos(t)-y2*sin(t));
ny2=abs(x2*sin(t)+y2*cos(t));
nx3=abs(x3*cos(t)-y3*sin(t));
ny3=abs(x3*sin(t)+y3*cos(t));
line(nx1,ny1,nx2,ny2);
line(nx2,ny2,nx3,ny3);
line(nx3,ny3,nx1,ny1);
getch();
closegraph();
}
OUTPUT:
2.WORD DROPPING
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
void main()
{
intgd=DETECT,gm,i,j,k,l,x,y;
char s[100]="",s1[100]="";
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter the string:");
gets(s);
outtextxy(40,40,s);
y=50+textheight(s);
setviewport(45,y,500,400,0);
l=strlen(s);
s[l]='\0';
j=0;
for(i=0;i<=1;i++)
{
s1[j]=s[i];
if(s[i]=='\0'||s[i]=='\0')
{
for(y=50;y<=350;y+=30)
{
outtextxy(x,y,s1);
delay(100);
clearviewport();
}
x+=textwidth(s1);
for(k=0;k<j;k++)
s1[k]='\0',j=1;
}
j++;
}
getch();
}
OUTPUT:
3.DDA ALGORITHM
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,pixel;
inti,gd,gm;
printf("enter the value of x1:");
scanf("%f",&x1);
printf("enter the value of y1:");
scanf("%f",&y1);
printf("enter the value of x2:");
scanf("%f",&x2);
printf("enter the value of y2:");
scanf("%f",&y2);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
pixel=dx;
else
pixel=dy;
dx=dx/pixel;
dy=dy/pixel;
x=x1;y=y1;
i=1;
while(i<=pixel)
{
putpixel(x,y,i);
x=x+dx;
y=y+dy;
i=i+1;
delay(100);
}
getchar();
closegraph();
}
OUTPUT:
4.MOVING A CAR
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
inti,j=0,gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("press any key to move a car");
getch();
setviewport(0,0,693,440,1);
for(i=0;i<420;i=i+10,j++)
{
rectangle(50+i,275,150+i,400);
rectangle(150+i,350,200+i,400);
circle(75+i,410,10);
circle(175+i,410,10);
setcolor(j);
delay(1000);
if(i==420)
break;
clearviewport();
}
getch();
closegraph();
}
OUTPUT:
5.BOUNCING BALL

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h=>
void main()
{
intgd=DETECT,gm=DETECT;
intx,y=0,j,t=400,c=1;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
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();
}
OUTPUT:
6.POINT CLIPPING
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
intgm,gr,xcmin,ycmin,xcmax,ycmax,x,y,c;
clrscr();
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"c:\\tc\\bgi");
printf("enter the clipmin coordinate:\n");
scanf("%d%d",&xcmin,&ycmin);
printf("enter the clipmax coordinate:\n");
scanf("%d%d",&xcmax,&ycmax);
printf("enter the coordinate of the point:\n");
scanf("%d%d",&x,&y);
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"c:\\tc\\bgi");
putpixel(x,y,15);
printf("\n 1.point clipping\n 2.exit\n enter your choice:\n");
scanf("%d",&c);
rectangle(xcmin,ycmax,xcmax,ycmin);
switch(c)
{
case 1:
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"c:\\tc\\bgi");
printf("******point clipping******");
if((xcmin<x)&&(x<xcmax))
{
if((ycmin<y)&&(y<ycmax))
{
printf("the point is inside the clipwindow\n");
putpixel(x,y,15);
}
}
else
printf("the point is outside the clipwindow\n the point is clipped\n");
break;
case 2:
exit(0);
}
getch();
}
OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy