Академический Документы
Профессиональный Документы
Культура Документы
#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;
setcolor(getmaxcolor());
xmax = getmaxx();
ymax = getmaxy();
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, "");
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, "");
#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:-
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:-
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:-
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:-
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:
OUTPUT:-
OUTPUT:
OUTPUT:
OUTPUT:
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 8 : In the timeline, position in Frame 5, drag the ball to a new position
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 15 : Stop
GUIDE LAYER ANIMATION
Input
Output
DEVELOPING AN ANIMATION USING ONION SKIN TECHNIQUE
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 13 : Stop
OUTPUT:-
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 5 : Using Oval tool from your tool box, draw a circle in your "Mask" layer and delete it's
border.
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 13 : Stop
OUTPUT:-
IMAGE EDITING USING CROPING
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 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 9 : Stop
OUTPUT:-