Cgrs
Cgrs
Cgrs
scaling, and rotation about an arbitrary point) on a shape using the graphics.h library in Turbo C.
However, there are a few issues and missing parts, so I’ll correct and complete the code and provide
an explanation.
EXP 6:
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>
int main()
int i, x, y, tx, ty, sx, sy, angle=10, xmax, ymax, xmid, ymid, op;
float p1[10] = {
50, 50,
100, 50,
100, 100,
50, 100,
50, 50
int pi[10];
float b[3][3] = {
1, 0, 0,
0, 1, 0,
0, 0, 1
}; // Transformation matrix
printf("\n1 : Translation");
printf("\n2 : Rotation");
printf("\n3 : Scaling");
scanf("%d", &op);
switch(op)
case 1:
scanf("%d", &tx);
scanf("%d", &ty);
b[0][0] = 1;
b[0][1] = 0;
b[0][2] = 0;
b[1][0] = 0;
b[1][1] = 1;
b[1][2] = 0;
b[2][0] = tx;
b[2][1] = ty;
b[2][2] = 1;
break;
case 2:
scanf("%d", &angle);
b[1][2] = 0;
b[2][0] = 0;
b[2][1] = 0;
b[2][2] = 1;
break;
case 3:
scanf("%d", &sx);
scanf("%d", &sy);
b[0][0] = sx;
b[0][1] = 0;
b[0][2] = 0;
b[1][0] = 0;
b[1][1] = sy;
b[1][2] = 0;
b[2][0] = 0;
b[2][1] = 0;
b[2][2] = 1;
break;
case 4:
scanf("%d", &x);
scanf("%d", &y);
tx = x;
ty = y;
b[0][2] = 0;
b[1][2] = 0;
b[2][2] = 1;
break;
detectgraph(&gd, &gm);
setcolor(1);
setcolor(4);
for (i = 0; i < 8; i = i + 2)
line(p1[i] + xmid, ymid - p1[i + 1], xmid + p1[i + 2], ymid - p1[i + 3]);
}
for (i = 0; i < 9; i = i + 2)
a[0][0] = p1[i];
pi[i] = c[0][0];
pi[i + 1] = c[0][1];
setcolor(15);
for (i = 0; i < 8; i = i + 2)
line(xmid + pi[i], ymid - pi[i + 1], xmid + pi[i + 2], ymid - pi[i + 3]);
getch();
closegraph();
return 0;
}
Exp 7:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#include <graphics.h>
int x, y;
char code[4];
} PT;
void drawwindow();
PT setcode(PT p);
int main()
PT p1, p2;
cleardevice();
cleardevice();
getch();
getch();
p2 = setcode(p2);
switch (v)
case 0:
drawwindow();
break;
case 1:
drawwindow();
break;
case 2:
p2 = resetendpt(p2, p1);
drawwindow();
break;
getch();
closegraph();
return 0;
void drawwindow()
setcolor(RED);
setcolor(cl);
PT setcode(PT p)
PT ptemp;
if (p.y < 100)
else
ptemp.code[0] = '0';
else
ptemp.code[1] = '0';
else
ptemp.code[2] = '0';
else
ptemp.code[3] = '0';
ptemp.x = p.x;
ptemp.y = p.y;
return ptemp;
int i, flag = 0;
for (i = 0; i < 4; i++)
flag = 1;
if (flag == 0)
PT temp;
int x, y, i;
float m, k;
x = 150;
x = 450;
temp.y = k;
temp.x = x;
temp.code[i] = p1.code[i];
return temp;
y = 100;
y = 350;
temp.x = k;
temp.y = y;
temp.code[i] = p1.code[i];
return temp;
return p1;
}
Exp 8
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <process.h>
float xxx[4][2];
xxx[0][0] = x2;
xxx[0][1] = y2;
/* Bezier function */
void bezier(float xb, float yb, float xc, float yc, float xd, float yd, int n) {
if (n == 0) {
line1(xb, yb);
line1(xc, yc);
line1(xd, yd);
} else {
n = n - 1;
void igraph() {
gd = DETECT;
if (graphresult() != 0) {
exit(1);
void main() {
int i;
igraph();
/* Read two end points and two control points of the curve */
xxx[i][0] = temp1;
xxx[i][1] = temp2;
getch();
closegraph();
}
Exp9:
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
void koch(int x1, int y1, int x2, int y2, int m) {
lx = (x2 - x1) / 3;
ly = (y2 - y1) / 3;
y[0] = y1;
y[4] = y2;
xx = x[3] - x[1];
yy = y[3] - y[1];
if (m > 0) {
} else {
void main() {
int x1 = 0, x2 = 550, y1 = 0, y2 = 0;
scanf("%d", &n);
gd = DETECT;
if (graphresult() != 0) {
printf("Error initializing graphics mode\n");
exit(1);
getch();
closegraph();
}
Exp 10:
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <conio.h>
void main() {
scanf("%d", &s);
}
// Input depth for the 3D effect
printf("Depth: ");
scanf("%d", &d);
draw3d(s, x, y, d);
getch();
setcolor(14);
getch();
closegraph();
int i, j, k = 0;
}}