Вы находитесь на странице: 1из 51

PRINT A TEXT USING GRAPHIC FUNCTIONS

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gd=DETECT,gm,errorcode;
int y=0,x=0;
int i;
char msg[80];
initgraph(&gd,&gm,"");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("Graphics error %s\n",grapherrormsg(errorcode));
printf("Press any key to halt");
getch();
exit(1);
}

for(i=1;i<=6;i++)
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,i);
sprintf(msg,"Text");
outtextxy(x,y,msg);
y+=textheight(msg);
x+=textwidth(msg);
}
getch();
closegraph();
}
OUTPUT:-

Text
Text
Text
Text
Text
Text
DRAW A HOUSE USING GRAPHIC FUNCTIONS

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

void main()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax;
int midx, midy;
int radius = 10;

/* initialize graphics and local variables */


initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}

setcolor(getmaxcolor());
xmax = getmaxx();
ymax = getmaxy();

/* draw a diagonal line */

line(150,150,400,150);
line(150,300,400,300);
line(150,150,150,300);
line(400,150,400,300);
line(150,150,275,50);

line(400,150,275,50);
line(275,50,500,50);

line(400,150,625,150);
line(500,50,625,150);
line(625,150,625,300);
line(400,300,625,300);
//door
line(250,300,250,250);
line(300,300,300,250);
line(250,250,300,250);
line(250,300,275,290);
line(250,250,275,260);
line(275,290,275,260);

//window
line(450,200,550,200);
line(450,250,550,250);
line(450,200,450,250);
line(550,200,550,250);
line(450,225,550,225);
line(500,200,500,250);
circle(275,100,15);
/* clean up */
getch();
closegraph();
}
OUTPUT:-
DRAW A BOAT USING GRAPHIC FUNCTIONS
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gd,gm;
int x1=100,y1=250,x2=150,y2=400,x3=400,y3=400,x4=450,y4=250;
int a1=150,b1=100,a2=180,b2=250;
int c1=180,d1=120,c2=210,d2=120,c3=180,d3=150;
int e1=180,f=300,e2=275,e3=370;
int i,j=10,r=10;
clrscr();
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x4,y4);
line(x4,y4,x1,y1);
rectangle(a1,b1,a2,b2);
line(c1,d1,c2,d2);
line(c2,d2,c3,d3);
circle(e1,f,r);
circle(e2,f,r);
circle(e3,f,r);
printf("Press any key to make the boat moving");
getch();
for(i=1;i<=10;i++)
{
cleardevice();
line(x1+j,y1,x2+j,y2);
line(x2+j,y2,x3+j,y3);
line(x3+j,y3,x4+j,y4);
line(x4+j,y4,x1+j,y1);
rectangle(a1+j,b1,a2+j,b2);
line(c1+j,d1,c2+j,d2);
line(c2+j,d2,c3+j,d3);
circle(e1+j,f,r);
circle(e2+j,f,r);
circle(e3+j,f,r);
delay(500);
j=j+10;
}
getch();
closegraph();
}
OUTPUT:-
Press any key to move the boat
DRAW A LINE USING DDA ALGORITHM
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>
#define ROUND(a)((int)(a+0.5))
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xa,xb,ya,yb;
// int y=0,x=0,i;
char msg[25];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */


errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
printf("Enter the value for x1,y1:\n");
scanf("%d%d",&xa,&ya);
printf("Enter the value for x2,y2:\n");
scanf("%d%d",&xb,&yb);
linedda(xa,ya,xb,yb);
getch();
closegraph();
return 0;
}

void linedda(int xa,int ya,int xb,int yb)


{
int dx=xb-xa,dy=yb-ya,steps,k;
float xincr,yincr,x=xa,y=ya;
if(abs(dx)>abs(dy))
steps=abs(dy);
else
steps=abs(dy);
xincr=dx/(float)steps;
yincr=dy/(float)steps;
putpixel(ROUND(x),ROUND(y),GREEN);
for(k=0;k<steps;k++)
{
x+=xincr;
y+=yincr;
putpixel(ROUND(x),ROUND(y),GREEN);
}
}
OUTPUT:-

Enter the value for x1,y1:


100
100
Enter the value for x2,y2:
250
300
DRAW A LINE USING BRESENHAM ALGORITHM
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>

void main()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xa,xb,ya,yb,x,y;
char msg[25];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */


errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
printf("Enter the x1 and y1 value:\n");
scanf("%d%d",&xa,&ya);
printf("Enter the x2 and y2 value:\n");
scanf("%d%d",&xb,&yb);
linebres(xa,ya,xb,yb);
getch();
closegraph();
}

void linebres(int xa,int ya,int xb,int yb)


{
int dx=abs(xa-xb),dy=abs(ya-yb);
int p=2*dy-dx;
int twody=2*dy,twodxdy=2*(dy-dx);
int x,y,xend;
if(xa>xb)
{
x=xb;y=yb;xend=xa;
}
else
{
x=xa;y=ya;xend=xb;
}
putpixel(x,y,YELLOW);
while(x<xend)
{
x++;
if(p<0)
p+=twody;
else
{
y++;
p+=twodxdy;
}
putpixel(x,y,YELLOW);
}
}
OUTPUT:-

Enter the x1 and y1 value:


100
100
Enter the x2 and y2value:
250
300
DRAW A CIRCLE USING MIDPOINT ALGORITHM

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

void main()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int x1,x2,x3,x4,xc,yc,r,y1,y2;
char msg[15];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
printf("Enter the value for xc,yc,r:");
scanf("%d%d%d",&xc,&yc,&r);
circlemidpoint(xc,yc,r);
getch();
closegraph();
}
void circlemidpoint(int xc,int yc,int r)
{
int x=0,y=r,p=1-r;
void circleplotpoints(int,int,int,int);
circleplotpoints(xc,yc,x,y);
while(x<y)
{
x++;
if(p<0)
p+=2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
circleplotpoints(xc,yc,x,y);
}
}
void circleplotpoints(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,YELLOW);
putpixel(xc-x,yc+y,YELLOW);
putpixel(xc+x,yc-y,GREEN);
putpixel(xc-x,yc-y,GREEN);
putpixel(xc+y,yc+x,GREEN);
putpixel(xc-y,yc+x,RED);
putpixel(xc+y,yc-x,RED);
putpixel(xc-y,yc-x,RED);
}
OUTPUT:-

Enter the value for xc, yc, r:


250
150
125
LINE CLIPPING USING COHEN SUTHERLAND ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define FALSE 0
#define TRUE 1
#define LEFTEDGE 0x1
#define RIGHTEDGE 0x2
#define TOPEDGE 0x8
#define BOTTOMEDGE 0x4
#define INSIDE(a) (!a)
#define REJECT(a,b) (a&b)
#define ACCEPT(a,b) (!(a|b))

unsigned char encode(int x,int y,int minx,int maxx,int miny,int maxy)


{
unsigned char code=0X00;
if(x<minx)
code=code|LEFTEDGE;
if(x>maxx)
code=code|RIGHTEDGE;
if(y<miny)
code=code|BOTTOMEDGE;
if(y>maxy)
code=code|TOPEDGE;
return(code);
}
void swappts(int *x1,int *y1,int *x2,int *y2)
{
int tx,ty;
tx=*x1;
ty=*y1;
*x1=*x2;
*y1=*y2;
*x2=tx;
*y2=ty;
}
void swapcode(unsigned char *c1,unsigned char *c2)
{
unsigned char temp;
temp=*c1;
*c1=*c2;
*c2=temp;
}
void clipline(int minx,int maxx,int miny,int maxy,int x1,int y1,int x2,int y2)
{
unsigned char code1,code2;
int done=FALSE;
int draw=FALSE;
float m;
while(!done)
{
code1=encode(x1,y1,minx,maxx,miny,maxy);
code2=encode(x2,y2,minx,maxx,miny,maxy);
if(ACCEPT(code1,code2))
{
done=TRUE;
draw=TRUE;
}
else if(REJECT(code1,code2))
done=TRUE;
else
{
if(INSIDE(code1))
{
swappts(&x1,&y1,&x2,&y2);
swapcode(&code1,&code2);
}
if(x2!=x1)
m=(y2-y1)/(x2-x1);
if(code1&LEFTEDGE)
{
y1+=(minx-x1)*m;
x1=minx;
}
else if(code1&RIGHTEDGE)
{
y1+=(maxx-x1)*m;
x1=maxx;
}
else if(code1&BOTTOMEDGE)
{
if(x2!=x1)
x1+=(miny-y1)/m;
y1=miny;
}
else if(code1&TOPEDGE)
{
if(x2!=x1)
x1+=(maxy-y1)/m;
y1=maxy;
}
}
}
if(draw)
line(x1,y1,x2,y2);
}

void main()
{
int x1,x2,y1,y2,minx,miny,maxx,maxy;
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
printf("Enter the minimum and maximum values of x:");
scanf("%d%d",&minx,&maxx);
printf("Enter the minimum and maximum values of y: ");
scanf("%d%d",&miny,&maxy);
printf("Enter the first enpoint of line: ");
scanf("%d%d",&x1,&y1);
printf("Enter the second endpoint of line: ");
scanf("%d%d",&x2,&y2);
printf("BEFORE CLIPPING");
rectangle(minx,maxy,maxx,miny);
line(x1,y1,x2,y2);
getch();
clrscr();
printf("AFTER CLIPPING");
rectangle(minx,maxy,maxx,miny);
clipline(minx,maxx,miny,maxy,x1,y1,x2,y2);
getch();
closegraph();
}
OUTPUT:-

Enter the minimum and maximum values of x: 300 400

Enter the minimum and maximum values of y: 300 400

Enter the first endpoint of line: 275 300

Enter the second endpoint of line: 350 420

BEFORE CLIPPING

AFTER CLIPPING
LINE CLIPPING USING LIANG BARSKY ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#define ROUND(a)((int)(a+0.5))
int cliptest(float p,float q,float *u1,float *u2)
{
float r;
int retval=1;
if(p<0.0)
{
r=q/p;
if(r>*u2)
retval=0;
if(r>*u1)
*u1=r;
}
else if(p>0.0)
{
r=q/p;
if(r<*u1)
retval=0;
if(r<*u2)
*u2=r;
}
else if(q<0.0)
retval=0;
return(retval);
}
void clipline(int minx,int miny,int maxx,int maxy,int x1,int y1,int x2,int y2)
{
float u1=0.0,u2=1.0,dx=x2-x1,dy;
if(cliptest(-dx,x1-minx,&u1,&u2))
if(cliptest(dx,maxx-x1,&u1,&u2))
{
dy=y2-y1;
if(cliptest(-dy,y1-miny,&u1,&u2))
if(cliptest(dy,maxy-y1,&u1,&u2))
{
if(u2<1.0)
{
x2=x1+u2*dx;
y2=y1+u2*dy;
}
if(u1>0.0)
{
x1+=u1*dx;
y1+=u1*dy;
}
line(x1,y1,x2,y2);
}
}
}
void main()
{
int gdriver=DETECT,gmode,x1,y1,x2,y2,minx,miny,maxx,maxy;
initgraph(&gdriver,&gmode,"");
clrscr();
printf("Enter the min & max x values: ");
scanf("%d %d",&minx,&maxx);
printf("Enter the min & max y values: ");
scanf("%d %d",&miny,&maxy);
printf("Enter the first endpoint: ");
scanf("%d %d",&x1,&y1);
printf("Enter the second endpoint: ");
scanf("%d %d",&x2,&y2);
clrscr();
printf("Before Clipping");
line(x1,y1,x2,y2);
rectangle(minx,maxy,maxx,miny);
getch();
clrscr();
printf("After Clipping");
clipline(minx,miny,maxx,maxy,x1,y1,x2,y2);
rectangle(minx,maxy,maxx,miny);
getch();
}
OUTPUT:-

Enter the min & max x values:: 300 400

Enter the min & max x values:: 300 400

Enter the first endpoint : 275 300

Enter the second endpoint : 350 420

Before Clipping

After Clipping
2 DIMENSIONAL ROTATION

#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
float px[10],py[10],tx[10],ty[10];
void disp1();
void disp2();
void translation();
void scaling();
void rotation();
int vertices;
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");
if(graphresult()!=grOk)
{
printf("Graphics error");
getch();
return;
}
printf("Enter number of vertices : ");
scanf("%d",&vertices);
printf("Enter the x and y coordinates : ");
for(i=0;i<vertices;i++)
{
scanf("%f%f",&px[i],&py[i]);
}
disp1();
rotation();
disp2();
getch();
return;
}
void disp1()
{
int i;
for(i=0;i<vertices-1;i++)
{
line(px[i],py[i],px[i+1],py[i+1]);
line(px[vertices-1],py[vertices-1],px[0],py[0]);
}
}
void disp2()
{
int i;
for(i=0;i<vertices-1;i++)
{
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx[vertices-1],ty[vertices-1],tx[0],ty[0]);
}
}
void rotation()
{
float a,rx,ry,dir,s;
int i;
printf("Enter the rotation angle : ");
scanf("%f",&a);
printf("Enter the rotation point coordinates : ");
scanf("%f%f",&rx,&ry);
printf("Enter the direction of rotation 1 for clockwise and 2 for anticlockwise:");
scanf("%f",&dir);
if(dir==1)
s=1;
else
s=-1;
for(i=0;i<vertices;i++)
{
tx[i]=(rx + (px[i]-rx)*cos(a) - (py[i]-ry)*sin(a)*s);
ty[i]=(ry + (px[i]-rx)*sin(a)*s + (py[i]-ry)*cos(a));
}
getch();
}
2 DIMENSIONAL ROTATION

OUTPUT:-

Enter the number of vertices:3

Enter the coordinate 1: 100 200

Enter the coordinate 2: 200 200

Enter the coordinate 3: 200 200

Enter the rotation angle: 90

Enter the rotation point: 200 200

Enter the direction (1.Clockwise 2.Anti Clockwise) : 1


2 DIMENSIONAL SCALING
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
int px[10],py[10],tx[10],ty[10];
void disp1();
void disp2();
void scaling();
int i,n=0;
void main()
{
/*reqest auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */


errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}

setcolor(getmaxcolor());
printf("\n\n Enter the no of vertics:");
scanf("%d",&n );
printf("\n\nEnter the value for coordinate:");
for(i=0;i<n;i++)
{
scanf("%d",&px[i]);
scanf("%d",&py[i]);
}
clrscr();
disp1();
scaling();
clrscr();
disp2();
getch();
closegraph();
}
void disp1()
{
for(i=0;i<n-1;i++)
line(px[i],py[i],px[i+1],py[i+1]);
line(px[n-1],py[n-1],px[0],py[0]);
getch();
}
void disp2()
{
for(i=0;i<n-1;i++)
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx[n-1],ty[n-1],tx[0],ty[0]);
getch();
}
void scaling()
{
int sx,sy;
printf("Enter the scaling vector:");
scanf("%d %d",&sx,&sy);
for(i=0;i<n;i++)
{
tx[i]=px[i]*sx;
ty[i]=py[i]*sy;
}
}
2-DIMENSIONAL SCALING

OUTPUT:

Enter the number of vertices: 3


Enter the x and y coordinates : 100
150
150
150
150
100
Enter scale factors (2 values ) :
2
2
2 DIMENSIONAL TRANSLATION
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
int px[10],py[10],tx[10],ty[10];
void disp1();
void disp2();
void translation();
int i,n=0;
void main()
{
/*reqest auto detection */
int gdriver = DETECT, gmode, errorcode;

/* initialize graphics and local variables */


initgraph(&gdriver, &gmode, "");

/* read result of initialization */


errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
setcolor(getmaxcolor());
printf("\n\n Enter the no of vertics:");
scanf("%d",&n );
printf("\n\nEnter the value for coordinate:");
for(i=0;i<n;i++)
{
scanf("%d",&px[i]);
scanf("%d",&py[i]);
}
clrscr();
disp1();
translation();
clrscr();
disp2();
getch();
closegraph();
}
void disp1()
{
for(i=0;i<n-1;i++)
line(px[i],py[i],px[i+1],py[i+1]);
line(px[n-1],py[n-1],px[0],py[0]);
getch();
}
void disp2()
{
for(i=0;i<n-1;i++)
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx[n-1],ty[n-1],tx[0],ty[0]);
getch();
}
void translation()
{
int dx,dy;
printf("Enter the translation vector:");
scanf("%d %d",&dx,&dy);
for(i=0;i<n;i++)
{
tx[i]=px[i]+dx;
ty[i]=py[i]+dy;
}
}
2 DIMENSIONAL TRANSLATION

OUTPUT:-

Enter the number of vertices:3

Enter the coordinate 1: 100 200

Enter the coordinate 2: 200 200

Enter the coordinate 3: 200 200

Enter the translation vector: 50 50


3 DIMENSIONAL TRANSLATION
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
float px[10],py[10],tx[10],ty[10],tx2[10],ty2[10],px2[10],py2[10];
void disp1();
void disp2();
void translation();
float depth,vertices;
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");
if(graphresult()!=grOk)
{
printf("Graphics error");
getch();
return;
}
printf("Enter number of vertices : ");
scanf("%f",&vertices);
printf("Enter the depth value : ");
scanf("%f",&depth);
printf("Enter the x and y coordinates : ");
for(i=0;i<vertices;i++)
{
scanf("%f%f",&px[i],&py[i]);
px2[i]=px[i]+depth;
py2[i]=py[i]+depth;
}
disp1();
translation();
disp2();
getch();
}
void disp1()
{
int i;
for(i=0;i<vertices-1;i++)
{
line(px[i],py[i],px[i+1],py[i+1]);
line(px2[i],py2[i],px2[i+1],py2[i+1]);
}
line(px[vertices-1],py[vertices-1],px[0],py[0]);
line(px2[vertices-1],py2[vertices-1],px2[0],py2[0]);
for(i=0;i<vertices;i++)
line(px[i],py[i],px2[i],py2[i]);
}
void disp2()
{
int i;
for(i=0;i<vertices-1;i++)
{
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx2[i],ty2[i],tx2[i+1],ty2[i+1]);
}
line(tx[vertices-1],ty[vertices-1],tx[0],ty[0]);
line(tx2[vertices-1],ty2[vertices-1],tx2[0],ty2[0]);
for(i=0;i<vertices;i++)
line(tx[i],ty[i],tx2[i],ty2[i]);
return;
}
void translation()
{
float dx,dy,i;
printf("Enter the translation value ( 2 values ) : ");
scanf("%f%f",&dx,&dy);
for(i=0;i<vertices;i++)
{
tx[i]=px[i]+dx;
ty[i]=py[i]+dy;
tx2[i]=dx+px2[i];
ty2[i]=dy+py2[i];
}
}
3-DIMENSIONAL TRANSLATION

OUTPUT:

Enter the number of vertices: 3


Enter the depth value : 10
Enter the x and y coordinates : 100
200
200
200
200
100
3 DIMENSIONAL SCALING
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
float px[10],py[10],tx[10],ty[10],tx2[10],ty2[10],px2[10],py2[10];
void disp1();
void disp2();
void scaling();
float depth,vertices;
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");
if(graphresult()!=grOk)
{
printf("Graphics error");
getch();
return;
}
printf("Enter number of vertices : ");
scanf("%f",&vertices);
printf("Enter the depth value : ");
scanf("%f",&depth);
printf("Enter the x and y coordinates : ");
for(i=0;i<vertices;i++)
{
scanf("%f%f",&px[i],&py[i]);
px2[i]=px[i]+depth;
py2[i]=py[i]+depth;
}
disp1();
scaling();
disp2();
getch();
return;
}
void disp1()
{
int i;
for(i=0;i<vertices-1;i++)
{
line(px[i],py[i],px[i+1],py[i+1]);
line(px2[i],py2[i],px2[i+1],py2[i+1]);
}
line(px[vertices-1],py[vertices-1],px[0],py[0]);
line(px2[vertices-1],py2[vertices-1],px2[0],py2[0]);
for(i=0;i<vertices;i++)
line(px[i],py[i],px2[i],py2[i]);
}
void disp2()
{
int i;
for(i=0;i<vertices-1;i++)
{
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx2[i],ty2[i],tx2[i+1],ty2[i+1]);
}
line(tx[vertices-1],ty[vertices-1],tx[0],ty[0]);
line(tx2[vertices-1],ty2[vertices-1],tx2[0],ty2[0]);
for(i=0;i<vertices;i++)
line(tx[i],ty[i],tx2[i],ty2[i]);
return;
}
void scaling()
{
float sx,sy,sz,i,dep;
printf("Enter the scale factors(3 values): ");
scanf("%f%f%f",&sx,&sy,&sz);
for(i=0;i<vertices;i++)
{
tx[i]=px[i]*sx;
ty[i]=py[i]*sy;
dep=depth*sz;
tx2[i]=tx[i]+dep;
ty2[i]=ty[i]+dep;
}
}
3-DIMENSIONAL SCALING

OUTPUT:

Enter the number of vertices: 3


Enter the depth value : 15
Enter the x and y coordinates : 100
50
50
50
50
100
Enter the scale factors ( 3 values ) : 2
2
2
3 DIMENSIONAL ROTATION
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
float px[10],py[10],tx[10],ty[10],tx2[10],ty2[10],px2[10],py2[10];
void disp1();
void disp2();
void rotation();
float depth,vertices;
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");
if(graphresult()!=grOk)
{
printf("Graphics error");
getch();
return;
}
printf("Enter number of vertices : ");
scanf("%f",&vertices);
printf("Enter the depth value : ");
scanf("%f",&depth);
printf("Enter the x and y coordinates : ");
for(i=0;i<vertices;i++)
{
scanf("%f%f",&px[i],&py[i]);
px2[i]=px[i]+depth;
py2[i]=py[i]+depth;
}
disp1();
rotation();
disp2();
getch();
}
void disp1()
{
int i;
for(i=0;i<vertices-1;i++)
{
line(px[i],py[i],px[i+1],py[i+1]);
line(px2[i],py2[i],px2[i+1],py2[i+1]);
}
line(px[vertices-1],py[vertices-1],px[0],py[0]);
line(px2[vertices-1],py2[vertices-1],px2[0],py2[0]);
for(i=0;i<vertices;i++)
line(px[i],py[i],px2[i],py2[i]);
}
void disp2()
{
int i;
for(i=0;i<vertices-1;i++)
{
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx2[i],ty2[i],tx2[i+1],ty2[i+1]);
}
line(tx[vertices-1],ty[vertices-1],tx[0],ty[0]);
line(tx2[vertices-1],ty2[vertices-1],tx2[0],ty2[0]);
for(i=0;i<vertices;i++)
line(tx[i],ty[i],tx2[i],ty2[i]);
}
void rotation()
{
float i,an,rx,ry,dir,s,a;
printf("Enter the rotation angle : ");
scanf("%f",&an);
printf("Enter the rotation point : ");
scanf("%f%f",&rx,&ry);
printf("Enter the dircetion of rotation [1 for clockwise / 2 for anticlockwise] : ");
scanf("%f",&dir);
if(dir==1)
s=1;
else
s=-1;
a=an*3.14/180;
for(i=0;i<vertices;i++)
{
tx[i]=rx+(px[i]-rx)*cos(a) - (py[i]-ry)*sin(a)*s;
ty[i]=ry+(px[i]-rx)*sin(a)*s + (py[i]-ry)*cos(a);
tx2[i]=rx+(px2[i]-rx)*cos(a) - (py2[i]-ry)*sin(a)*s;
ty2[i]=ry+(px2[i]-rx)*sin(a)*s + (py2[i]-ry)*cos(a);
}
}
3-DIMENSIONAL ROTATION

OUTPUT:

Enter the number of vertices: 3


Enter the depth value : 20
Enter the x and y coordinates : 100
150
150
150
150
100
Enter the rotation angle: 30
Enter the rotation point : 50
50
Enter the direction of rotation (1-Clockwise, 2-Anticlockwise) : 1
DEVELOPING AN ANIMATION USING GUIDE LAYER TECHNIQUE

Step 1 : Create a new Flash document

Step 2 : Choose View > Grid > Show Grid

Step 3 : In the Timeline, select Frame 1

Step 4 : In Frame 1, use the oval tool to create a circle that represents a ball

Step 5 : In the timeline, select Frame 20, and choose Insert > Frame

Step 6 : In the Timeline, select Frame 1

Step 7 : Choose Insert > Create Motion Tween

Step 8 : In the timeline, position in Frame 5, drag the ball to a new position

Step 9 : Do the same for Frame 10, 15 and 20

Step 10 : At the bottom of the timeline, click the add guide layer button

Step 11 : With the motion guide layer selected, use the pencil tool to draw a line on the stage
showing the path

Step 12 : In Frame 1, drag the circle to position over the beginning of the motion path

Step 13 : In Frame 20, drag the circle to reposition it over the end of the motion path

Step 14 : Select the first and select Control > Play

Step 15 : Stop
GUIDE LAYER ANIMATION

Input

Output
DEVELOPING AN ANIMATION USING ONION SKIN TECHNIQUE

Step 1 : Create a new Flash document

Step 2 : Choose View > Grid > Show Grid

Step 3 : In the Timeline, select Frame 1

Step 4 : In the Tool Box, select the oval tool

Step 5 : Near the top of the edge, draw a circle

Step 6 : In the Timeline, select Frame 2

Step 7 : Choose Insert > Timeline > Key frame

Step 8 : Select the ball and reposition it at the bottom of the previous ball

Step 9 : Similarly create some more key frames and do the same in such a way that balls are
positioned in a wave form

Step 10 : In the status bar of the timeline, check the onion skin button

Step 11 : In the timeline, check and modify onion marker button. Select Onion 2, Onion 5 or Onion
all

Step 12 : Select Control > Play

Step 13 : Stop
OUTPUT:-

ANIMATION USING ONION SKIN METHOD


DEVELOPING AN ANIMATION USING MASKING OF LAYER

Step 1 : Create a new Flash document

Step 2 : Insert one more layer, rather than the default layer.

Step 3 : Rename the top layer to "Mask" and the layer below that to "background".

Step 4 : Import your picture to the "background" layer.

Step 5 : Using Oval tool from your tool box, draw a circle in your "Mask" layer and delete it's
border.

Step 6 : Drag the circle to one end of your picture.

Step 7 : Now go to"frame 40" of your "Mask" layer and press "F6" to insert a new keyframe.

Step 8 : Now go to "frame 40" of your "background" layer and press "F5" to insert frames, so that
your background image is available all through your mask.

Step 9 : Select "frame 40" of your "Mask" layer, that is your new keyframe, Keeping the playhead
on "frame 40" of "Mask" layer, drag the circle to other end of your picture.

Step 10 : Now go back to "frame 1" of your "Mask" layer, keeping the playhead on "frame 1" of
your "Mask" layer, select Shape tween in your properties window.

Step 11 : Right click on the "Mask" layer (the area where you named the layer not where the frames
exist) and select Mask.

Step 12 : select Control > Play

Step 13 : Stop
OUTPUT:-
IMAGE EDITING USING CROPING

Step 1 : Create a new Photoshop document

Step 2 : Import a picture on to the document

Step 3 : Select the Crop tool

Step 4 : Drag over the part of the image you want to keep to create a marquee.

Step 5 : To complete the crop, press Enter or double-click inside the cropping marquee.

Step 6 : Stop
OUTPUT:-
IMAGE EDITING USING CLONING

Step 1 : Create a new Photoshop document

Step 2 : Import a picture on to the document

Step 3 : Select the Clone Stamp Tool from the toolbox.

Step 4 : On the Options bar across the top of the screen, select the brush size and type of brush you
want to use

Step 5 : Move the cursor over the image to the area you would like to reproduce elsewhere.

Step 6 : Hold down the Alt key and click to select the area to clone from.

Step 7 : When you release the mouse, the brush will appear on the image in the shape of the brush
selected. Crosshairs will appear over the area to be reproduced and move with the brush.

Step 8 : Click repeatedly or drag the mouse to reproduce the pattern.

Step 9 : Stop
OUTPUT:-

Вам также может понравиться