0% found this document useful (0 votes)
10 views

Graphics in C++ - Mohammed Ihsan

The document provides an overview of using graphics in C++ for creating visual representations, highlighting libraries like graphics.h, SDL, and OpenGL. It includes setup instructions, basic drawing functions, and examples of code for drawing shapes and using loops and conditions. The conclusion emphasizes the importance of graphics in understanding programming flow and logic visually.

Uploaded by

Stive Brack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Graphics in C++ - Mohammed Ihsan

The document provides an overview of using graphics in C++ for creating visual representations, highlighting libraries like graphics.h, SDL, and OpenGL. It includes setup instructions, basic drawing functions, and examples of code for drawing shapes and using loops and conditions. The conclusion emphasizes the importance of graphics in understanding programming flow and logic visually.

Uploaded by

Stive Brack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

<Graphics in C++/> Medical Instrumentation Mohammed Ihsan Cover

Nineveh University
College of Electronics Engineering
Department of Electronic Engineering </>
Medical Instrumentation

<Graphics in C++/>
<Mohammed
Ihsan/>2 Stage
</>
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 1

Introduction to
Graphics in C++
1. Used for creating visual representations and
designs.
*
2. Enables dynamic and interactive content.
3. Popular libraries: graphics.h, SDL, OpenGL,
SFML.
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 2

Setup and Using


graphics.h
1. Common library for beginners.
2. Key functions:
3. initgraph() to initialize.
4. closegraph() to close.
5. Drawing functions: line(), circle(), rectangle(),
bar(), ellipse().
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 3

Basic Drawing Functions


1. line(): Draws a line.
2. circle(): Draws a circle.
3. rectangle(): Draws a rectangle.
4. bar(): Draws a filled rectangle.
5. ellipse(): Draws an ellipse.
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 4

Example Code for Setup


A simple C++ program using
the graphics.h library to draw
a line and a circle on the
screen.
1. Include libraries:

#include <graphics.h>
#include <conio.h>

• graphics.h provides functions to draw shapes.


• conio.h allows the use of getch() for waiting for a
key press.
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 5

2. Initialize graphics mode:

int gd = DETECT, gm;


initgraph(&gd, &gm, "");

• DETECT automatically detects the graphics


driver.
• Initializes the graphics window.
3. Draw a line:

line(100, 100, 200, 200);

• Draws a line from point (100, 100) to (200, 200).

4. Draw a circle:

circle(300, 200, 50);

• Draws a circle with center (300, 200) and radius


50.
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 6

5. Pause and close:

getch();
closegraph();

• Waits for a key press and then closes the


graphics window.

End of Program
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 7

Bitwise Operators & Shifting Operations


Graphics
• << left shift: multiply by powers of 2.
• AND (&), OR (|), XOR (^), NOT (~).
• >> right shift: divide by powers of 2.
• Can be used for pixel manipulation.
• Shifts used to move pixels or scale graphics data.
• Example: R = N1 & N2; for bit control.
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 8

Loops for Graphics


• Use for, while, do-while for repetitive drawing.

• Example: nested loops to create patterns.

• Example: pyramid, triangle, diagonal lines using loops.


<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 9

Graphics Application Examples


1. Draw shapes based on loops and conditions:

#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
for (int i = 50; i <= 250; i += 50) {
rectangle(i, i, i+40, i+40);
}
getch();
closegraph();
}
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 10

Graphics Application Examples


2. Display dynamic values (like factorial, summation):

#include <iostream.h>
#include <conio.h>
#include <math.h>
void main() {
double sum = 0;
int n;
cout << "Input n: ";
cin >> n;
for (int i = 1; i <= n; i++) {
sum += 1 / pow(i, i);
}
cout << "Sum of series: " << sum;
getch();
}
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 11

Graphics Application Examples


Use conditional logic for drawing or skipping elements (continue statement):

#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
for (int x = 50; x <= 400; x += 50) {
if (x == 150 || x == 300) continue;
circle(x, 200, 20);
}
getch();
closegraph();
}
<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 12

Conclusion
• Graphics in C++ demonstrated through loops, conditions,
and bitwise operations.

• Helps understand programming flow and logic visually.


<Graphics in C++/> Medical Instrumentation Mohammed Ihsan 13

</>

<THANK’S/>
</>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy