Phougat Sahil Merged CG
Phougat Sahil Merged CG
Experiment 4
Student Name: Sahil Phogat UID: 22BCS11636
Branch: B.E CSE Section/Group: IOT_635
Semester: 6th Date of Performance:
Subject Name: Computer Graphics Subject Code: 22CSH-352
1. Aim: (a). Develop a program to draw a circle using the circle generator algorithm for a
given center and radius.
(b). Develop a program to draw a circle using the midpoint circle algorithm for a given
center and radius.
3. Implementation/Code:
(a). #include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
while (x < y) {
x++;
if (p < 0)
p = p + (2 * x) + 1;
else {
y--;
p = p + (2 * (x - y) + 1);
}
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI"); // Ensure Turbo C++ BGI path is
correct
void main() {
clrscr();
// METHOD 1
int xc = 100, yc = 150, r = 50;
float x = 0, y = 0;
delay(100);
}
// METHOD 2
x = 0, y = r;
xc = 300, yc = 150;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
delay(100);
}
getch();
closegraph();
}
4. Output
(a).
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
(b).
5. Learning Outcome
• Understand Circle Generation Algorithms – Learn and implement the Midpoint
Circle Algorithm and Trigonometric Method for drawing circles in computer
graphics.
• Use Graphics Functions in Turbo C++ – Gain hands-on experience with
graphics.h functions like putpixel(), initgraph(), closegraph(), and setcolor().
• Apply Mathematical Concepts – Utilize trigonometry (sin, cos) and coordinate
geometry to plot points symmetrically in all octants of a circle.
• Optimize Graphics Programming – Understand efficient ways to draw circles
using decision parameters instead of floating-point calculations to enhance
performance.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 5
Student Name: Sahil Phogat UID: 22BCS11636
Branch: B.E CSE Section/Group: IOT_635
Semester: 6th Date of Performance:
Subject Name: Computer Graphics Subject Code: 22CSH-352
3. Implementation/Code:
(a). To rotate clockwise
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main() {
clrscr(); // Clear screen
cout << "Enter (x1, y1), (x2, y2), (x3, y3) for the triangle: ";
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
// Find centroid
int xf = (x1 + x2 + x3) / 3;
int yf = (y1 + y2 + y3) / 3;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
float ang;
cout << "Enter the rotation angle: ";
cin >> ang;
void main() {
clrscr(); // Clear the screen
cout << "Enter (x1, y1), (x2, y2), (x3, y3) for the triangle: ";
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
float ang;
cout << "Enter the rotation angle: ";
cin >> ang;
4. Output
(a).
(b).
5. Learning Outcome
• Correctly rotates the triangle around its centroid.
• Fixes sign errors in the rotation formula.
• Ensures proper graphics initialization and closure.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 6
Student Name: Sahil Phogat UID: 22BCS11636
Branch: B.E CSE Section/Group: IOT_635
Semester: 6th Date of Performance:
Subject Name: Computer Graphics Subject Code: 22CSH-352
1. Aim: Analyze and implement the reflection of a point about a line defined by the
equation y=mx+c.
2. Objective: To implement and analyze the reflection of a point about a straight line
defined by the equation y=mx+c.
3. Implementation/Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); // Corrected BGI path
setcolor(6);
line(x1, y1, x2, y2);
outtextxy(x1, y1 + 10, "Original Object");
getch();
closegraph();
}
4. Output
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Learning Outcome
• Reflects a line along the X-axis and Y-axis.
• Draws coordinate axes for reference.
• Uses different colors to distinguish the original and reflected lines.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 7
Student Name: Sahil Phogat UID: 22BCS11636
Branch: B.E CSE Section/Group: IOT_635
Semester: 6th Date of Performance:
Subject Name: Computer Graphics Subject Code: 22CSH-352
1. Aim: Evaluate the 4-bit region code for line endpoints and determine whether the line
lies inside or outside the screen.
2. Objective: To calculate and display the 4-bit region code for line endpoints and
determine whether the line lies within the screen boundaries.
3. Implementation/Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); // Corrected BGI path
getch();
closegraph();
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Output
5. Learning Outcome
• Draws a clipping window with boundaries at (xmin, xmax, ymin, ymax).
• Determines region codes for both endpoints of the given line.
• Classifies the line into three categories:
a) Completely inside → No clipping needed.
b) Partially inside → Clipping is required.
c) Completely outside → Line is rejected.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 8
Student Name: Sahil Phogat UID: 22BCS11636
Branch: B.E CSE Section/Group: IOT_635
Semester: 6th Date of Performance:
Subject Name: Computer Graphics Subject Code: 22CSH-352
1. Aim: a). Apply the Cohen-Sutherland Line Clipping algorithm to clip a line
intersecting at one point with a given window.
b). Apply the Cohen-Sutherland Line Clipping algorithm to clip a line intersecting at
two or more points with a given window
2. Objective: To clip a line intersecting at a single point and two or more points with a
window using the Cohen-Sutherland Line Clipping algorithm.
3. Implementation/Code:
a). For One Point
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
void main() {
int gd = DETECT, gm;
float i, xmax, ymax, xmin, ymin, x1, y1, x2, y2, m;
float start[4], end[4], code[4];
getch();
} else {
// Case 2: Line is partially visible
cleardevice();
printf("\n\t\tLine is partially visible");
rectangle(xmin, ymin, xmax, ymax);
line(x1, y1, x2, y2);
getch();
// Perform clipping
if ((start[2] == 0) && (start[3] == 1)) {
x1 = x1 + (ymin - y1) / m;
y1 = ymin;
}
if ((end[2] == 0) && (end[3] == 1)) {
x2 = x2 + (ymin - y2) / m;
y2 = ymin;
}
if ((start[2] == 1) && (start[3] == 0)) {
x1 = x1 + (ymax - y1) / m;
y1 = ymax;
}
if ((end[2] == 1) && (end[3] == 0)) {
x2 = x2 + (ymax - y2) / m;
y2 = ymax;
}
if ((start[1] == 0) && (start[0] == 1)) {
y1 = y1 + m * (xmin - x1);
x1 = xmin;
}
if ((end[1] == 0) && (end[0] == 1)) {
y2 = y2 + m * (xmin - x2);
x2 = xmin;
}
if ((start[1] == 1) && (start[0] == 0)) {
y1 = y1 + m * (xmax - x1);
x1 = xmax;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
getch();
closegraph();
}
void main() {
int gd = DETECT, gm;
float i, xmax, ymax, xmin, ymin, x1, y1, x2, y2, m;
float start[4], end[4], code[4];
cleardevice();
printf("\n\t\tThe line is totally visible\n\t\tand not a clipping candidate");
rectangle(xmin, ymin, xmax, ymax);
line(x1, y1, x2, y2);
getch();
} else {
cleardevice();
printf("\n\t\tLine is partially visible");
rectangle(xmin, ymin, xmax, ymax);
line(x1, y1, x2, y2);
getch();
// Perform clipping
if ((start[2] == 0) && (start[3] == 1)) {
x1 = x1 + (ymin - y1) / m;
y1 = ymin;
}
if ((end[2] == 0) && (end[3] == 1)) {
x2 = x2 + (ymin - y2) / m;
y2 = ymin;
}
if ((start[2] == 1) && (start[3] == 0)) {
x1 = x1 + (ymax - y1) / m;
y1 = ymax;
}
if ((end[2] == 1) && (end[3] == 0)) {
x2 = x2 + (ymax - y2) / m;
y2 = ymax;
}
if ((start[1] == 0) && (start[0] == 1)) {
y1 = y1 + m * (xmin - x1);
x1 = xmin;
}
if ((end[1] == 0) && (end[0] == 1)) {
y2 = y2 + m * (xmin - x2);
x2 = xmin;
}
if ((start[1] == 1) && (start[0] == 0)) {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
y1 = y1 + m * (xmax - x1);
x1 = xmax;
}
if ((end[1] == 1) && (end[0] == 0)) {
y2 = y2 + m * (xmax - x2);
x2 = xmax;
}
getch();
closegraph();
}
4. Output
a). For One Points
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
a).
b).
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Learning Outcome
• Understanding Line Clipping – Learned Cohen-Sutherland algorithm, region
codes, and clipping logic.
• Debugging C Graphics – Fixed division by zero, logical errors, and improved code
efficiency.
• Graphics Implementation – Used Turbo C++ functions to create and modify
viewport-based line rendering.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 9
Student Name: Sahil Phougat UID: 22BCS11636
Branch: B.E CSE Section/Group: IOT_635 / B
Semester: 6th Date of Performance:
Subject Name: Computer Graphics Subject Code: 22CSH-352
3. Implementation/Code:
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
void main() {
int gd=DETECT, gm;
initgraph(&gd, &gm, ""); // Use empty string instead of NULL
clrscr(); // Place after initgraph()
// Scaling factors
float sx = (vxmax - vxmin) / (wxmax - wxmin);
float sy = (vymax - vymin) / (wymax - wymin);
// Transform coordinates
float vx1 = sx * (wx1 - wxmin) + vxmin;
float vy1 = sy * (wy1 - wymin) + vymin;
float vx2 = sx * (wx2 - wxmin) + vxmin;
float vy2 = sy * (wy2 - wymin) + vymin;
// Labels
outtextxy(60, 260, "Window");
outtextxy(360, 260, "Viewport");
getch();
closegraph(); // Properly exit graphics mode
}
4. Output
5. Learning Outcome
• Learned how to transform coordinates from a window to a viewport.
• Practiced rectangle(), line(), and outtextxy() for visualization.
• Implemented formulas to scale and position graphical objects.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 3
Student Name: Sahil Phogat UID: 22BCS11636
Branch: CSE Section/Group: I O T - 6 3 5 ‘ B ’
Semester: 6th Date of Performance:
Subject Name: Foundation of Cloud IoT Edge Subject Code: 22CSP-314
ML Lab
1. Aim: Monitor air quality using a gas sensor (MQ135) and display the data on
ThingSpeak.
2. Objective: Monitor air quality using the MQ135 gas sensor and send the data to
ThingSpeak for visualization and analysis.
3. Hardware Used:
• MQ135 gas sensor
• ESP8266/Node MCU (or any microcontroller with Wi-Fi capability)
• Breadboard and jumper wires
• Power supply (5V for the sensor and microcontroller)
• ThingSpeak account (free API key)
Wiring:
• MQ135 VCC → NodeMCU 3V3 or 5V (depending on module support)
• MQ135 GND → NodeMCU GND
• MQ135 A0 → NodeMCU A0
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Set Up ThingSpeak:
• Go to ThingSpeak and create a free account.
• Create a new channel and add a Field (e.g., "Air Quality").
• Note down the Write API Key from the API Keys tab.
4. Script:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
// Replace with your network credentials const
char* ssid = "Your_SSID"; const char*
password = "Your_PASSWORD";
// ThingSpeak settings
const char* server = "http://api.thingspeak.com";
String apiKey = "YOUR_API_KEY";
// MQ135 connected to A0 int
mq135Pin = A0;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password); while
(WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
// Read analog value from MQ135 int
airQuality = analogRead(mq135Pin);
Serial.println("Air Quality Value: " + String(airQuality));
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Output:
ii. Hardware
7. Learning Outcomes:
• Understanding how to interface and calibrate the MQ135 gas sensor with
microcontrollers such as Arduino or ESP32.
• Collecting sensor data efficiently and reading analog values for air quality
monitoring.
• Learning how to set up wireless communication protocols (Wi-Fi, MQTT) to
connect with cloud platforms.