Lab Assessment:- Complex Problems
Student Name: Rahul UID: 22BCS10755
Branch: BE-CSE Section/Group: 22BCS_IoT_610(B)
Semester: 6th. Date of Performance: 03/04/25
Subject Name: Computer Graphics Subject Code: 22CSH-352
Problem-1
1. Problem Statement: Implement a ray-tracing renderer to simulate realistic lighting effects,
including shadows and reflections.
2. Aim: To simulate realistic light behavior in computer graphics.
3. Objective: Understand ray tracing concepts, including intersections, light reflection, and
refraction for photorealistic rendering.
4. Implementation/Code:
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
void drawSphere(int x, int y, int r)
{ setcolor(WHITE);
circle(x, y, r);
floodfill(x, y, WHITE);
}
int main() {
int gd = DETECT, gm, x, y, r;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
cout<<"Enter sphere center (x y) and radius: ";
cin>>x>>y>>r);
drawSphere(x, y, r);
setcolor(LIGHTGRAY);
line(x - 50, y - 50, x + 100, y - 100);
circle(x + 100, y - 100, 10);
getch();
closegraph();
return 0;
}
5. Output:
6. Learning Outcomes:
• Understanding ray tracing concepts such as light interaction, reflection and shadows.
• Learnt to simulate light behavior in a 2D/3D environment.
• Learnt using primitive graphics functions such as circle(), line().
• Developed an understanding of light-source positioning for realistic rendering.
Problem-2
1. Problem Statement: Develop a physics-based particle system to simulate explosions or
fire effects.
2. Aim: To create dynamic and interactive particle effects using physics principles.
3. Objective: Learn to apply forces, gravity, and randomness to particles for realistic
animations.
4. Implementation/Code:
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
void fireEffect(int count) {
for (int i = 0; i < count; i++)
{ int x = rand() % 640;
int y = rand() % 480;
putpixel(x, y, RED);
delay(10);
}
}
int main() {
int gd = DETECT, gm, count;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
cout<<"Enter the number of fire particles: ";
cin>>count;
while (!kbhit())
{ fireEffect(count
);
}
closegraph();
return 0;
}
5. Output:
6. Learning Outcomes:
• Understanding randomization and its role in creating natural-looking physics effects.
• Learnt to apply particle system concepts for simulating fire, explosions and other effects.
• Implement basic physics principles like gravity and velocity in graphics.
• Gain hands-on experience with pixel manipulation (putpixel()) for real-time effects.
Problem-3
1. Problem Statement: Create a 3D maze generator and solver, visualized using perspective
transformations and real-time rendering.
2. Aim: To generate and navigate complex 3D environments.
3. Objective: Implement maze generation algorithms and explore pathfinding techniques in 3D
space.
4. Implementation/Code:
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
void drawMaze(int size) {
for (int i = 50; i < size; i += 50)
{ line(i, 50, i, size);
line(50, i, size, i);
}
}
int main() {
int gd = DETECT, gm, size;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
cout<<"Enter maze grid size (suggested 400 for full screen): ";
cin>>size;
drawMaze(size);
getch();
closegraph();
return 0;
}
5. Output:
6. Learning Outcomes:
• Understanding maze generation algorithms ( recursive division, DFS).
• Learnt grid-based rendering techniques to generate structures environments.
• Explore how perspective transformations impact visual representation.
• Gain experience with pathfinding techniques for AI-based navigation.
Problem-4
1. Problem Statement: Buildadynamicwatersimulationsystemthatusesparticle or grid-based
methods to depict fluid motion.
2. Aim: To simulate realistic water motion using computational techniques.
3. Objective: Understand fluid dynamics principles and their implementation in real-time
simulations.
4. Implementation/Code:
#include <graphics.h>
#include <math.h>
#include <conio.h>
#include <iostream.h>
void drawWaves(int amplitude)
{ for (int i = 0; i < getmaxx(); i++)
{
int y = 200 + amplitude * sin(i * 0.1);
putpixel(i, y, BLUE);
}
}
int main() {
int gd = DETECT, gm, amplitude;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
cout<<"Enter wave amplitude (suggested between 10-50): ";
cin>>amplitude;
drawWaves(amplitude);
getch();
closegraph();
return 0;
}
5. Output:
6. Learning Outcomes
• Understanding how trigonometric functions (sin, cos) are used in graphics.
• Learnt to simulate fluid motion using mathematical functions.
• Developed an understanding of frame-by-frame rendering for dynamic visuals.
• Learnt to manipulate amplitude and frequency to control wave effects.
Problem-5
1. Problem Statement: Write a program to model and render a 3D fractal object such as the
Mandelbrot set or a 3D Koch snowflake.
2. Aim: To explore fractal geometry and its applications in graphics.
3. Objective: Learn iterative fractal generation techniques and visualize self- similarity
properties in 3D.
4. Implementation/Code:
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
void drawKoch(int x1, int y1, int x2, int y2, int depth)
{ if (depth == 0) {
line(x1, y1, x2, y2);
return;
}
int dx = (x2 - x1) / 3;
int dy = (y2 - y1) / 3;
int xA = x1 + dx, yA = y1 + dy;
int xB = x1 + 2 * dx, yB = y1 + 2 * dy;
int midX = (x1 + x2) / 2 + (y1 - y2) / 3;
int midY = (y1 + y2) / 2 + (x2 - x1) / 3;
drawKoch(x1, y1, xA, yA, depth - 1);
drawKoch(xA, yA, midX, midY, depth - 1);
drawKoch(midX, midY, xB, yB, depth - 1);
drawKoch(xB, yB, x2, y2, depth - 1);
}
int main() {
int gd = DETECT, gm, depth;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
cout<<"Enter recursion depth (suggested 1-4): ";
cin>>depth;
drawKoch(100, 300, 400, 300, depth);
getch();
closegraph();
return 0;
}
5. Output
6. Learning Outcomes
• Understanding the concept of fractals and their applications in computer graphics.
• Learnt recursion and iterative algorithms for fractal generation.
• Gain experience in self-similarity properties of fractals.
• Implement geometric transformations to create complex shapes.