SlideShare a Scribd company logo
1 of 39
Date:27/03/2015
baabtra@baabte.com
facebook.com/baabtra
twitter.com/baabtra
in.linkedin.com/in/baabtra
Introduction to Graphics
Programming in
Team: Golden Girlzz
Contents
❏ Setting Up graphics using gcc
❏ Basic Idea About Graphics Programming in C
❏ Some functions in Graphics
❏ Working Example
❏ Computer Graphics is one of the most powerful and interesting aspect
of computers.
❏ There are many things we can do in graphics apart from drawing
figures of various shapes.
❏ All video games, animation, multimedia predominantly works using
computer graphics.
❏ There is a large number of functions in C which are used for putting pixel
on a graphic screen to form lines, shapes and patterns.
❏ The Default output mode of C language programs is “Text” mode.
❏ We have to switch to “Graphic” mode before drawing any graphical shape
like line, rectangle, circle etc.
❏ First of all, we must include the ”graphics.h” header file in our source
program
❏ GCC compiler doesn’t provides inbuilt facility to run graphics.h library.
❏ So you are not able to run graphics in C language
❏ To run "graphics.h" library in Ubuntu, following are some simple steps.
Graphics in C
Make sure that you have basic compilers installed. For this run the command:
Install few packages that required. Run the command:
Run “graphics.h” in Ubuntu
#1
sudo apt-get install build-essential
#2
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-
1.8-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev libesd0-dev
libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-
xext-dev libfreetype6 libaa1 libaa1-dev libslang2-dev libasound2
libasound2-dev
Now download libgraph
Copy libgraph-1.0.2.tar.gz to your home folder. Right click on it and select "Extract
Here".
Then run following commands one by one.
Now Ubuntu is ready to run graphics program. To do that add
#include<graphics.h> in your C program.
Here is a sample program to test it's working or not. sample.c
#3
cd libgraph-1.0.2
./configure
sudo make
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/li
#4
#include<graphics.h>
main() {
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
closegraph();
}
❏ Run it with following command:
If you get following screen then graphics.h is working
gcc sample.c -o sample -lgraph
./sample
#5
Initializing Graphics Mode
❏ The initgraph function is used to switch the output from text mode to
graphics mode
❏ The initgraph function takes three arguments
❏ Syntax: –
intigraph(&graphics_driver,&graphics_mode,Path _to_driver);
❏ Example:
If you are working on Turbo C, use the path “c:tcbgi”
initgraph(&dr, &md, NULL );
Graphics Driver
Type
Initial Graphics
Mode
Directory Path of
Graphics Driver
Closing Graphics Mode
❏ Graphics mode must be closed at the end
❏ For that function closegraph() is used
❏ Syntax: –
closegraph();
Some Functions in
“graphics.h”
void line(int x1, int y1, int x2, int y2);
❏ Remarks
➔ line draws a line from (x1, y1) to (x2, y2) using the
current color
line()
❏ line function is used to draw a line from a point(x1,y1) to
point(x2,y2)
❏ Syntax :-
void circle(int x, int y, int radius);
● (x , y) -> Center point of circle
● radius-> Radius of circle
circle()
❏ Circle function is used to draw a circle with center (x,y) and
third parameter specifies the radius of the circle.
❏ Syntax :-
void rectangle(int left, int top, int right, int
bottom);
rectangle()
❏ Coordinates of left top and right bottom corner are required
to draw the rectangle.
❏ Syntax:-
void bar( left, top, right, bottom);
bar( )
❏ bar function draws a bar
❏ bar draws a filled-in, rectangular, two-dimensional bar.
❏ žSyntax:
void ellipse(int x, int y, int stangle, int endangle, int
xradius, int yradius);
ellipse()
❏ Ellipse function is used to draw an ellipse, (x,y) are
coordinates of center of the ellipse, stangle is the
starting angle, end angle is the ending angle, and fifth
and sixth parameters specifies the X and Y radius of
the ellipse.
❏ Syntax :-
Note the Point:
In this, color can be represented
using the name of colors in
CAPITAL LETTER and also using
the numbers
Eg:
code 0 means BLACK
code 1 means BLUE
code 2 means GREEN
putpixel() and getpixel()
❏ getpixel() returns the color of pixel present at point(x, y)
❏ Syntax: –
❏ putpixel plots a pixel at a point(x, y) of specified color
❏ Syntax:-
int getpixel(int x, int y);
void putpixel(int x, int y, int color);
setbkcolor()
❏ setbkcolor function changes current background color e.g.
setbkcolor(YELLOW) changes the current background color to
YELLOW.
❏ Remember that default drawing color is WHITE and background color
is BLACK.
❏ Syntax :-
void setbkcolor(int color);
setcolor()
❏ setcolor() function changes current drawing color
❏ Syntax :-
❏ Example:
changes the current drawing color to YELLOW.
void setcolor(int color);
setcolor(YELLOW);
Text with Graphics
❏ There are functions in C language that draw text characters in
graphics mode.
❏ These functions can be used to mix text and graphics in the same
image.
❏ These functions also make it possible to change text font and very the
size of text.
outtext()
❏ displays a string in the viewport (graphics mode)
❏ Declaration:
❏ outtext display a text string, using the current justification settings and
the current font, direction, and size
❏ outtext outputs textstring at the current position (CP)
void outtext(char *textstring);
outtextxy()
❏ outtextxy displays a string at the specified location (graphics mode)
❏ Declaration:
❏ Remarks: outtextxy() display a text string, using the current
justification settings and the current font, direction, and size.(CP)
outtextxy() displays textstring in the viewport at the position (x, y)
void outtextxy(x, y, char *textstring);
Working
#include<graphics.h>
#include<stdio.h>
main() {
int gd = DETECT,gm,left=100,top=100,right=200,bottom=200;
int x=300,y=150,radius=50,color;
initgraph(&gd, &gm,NULL);
printf("Press any key to change the back color");
getch();
setbkcolor(2);
setcolor(RED);
outtext("Introduction to Graphics Programming....n");
outtextxy(100,100,"Text at position x=100 and y=100");
color=getpixel(0,0);
printf("color of pixel at (0,0) = %d",color);
putpixel(25,25,YELLOW);
putpixel(25,26,YELLOW);
putpixel(25,27,YELLOW);
rectangle(left, top, right, bottom);
circle(x, y, radius);
bar(left+100,top+100,right+100,bottom+100);
line(left - 10, top + 150, left + 410, top + 150);
ellipse(x, y + 200, 0, 360, 100, 50);
outtextxy(left + 100, top + 325, "My First C Graphics Program");
getch();
closegraph();
return 0;
}
and the output is..
US UK UAE
7002 Hana Road,
Edison NJ 08817,
United States of America.
90 High Street,
Cherry Hinton,
Cambridge, CB1 9HZ,
United Kingdom.
Suite No: 51, Oasis Center,
Sheikh Zayed Road, Dubai,
UAE
Email to info@baabtra.com or Visit baabtra.com
Looking for learning more about the above
topic?
India Centres
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square IT Park,
Hilite Business Park,
Kozhikode
Kerala, India.
Email: info@baabtra.com
TBI - NITC
NIT Campus, Kozhikode.
Kerala, India.
Start up Village
Eranakulam,
Kerala, India.
Start up Village
UL CC
Kozhikode, Kerala
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.

More Related Content

What's hot (20)

Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptx
 
Color Models Computer Graphics
Color Models Computer GraphicsColor Models Computer Graphics
Color Models Computer Graphics
 
Color Models
Color ModelsColor Models
Color Models
 
HSV color model
HSV color modelHSV color model
HSV color model
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Rgb and Cmy color model
Rgb and Cmy color modelRgb and Cmy color model
Rgb and Cmy color model
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Illumination Models & Shading
Illumination Models & ShadingIllumination Models & Shading
Illumination Models & Shading
 
Halftoning in Computer Graphics
Halftoning  in Computer GraphicsHalftoning  in Computer Graphics
Halftoning in Computer Graphics
 
Features image processing and Extaction
Features image processing and ExtactionFeatures image processing and Extaction
Features image processing and Extaction
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Image & Graphics
Image & GraphicsImage & Graphics
Image & Graphics
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
Hit and-miss transform
Hit and-miss transformHit and-miss transform
Hit and-miss transform
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4
 
Color Image Processing
Color Image ProcessingColor Image Processing
Color Image Processing
 

Similar to Introduction to graphics programming in c

bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfshehabhamad_90
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics FunctionsSHAKOOR AB
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
Circles graphic
Circles graphicCircles graphic
Circles graphicalldesign
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)JAINAM KAPADIYA
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
Computer graphics
Computer graphics Computer graphics
Computer graphics shafiq sangi
 
Powerpointpresentation.c
Powerpointpresentation.cPowerpointpresentation.c
Powerpointpresentation.cMaqbool Ur Khan
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignmentAbdullah Al Shiam
 
Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics ConceptsSHAKOOR AB
 
Creating a rainbow using graphics programming in c
Creating a rainbow using graphics programming in cCreating a rainbow using graphics programming in c
Creating a rainbow using graphics programming in cBathshebaparimala
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing StuffMark Kilgard
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfShaiAlmog1
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
ch03g-graphics.ppt
ch03g-graphics.pptch03g-graphics.ppt
ch03g-graphics.pptMahyuddin8
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to CodingFabio506452
 

Similar to Introduction to graphics programming in c (20)

bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
7. chapter vi
7. chapter vi7. chapter vi
7. chapter vi
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
Powerpointpresentation.c
Powerpointpresentation.cPowerpointpresentation.c
Powerpointpresentation.c
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
Graphics mod
Graphics modGraphics mod
Graphics mod
 
Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
 
Creating a rainbow using graphics programming in c
Creating a rainbow using graphics programming in cCreating a rainbow using graphics programming in c
Creating a rainbow using graphics programming in c
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 
Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
ch03g-graphics.ppt
ch03g-graphics.pptch03g-graphics.ppt
ch03g-graphics.ppt
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Recently uploaded

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 

Recently uploaded (20)

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 

Introduction to graphics programming in c

  • 1.
  • 3. Contents ❏ Setting Up graphics using gcc ❏ Basic Idea About Graphics Programming in C ❏ Some functions in Graphics ❏ Working Example
  • 4. ❏ Computer Graphics is one of the most powerful and interesting aspect of computers. ❏ There are many things we can do in graphics apart from drawing figures of various shapes. ❏ All video games, animation, multimedia predominantly works using computer graphics.
  • 5. ❏ There is a large number of functions in C which are used for putting pixel on a graphic screen to form lines, shapes and patterns. ❏ The Default output mode of C language programs is “Text” mode. ❏ We have to switch to “Graphic” mode before drawing any graphical shape like line, rectangle, circle etc.
  • 6. ❏ First of all, we must include the ”graphics.h” header file in our source program ❏ GCC compiler doesn’t provides inbuilt facility to run graphics.h library. ❏ So you are not able to run graphics in C language ❏ To run "graphics.h" library in Ubuntu, following are some simple steps. Graphics in C
  • 7. Make sure that you have basic compilers installed. For this run the command: Install few packages that required. Run the command: Run “graphics.h” in Ubuntu #1 sudo apt-get install build-essential #2 sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile- 1.8-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto- xext-dev libfreetype6 libaa1 libaa1-dev libslang2-dev libasound2 libasound2-dev
  • 8. Now download libgraph Copy libgraph-1.0.2.tar.gz to your home folder. Right click on it and select "Extract Here". Then run following commands one by one. Now Ubuntu is ready to run graphics program. To do that add #include<graphics.h> in your C program. Here is a sample program to test it's working or not. sample.c #3 cd libgraph-1.0.2 ./configure sudo make sudo make install sudo cp /usr/local/lib/libgraph.* /usr/li #4 #include<graphics.h> main() { int gd=DETECT,gm; initgraph(&gd,&gm,NULL); closegraph(); }
  • 9. ❏ Run it with following command: If you get following screen then graphics.h is working gcc sample.c -o sample -lgraph ./sample #5
  • 10. Initializing Graphics Mode ❏ The initgraph function is used to switch the output from text mode to graphics mode ❏ The initgraph function takes three arguments ❏ Syntax: – intigraph(&graphics_driver,&graphics_mode,Path _to_driver);
  • 11. ❏ Example: If you are working on Turbo C, use the path “c:tcbgi” initgraph(&dr, &md, NULL ); Graphics Driver Type Initial Graphics Mode Directory Path of Graphics Driver
  • 12. Closing Graphics Mode ❏ Graphics mode must be closed at the end ❏ For that function closegraph() is used ❏ Syntax: – closegraph();
  • 14. void line(int x1, int y1, int x2, int y2); ❏ Remarks ➔ line draws a line from (x1, y1) to (x2, y2) using the current color line() ❏ line function is used to draw a line from a point(x1,y1) to point(x2,y2) ❏ Syntax :-
  • 15.
  • 16. void circle(int x, int y, int radius); ● (x , y) -> Center point of circle ● radius-> Radius of circle circle() ❏ Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle. ❏ Syntax :-
  • 17.
  • 18. void rectangle(int left, int top, int right, int bottom); rectangle() ❏ Coordinates of left top and right bottom corner are required to draw the rectangle. ❏ Syntax:-
  • 19.
  • 20. void bar( left, top, right, bottom); bar( ) ❏ bar function draws a bar ❏ bar draws a filled-in, rectangular, two-dimensional bar. ❏ žSyntax:
  • 21.
  • 22. void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius); ellipse() ❏ Ellipse function is used to draw an ellipse, (x,y) are coordinates of center of the ellipse, stangle is the starting angle, end angle is the ending angle, and fifth and sixth parameters specifies the X and Y radius of the ellipse. ❏ Syntax :-
  • 23.
  • 24. Note the Point: In this, color can be represented using the name of colors in CAPITAL LETTER and also using the numbers Eg: code 0 means BLACK code 1 means BLUE code 2 means GREEN
  • 25. putpixel() and getpixel() ❏ getpixel() returns the color of pixel present at point(x, y) ❏ Syntax: – ❏ putpixel plots a pixel at a point(x, y) of specified color ❏ Syntax:- int getpixel(int x, int y); void putpixel(int x, int y, int color);
  • 26. setbkcolor() ❏ setbkcolor function changes current background color e.g. setbkcolor(YELLOW) changes the current background color to YELLOW. ❏ Remember that default drawing color is WHITE and background color is BLACK. ❏ Syntax :- void setbkcolor(int color);
  • 27. setcolor() ❏ setcolor() function changes current drawing color ❏ Syntax :- ❏ Example: changes the current drawing color to YELLOW. void setcolor(int color); setcolor(YELLOW);
  • 28. Text with Graphics ❏ There are functions in C language that draw text characters in graphics mode. ❏ These functions can be used to mix text and graphics in the same image. ❏ These functions also make it possible to change text font and very the size of text.
  • 29. outtext() ❏ displays a string in the viewport (graphics mode) ❏ Declaration: ❏ outtext display a text string, using the current justification settings and the current font, direction, and size ❏ outtext outputs textstring at the current position (CP) void outtext(char *textstring);
  • 30. outtextxy() ❏ outtextxy displays a string at the specified location (graphics mode) ❏ Declaration: ❏ Remarks: outtextxy() display a text string, using the current justification settings and the current font, direction, and size.(CP) outtextxy() displays textstring in the viewport at the position (x, y) void outtextxy(x, y, char *textstring);
  • 32. #include<graphics.h> #include<stdio.h> main() { int gd = DETECT,gm,left=100,top=100,right=200,bottom=200; int x=300,y=150,radius=50,color; initgraph(&gd, &gm,NULL); printf("Press any key to change the back color"); getch(); setbkcolor(2); setcolor(RED); outtext("Introduction to Graphics Programming....n"); outtextxy(100,100,"Text at position x=100 and y=100"); color=getpixel(0,0); printf("color of pixel at (0,0) = %d",color); putpixel(25,25,YELLOW); putpixel(25,26,YELLOW); putpixel(25,27,YELLOW); rectangle(left, top, right, bottom); circle(x, y, radius); bar(left+100,top+100,right+100,bottom+100); line(left - 10, top + 150, left + 410, top + 150); ellipse(x, y + 200, 0, 360, 100, 50); outtextxy(left + 100, top + 325, "My First C Graphics Program"); getch(); closegraph(); return 0; }
  • 34.
  • 35.
  • 36. US UK UAE 7002 Hana Road, Edison NJ 08817, United States of America. 90 High Street, Cherry Hinton, Cambridge, CB1 9HZ, United Kingdom. Suite No: 51, Oasis Center, Sheikh Zayed Road, Dubai, UAE Email to info@baabtra.com or Visit baabtra.com Looking for learning more about the above topic?
  • 37. India Centres Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square IT Park, Hilite Business Park, Kozhikode Kerala, India. Email: info@baabtra.com TBI - NITC NIT Campus, Kozhikode. Kerala, India. Start up Village Eranakulam, Kerala, India. Start up Village UL CC Kozhikode, Kerala
  • 38. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • 39. Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.