Computer Graphics
Computer Graphics
Computer Graphics
Science and Application
Experiment No. 1
Study about computer graphics library and draw a hut by using it.
Ans:
#include <graphics.h>
#include <stdio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
getch();
closegraph();
return 0;
}
Experiment No.2
1 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
2 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
getch();
closegraph();
return 0;
}
Experiment No.3
putpixel(x, y, WHITE);
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
3 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
getch();
closegraph();
return 0;
}
Experiment No.4
while (x <= y) {
putpixel(xc + x, yc + y, WHITE);
putpixel(xc - x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc + y, yc + x, WHITE);
putpixel(xc - y, yc + x, WHITE);
putpixel(xc + y, yc - x, WHITE);
putpixel(xc - y, yc - x, WHITE);
if (p < 0) {
4 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
p += 4 * x + 6;
} else {
p += 4 * (x - y) + 10;
y--;
}
x++;
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
getch();
closegraph();
return 0;
}
Experiment No.5
5 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
getch();
closegraph();
return 0;
}
Experiment No.6
void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
6 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
7 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
x3 += tx;
y3 += ty;
getch();
closegraph();
return 0;
}
Experiment No.7
void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
getch();
closegraph();
return 0;
}
Experiment No.8
#include <stdio.h>
9 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
void scaleTriangle(float x[], float y[], float z[], float sx, float sy, float sz) {
x[i] *= sx;
y[i] *= sy;
z[i] *= sz;
int main() {
10 Huzefa Zeenwala
Department of Computer
Computer Graphics
Science and Application
// Apply scaling
return 0;
11 Huzefa Zeenwala