CGR
CGR
CGR
B.scaling
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2;
int sx,sy;clrscr();
printf("\n Enter the x,y coordinates of 2 line end points: ");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\n Original line before scaling: ");
line(x1,y1,x2,y2);
printf("\n Enter the scaling factor: ");
scanf("%d%d",&sx,&sy);
x1=x1*sx;
y1=y1*sy;
x2=x2*sx;
y2=y2*sy;
printf("\n Line after scaling");
setcolor(RED);
line(x1,y1,x2,y2);
getch();
closegraph();
}
B.y shear
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2,sh_y;
clrscr();
printf("\nEnter the coordinates of rectangle:");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
initgraph(&gd,&gm,"C://turboc3//bgi");
rectangle(x1,y1,x2,y2);
printf("\nEnter the x shear factor:");
scanf("%d",&sh_y);
y1=y1+sh_y*x1;
x1=x1;
y2=y2+sh_y*x2;
x2=x2;
printf("\nRctangle after shering:");
rectangle(x1,y1,x2,y2);
getch();
closegraph();
}
16.bezier curve
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
void bezier (int x[4], int y[4])
{
int gd=DETECT,gm;
int i;
double t;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
for (t=0.0;t<1.0;t+=0.0005)
{
double xt=pow(1-t,3)*x[0]+3*t*pow(1-t,2)*x[1]+3*pow(t,2)*(1-t)*x[2]+pow(t,3)*x[3];
double yt=pow(1-t,3)*y[0]+3*t*pow(1-t,2)*y[1]+3*pow(t,2)*(1-t)*y[2]+pow(t,3)*y[3];
putpixel(xt,yt,WHITE);
delay(10);
}
for(i=0;i<4;i++)
putpixel(x[i],y[i],YELLOW);
getch();
closegraph();
return;
}
void main()
{
int x[4],y[4];
int i;
printf("Enter the x- and y-coordinates of the four control points.\n");
for(i=0;i<4;i++)
scanf("%d%d",&x[i],&y[i]);
bezier(x,y);
}