COMPUTER
GRAPHICS
UNIT 1
By- Komal S. Munde
UNIT-1
BASICS OF
COMPUTER
GRAPHICS
Hi
!
Welcome!
Are you
excited for a
fun learning
session?
Unit
Outcomes
Differentiate attributes of given mode
Compare features of given scan display
Write a program to draw given type of
primitives using "C"
Describe the application of given display
Describe the application of given display
Convert given 2D coordinates to physical
coordinates
What is Computer
Graphics ?
Computer Graphics is creating images, pictures, videos with
the help of
computers
It is one of the branch of Computer Science
It involves creation, manupulations and computation of data.
Algorithms and other techniques/hardware are used to
generate graphics in computer.
Advanced computer technologies have created scope for
various
appplications of Computer graphics.
What is image and
Object ?
Image is graphical representation of real world object on
computer.
Object is an item in graphic, represented using 2D and 3D
coordinates
Real image of
elephant
Pixe
l
Each screen point is called as pixel or pel (short form of
picture element)
It is smallest addressable point on display device.
It is smallest controllable element on display device We can
change the intensity, color, of individual pixel
Pixe
l
Pixe
l
Resolutio
n
The maximum number of points that can displayed on
screen without overlapping is called as resolution
It is total number of pixels in horizontal (M) and vertical
(N) directions
Resolution = M x N ex. 800x600, 640x480
Sharpness of image depends on resolution.
More the resolution higher the quality and sharpness of
image
M Resolutio
n
M = No. of pixels on
horizontal axis
N= No. of pixels on vertical
axis
N
Resolution = M x N
Display
Modes
Text Mode Graphics Mode
Content is displayed as characters Generates images using pixels
Lines, characters etc are dawn
Screen is divided into rectangular using pixels
character cells
Each cell contains a character Variety of shapes and colors can
be drawn
Also known as character mode or
alphanumeric mode Screen is divided into pixels
80 characters per row x 25
characters per column
Text Mode
Functions
Window( ) - creates window on screen
Syntax: window(top, left, right, bottom) Ex:
window(150,10,200,10)
gotoxy(x,y ) - positions cursor on x, y
coordinates Syntax: gotoxy(int x,int y)
Ex: gotoxy(42,80)
textcolor(x,y ) - Changes color of drawing text
Syntax: void textcolor(int color)
Ex: textcolor(BLUE) or textcolor(2)
Text Mode
Functions
textbackground( ) - changes current background color of text
Syntax: void textbackground(int color) Ex:
textbackground(RED)
moveto(x,y ) - changes current position to x,y coordinate
position Syntax: void moveto(int x,int y)
Ex: moveto(10,20)
outtext(x,y,str) - displayes text or string at x, y position
Syntax: void outtextxy(int x,int y, char* str)
Ex: outtextxy(80,80,"welcome")
Text Mode
Functions
dellline( ) - deletes cursor line and moves line up by one line
Syntax: void delline( ) Ex: delline()
Other simple functions:
putch(ch) - displays one character at a time clrscr() - clears
the consol escreen
puts(const char *s) - writes a string to standard output
(stdout)
Graphics Mode
Functions
initgraph( ) - initializes the graphics system by loading graphics driver
from disk and putting the system in graphics mode
Syntax: void initgraph(int *graphdriver, int * graphmode, char* pathtodriver
graphdriver - specifies driver to be used graphmode - specifies
initial graphics mode
pathtodriver- specifies path or location to graphics driver
Ex: initgraph(&gd, &gm, "C:\\TURBOC\\BGI")
Graphics Mode
Functions
closegraph( ) - deallocates all memory and restores screen to
previous
mode
Syntax: void closegraph( ) x1,y1 = 30,100
Ex: closegraph( )
line( ) - draws a line on screen
Syntax: void line(int x1, int y1, int x2, int x2,y2 = 70,80
y2 ) Ex: line( 30,100,70,80)
Graphics Mode
x,y
Functions
lineto( ) - draws line from current position to x,y
position
Syntax: void lineto(int x, int y ) Ex: lineto(120,120)
current position
circle( ) - draws a circle on screen Syntax: void radiu
s
circle(x, y, radius )
x,y
Ex: circle(50,60,30)
Graphics Mode
Functions
rectangle( ) - draws a rectangle from top
left to right bottom Syntax: void
rectangle(int left, int top, int right, int
bottom ) Ex: rectangle(20,20,60,60)
left,top = 20.20
ellipse( ) - draws
ellipse
Syntax: void ellipse(int x,int y,int
right,bottom=60,60
start_angle,int end_angle,in xradius,int
yradius ) angle
Ex: xradius
circle(50,60,30)
yradius
Graphics Mode
Functions
drawpoly( ) - drawpoly function is used to draw polygons
120,120
like traingle,rectangle,pentagon,hexagon etc.
Syntax: void drawpoly(int num,int polypoints[ ] ) num = no.
of vertices + 1
polypoints[ ] = array or collection of polygon
points 60,60 160,160
Ex: int polypoints = {60,60,160,160,120,120,60,60}
drawpoly (4,polypoints)
Graphics Mode
Functions
setcolor( ) - changes current drawing color
Syntax: void setcolor(int color) Ex: setcolor
(RED)
setfillstyle( ) - sets current color and fill
pattern
Syntax: void setfillstyle(int pattern, int color)
Ex: setfillstyle(SOLID_FILL,BLUE)
Graphics Mode
Functions
setlinestyle( ) - sets the style for drawing lines
Syntax: void setlinestyle(int linestyle,unsigned
pattern,int thickness )
Ex:
dotted
setlinestyle(2,0,0
line
)
fillpoly( ) - draws polygon and also fill color
in polygon
Syntax: void fillpoly(int num, int
polypoints[ ]) num = no. of vertices + 1
polypoints[ ] = array of polygon points Ex:
fillpoly(4,polypoints)
Basic Graphics
Pipeline
It describes steps in a graphics system to convert 3D scene
to a 2D screen
It is the process of turning 3D model into what computer
displays
Applicatio Geometry Rasterizati
n on Scree
n
Fig: Basic Graphics
Pipeline
Classifi cation of Computer
Graphics
Bitmap
Vector
Graphics
based
Graphics
Bitmap
Im ages are stored Graphics
Pix Also called as
and drawn as el raster graphics
series of pixels
bitm ap formats : Images
gif, depends on
jpeg,png,tiff,xmb,b resolution
mp,
Suitable for
complex Can't scale
easily
images
High processing Large file
speed size
Image editors:Painshop Pro, photoshop, M S paint,
Paint.NET
Vector
Constructed using Graphics Mathematical formulas
mathematical describes shapes,color
formulas and placement
vector file Images don't
formats : depend on
svg ,eps,pdf, ai resolution
Suitable for images
with solid color Can be scaled
areas like logos easily
images have smooth Small file
edges size
Image editors:Adobe freehand, Affi nity designer,
coralDRAW etc.
Applications of Computer
Graphics
Advanced computer technology have made various applications
of computer graphics possible like
Computer -Aided Design Education and
(CAD) Training
Presentation Graphics Visualization
Computer Art Image Processing
Entertainment Medicine
Applications of Computer
Graphics
Computer Aided Design
(CAD)
CAD design of CAD design of
Spaceship machine
Applications of Computer
Graphics
Presentation
Graphics
3D surface 3D bar
chart chart
Applications of Computer
Graphics
Computer
Art
Computer
Painting Digital
Art
Applications of Computer
Graphics
Entertainm
ent
Toy Story Good Dinosaur
Movie Movie
Applications of Computer
Graphics
Education
Training
Pilot Tractor
Training Simulation
Applications of Computer
Graphics
Visualizati
on
Time series Bacteria Protein
data Structure
Applications of Computer
GraphicsImage
Processing
Image processing of MRI scan
brain machine
Video Display Devices - Cathod
Ray Tube
Ref:
Aspect
Ratio
It is property of video
monitors
Aspect Ratio No. of vertical points to draw same
= length line
No. of horizontal points to draw same length line
3 vertical dots for same length line
3
Aspect Ratio
=
5
5 horizontal
dots for
same length
Cathod Ray Tube ( CRT ) - Raster Scan
Displays
Suitable for real
Electron beam is
scenes
m oved
top to bottom, one
time.
row at
Electron beam is
turned on/off to
create pattern of
spots
Picture defi nation is
stored in memory area Refreshing rate is 60
called refresh to 80
buffer/frame buffer frames per second or
interlaced refresh - hertz
scans one line and
Cathod Ray Tube ( CRT ) - Random
Scan Display Also called as vector displays /
Electron beam is stroke / calliagraphic
writing
directed to only that displays
part of screen
where
draw picture is
n. Suitable for
Picture display is line drawing
stored as set of
line drawing Draws smooth
commands called line
as refresh display
file All lines of picture
drawn
Higher resolution
30 to 60 tim es per
second than raster scan
Flat Panel
Displays
Thinner, less volume, weight and
volume
Em issive display :
convert Non-Emissive display : convert
sunlight
electrical energy to
light or other light to display
Pl a sma panel display
Liquid Crystal display (LCD)
LED display
Flat Panel
Displays
Plasma Panel Displays
Basic design of plasma panel
device
Flat Panel
Displays
Plasma Panel
Displays
Basic design of electroluminscent
device
Flat Panel
Displays
Liquid Crystal Displays
(LCD)
Source:
Javapoint
Flat Panel
Displays
Touch Panels
Screen selected using touch of finger. Three types of
touch panels
1. Optical Touch Panel
detecto
Has line of infrared LEDs along one rs
horizontal and one vertical edge.
Opposite end contains light
rs
to
ec
et
d
LED
detectors
s
When crossing beams are
interrupted, , position on screen is
identifiec by detectors LED
s
Infrared light not visible to eyes
Flat Panel
Displays
Touch
Panels
2. Electrical Touch Panel conductive material
plate
Contains two transparent
plates
separated by small distance
One plate coated with conductive
material
Other plate coated with
material.
resistive/oppose
Outer plate touches inner plate and
voltage drops accross resistive plate
resistive material
and we get
selelcted screen plate
position
Flat Panel
Displays
Touch Panels
3. Acoustical (Sound) Touch Panel sound
waves
Sound waves are generated in
horizontal and vertical directions in
glass plate
rs
te
it
m
e
When screen is touched, waves get
reflected from fi ngers to emitters
Screen position is caculated from time
between emitte
transmission and reflection to emitter rs
High frequency sound is
used
Ouput
Primitives
What is ouput primitives ?
They are basic geometric diagrams used to draw a
scene
Basic geometric diagrams are grouped to draw
complex
Examplesscene
of basic output
primitives Points Spline curves and
Straight lines Circles surfaces Polygon
Conic section and surfaces color areas
Quadric surfaces Character strings
Ouput
Primitives
Point
setPixel(x,y) and putpixel() functions set color of pixel at
x, yosition.
Syntax : setPixel(int x,int y,int color), putpixel(int x,int
y,int color) Ex: setPixel(30,60,BLUE),putpixel(60,40,RED)
getpixe() function returns color of pixel at x, y position
Syntax : int getpixel(int x, int y)
Ex: int color = getpixel(70,80)
Ouput
Primitives
Text
setTextColor() function is changes color
of text.
Syntax : setTextColor(hdc,RGB_value)
Ex: setTextColor(hDC,RGB(255,0,0))
setTextAlign() is used to align the text.
Syntax : setTextAign(int align)
Ex. setTextAlign(2) // aligns text at
center
Ouput
Primitives
Marker
Marker symbol is single character displayed in diff erent
color and size setM arkerType(m t) - set m arker sym bol
polymaker() - draws figure with marker symbol
already set Syntax : polymarker(n, wcPoints)
n = no. of points
wcPoints = array of coordinate position.
Attributed of Ouput
Primitives
Text - font or typeface, color, alignment, space,
height etc.
Marker- size,color,type
Line - type, width, color Curve - type, width,
color
Various functions are available to change these
attributes
Graphics
Standards
Standards are required so that software moves easily from one
hardware system to another (portability)
Graphical Kernel System (GKS) - two dimensional and three
dimensional
graphics package
Programmer's Hierarchical Interactive Graphics Standard
(PHIGS) - increasd capability for object modelling, color, picture,
surface manipulation
Computer Graphics Interface (CGI) - standards for device
interface.
Computer Graphics Metafi le (MGM) - standards for storing and
transporting pictures
Recent Trends in Computer
GraphicsVirtual Reality ( VR)
Uses computer technology to create simulated / real like
environment
Immersive VR - As if physicall present in non-physical world,
simulates as
many senses as possible
Non - immersive : Computer generated environment without
feeling of present in virtual world
Semi - immersive VR : Virtual three dimesional
environment while remain connected to real world
surroundings through senses.
Recent Trends in Computer
Graphics Virtual Reality ( VR)
Devices used in VR - Joysticks, force Balls/Tracking balls, controller
wands, data gloves, trackpads, On-device control, buttons,
motion trackers, bodysuits, treadmills and motion platforms,VR
headsets, head mounted display
Applications of Virtual
Reality Sport Entertainment
Mental health Scientific
Medical training Visualization
Education Construction
Military etc.
Recent Trends in Computer
Graphics Virtual Reality
( VR)
Examples of Virtual
Reality
Recent Trends in Computer
Graphics
Augmented Reality ( VR)
It is interactive environment where real world objects are
improved by computer generated information
Combination of real and virtual world, real time interaction ,
3D real and virtual objects
VR is completely based on virtual information and AR is
provided with
additional computer generated information that improves
reality
Recent Trends in Computer
Graphics
Augmented Reality
( AR)
Examples of Augmented
Reality
Computer Graphics Progam
in C
Functions and files required for writing basic c program
void initgraph( ) - This function is compulsory. It is written at
beginning of program, we enter into graphics mode by this
function.
Ex: initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
closegraph() - This function is compulsory and written at end of
program.It closes the graphics mode bring back to previous
mode.
Ex: closegraph();
graphics.h - this is header file and compulsory required in
program. It contains
simple graphic functions
How To Write Graphics Progam
in C ?
Open TURBOC software
Open a new file in TURBOC
Write \ edit c program.
Save the program \ file with .c extension in TURBOC like
filename.c Compile (check errors ) the program, click on
compile button in TURBOC
If no errors click run the program , click on run button in
TURBOC
You will get the graphics ouput on screen
Simple Graphics Progam
in C
#include <graphics.h>
#include<conio.h>
#include<stdio.h> void main()
{
int gd = DETECT, gm; int x =100,
y= 150; int radius = 90;
initgraph(&gd, &gm, "C:\\
TURBOC3\\BGI");
setcolor(YELLOW);
circle(x,y,radius);
rectangle(150,150,,300,300);
line(50,50,200,200);
getch(); closegraph();
}
Output of C
Program
Activity
Time
Programming
Assignment Survey
Peer to Peer teaching
Supplemental Video
https://nptel.ac.in/
courses/1
06/102/106102065/
Additional
Resources
https://MIT ADT University,
Loni Kalbhor Pune,
412201www.tutorialspoint.com/computer_graphics
https://nptel.ac.in/courses/106/102/106102065
Computer Graphics - Donald Hearn, Baker M Pauline,
Pearson Education
Summary of
Class
Lesson Lesson Lesson
Recap 1 Recap 2 Recap 3
Different Scan Display Computer
Graphics mode Graphics
Lesson Recap Lesson programming in
4 Recap 5 c
Applications of Virtual Reality
display devices and Augmented
Reality
Thank you for
attending!