SlideShare une entreprise Scribd logo
1  sur  17
Graphics Programming in C
Kasun Ranga Wijeweera
(Email: krw19870829@gmail.com)
Evaluation Criteria
• Project: 40%
• End Semester Examination: 60%
Course Content
• Introduction to Graphics Programming in C
• Points, Lines and Polygons
• Line Drawing Algorithms
• Circle Drawing Algorithms
• Area Filling Algorithms
• Geometric Transformations in 2D
• Geometric Transformations in 3D
• Line Clipping Algorithms in 2D
• Line Clipping Algorithms in 3D
Integrated Development Environment
• Turbo C++ , Version 3.0, Copyright (c) 1990, 1992 by Borland
International, Inc
Graphics Header File
• Go to File  New
• Type initgraph in the new window and right click on it
• There you will find a program and using it lets try to create a
header file to initialize and exit graphics mode
• Open another file and save it as grap.h
The grap.h Header File
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void ginit()
{
……
……
}
void gexit()
{
……
……
}
The ginit() Function
void ginit()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "D:/Tcpp/BGI");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %sn", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
}
The gexit() Function
void gexit()
{
closegraph();
}
The First Program
• Open a new file and save it as first.c
• There you have to include the grap.h header file that had been
created earlier
• Then your first program should look like as follows and
running it will give a black and empty screen
#include<stdio.h>
#include<conio.h>
#include"D:/GP/header/grap.h"
void main()
{
ginit();
getch();
gexit();
}
The Output Screen
• Execute following code to get the maximum x and maximum y
values of the output screen
#include<stdio.h>
#include<conio.h>
#include"D:/GP/header/grap.h"
void main()
{
ginit();
printf("%d %d",getmaxx(),getmaxy());
getch();
gexit();
}
The Output Screen
x
y
The Output Screen
• The y-axis is upside down?
• The solution:
(x,y)  (x, getmaxy() - y)
x
y
x
y
Better Approximation as an Integer
FLOOR (x + 0.5)
Approximating x and y Coordinates
int dpx(double x)
{
int p;
p=(int)(x+0.5);
return p;
}
int dpy(double y)
{
int p;
p=(int)(y+0.5);
p=getmaxy()-p;
return p;
}
Displaying a Point
void main()
{
ginit();
putpixel(dpx(50.2),dpy(70.7),15);
getch();
gexit();
}
Any Questions?
Thank You!

Contenu connexe

Tendances

3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphicssabbirantor
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformationSelvakumar Gna
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arraysmussawir20
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmrajivagarwal23dei
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in CompilerAkhil Kaushik
 
Introduction to Python Programming language.pptx
Introduction to Python Programming language.pptxIntroduction to Python Programming language.pptx
Introduction to Python Programming language.pptxBharathYusha1
 
Applications Of Computer Graphics
Applications Of Computer GraphicsApplications Of Computer Graphics
Applications Of Computer GraphicsMuhammad Amjad Rana
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphicsKamal Acharya
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in cPrabhu Govind
 
Graphics software and standards
Graphics software and standardsGraphics software and standards
Graphics software and standardsMani Kanth
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphicsSHIVANI SONI
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!Fariz Darari
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksEueung Mulyana
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projectionPooja Dixit
 
applications of computer graphics
applications of computer graphicsapplications of computer graphics
applications of computer graphicsAaina Katyal
 

Tendances (20)

3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
File in C language
File in C languageFile in C language
File in C language
 
Python ppt
Python pptPython ppt
Python ppt
 
Data types
Data typesData types
Data types
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithm
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
Introduction to Python Programming language.pptx
Introduction to Python Programming language.pptxIntroduction to Python Programming language.pptx
Introduction to Python Programming language.pptx
 
Applications Of Computer Graphics
Applications Of Computer GraphicsApplications Of Computer Graphics
Applications Of Computer Graphics
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphics
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphics
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Graphics software and standards
Graphics software and standardsGraphics software and standards
Graphics software and standards
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projection
 
applications of computer graphics
applications of computer graphicsapplications of computer graphics
applications of computer graphics
 

En vedette

Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics PracticalNeha Sharma
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics labPriya Goyal
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics ProgramesAbhishek Sharma
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphicsRafi_Dar
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneBhavesh Shah
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics FunctionsSHAKOOR AB
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALVivek Kumar Sinha
 
Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)Tushar B Kute
 
Computer graphics file
Computer graphics fileComputer graphics file
Computer graphics fileaman1001
 
Computer Graphics Applications
Computer Graphics ApplicationsComputer Graphics Applications
Computer Graphics ApplicationsSaravana Priya
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clippingavelraj
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicalsManoj Chauhan
 
Vighnesh testing developer
Vighnesh testing developerVighnesh testing developer
Vighnesh testing developervighnesh kumar
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
برمجة الرسوم بلغة السي بلس بلس المرحلة الثالثة
     برمجة الرسوم بلغة السي بلس بلس المرحلة الثالثة     برمجة الرسوم بلغة السي بلس بلس المرحلة الثالثة
برمجة الرسوم بلغة السي بلس بلس المرحلة الثالثةميثاق المعموري
 
1 c – graphic designs
1 c – graphic designs1 c – graphic designs
1 c – graphic designsHaseeb Patel
 

En vedette (20)

Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 
Graphics in C++
Graphics in C++Graphics in C++
Graphics in C++
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)
 
Computer graphics file
Computer graphics fileComputer graphics file
Computer graphics file
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Computer Graphics Applications
Computer Graphics ApplicationsComputer Graphics Applications
Computer Graphics Applications
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
 
Vighnesh testing developer
Vighnesh testing developerVighnesh testing developer
Vighnesh testing developer
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
برمجة الرسوم بلغة السي بلس بلس المرحلة الثالثة
     برمجة الرسوم بلغة السي بلس بلس المرحلة الثالثة     برمجة الرسوم بلغة السي بلس بلس المرحلة الثالثة
برمجة الرسوم بلغة السي بلس بلس المرحلة الثالثة
 
1 c – graphic designs
1 c – graphic designs1 c – graphic designs
1 c – graphic designs
 

Similaire à Graphics Programming in C

Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io
 
Sachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin Kumar
 
Simple c program
Simple c programSimple c program
Simple c programRavi Singh
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Pritam Samanta
 
Circles graphic
Circles graphicCircles graphic
Circles graphicalldesign
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docxPayalJindal19
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHFC BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHFAbcdR5
 
A 3D printing programming API
A 3D printing programming APIA 3D printing programming API
A 3D printing programming APIMax Kleiner
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)JAINAM KAPADIYA
 

Similaire à Graphics Programming in C (20)

graphics ss.pdf
graphics ss.pdfgraphics ss.pdf
graphics ss.pdf
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
1.2.3.pptx
1.2.3.pptx1.2.3.pptx
1.2.3.pptx
 
Sachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin kumar ppt on programming in c
Sachin kumar ppt on programming in c
 
Hidden Dragons of CGO
Hidden Dragons of CGOHidden Dragons of CGO
Hidden Dragons of CGO
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
Simple c program
Simple c programSimple c program
Simple c program
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game
 
02 c++g3 d (1)
02 c++g3 d (1)02 c++g3 d (1)
02 c++g3 d (1)
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHFC BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
 
A 3D printing programming API
A 3D printing programming APIA 3D printing programming API
A 3D printing programming API
 
10java 2d
10java 2d10java 2d
10java 2d
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Graphics mod
Graphics modGraphics mod
Graphics mod
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
 

Plus de Kasun Ranga Wijeweera

Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonKasun Ranga Wijeweera
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmKasun Ranga Wijeweera
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingKasun Ranga Wijeweera
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic ProgrammingKasun Ranga Wijeweera
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingKasun Ranga Wijeweera
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Kasun Ranga Wijeweera
 

Plus de Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
 

Dernier

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Dernier (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Graphics Programming in C

  • 1. Graphics Programming in C Kasun Ranga Wijeweera (Email: krw19870829@gmail.com)
  • 2. Evaluation Criteria • Project: 40% • End Semester Examination: 60%
  • 3. Course Content • Introduction to Graphics Programming in C • Points, Lines and Polygons • Line Drawing Algorithms • Circle Drawing Algorithms • Area Filling Algorithms • Geometric Transformations in 2D • Geometric Transformations in 3D • Line Clipping Algorithms in 2D • Line Clipping Algorithms in 3D
  • 4. Integrated Development Environment • Turbo C++ , Version 3.0, Copyright (c) 1990, 1992 by Borland International, Inc
  • 5. Graphics Header File • Go to File  New • Type initgraph in the new window and right click on it • There you will find a program and using it lets try to create a header file to initialize and exit graphics mode • Open another file and save it as grap.h
  • 6. The grap.h Header File #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> void ginit() { …… …… } void gexit() { …… …… }
  • 7. The ginit() Function void ginit() { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; /* initialize graphics mode */ initgraph(&gdriver, &gmode, "D:/Tcpp/BGI"); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %sn", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* return with error code */ } }
  • 8. The gexit() Function void gexit() { closegraph(); }
  • 9. The First Program • Open a new file and save it as first.c • There you have to include the grap.h header file that had been created earlier • Then your first program should look like as follows and running it will give a black and empty screen #include<stdio.h> #include<conio.h> #include"D:/GP/header/grap.h" void main() { ginit(); getch(); gexit(); }
  • 10. The Output Screen • Execute following code to get the maximum x and maximum y values of the output screen #include<stdio.h> #include<conio.h> #include"D:/GP/header/grap.h" void main() { ginit(); printf("%d %d",getmaxx(),getmaxy()); getch(); gexit(); }
  • 12. The Output Screen • The y-axis is upside down? • The solution: (x,y)  (x, getmaxy() - y) x y x y
  • 13. Better Approximation as an Integer FLOOR (x + 0.5)
  • 14. Approximating x and y Coordinates int dpx(double x) { int p; p=(int)(x+0.5); return p; } int dpy(double y) { int p; p=(int)(y+0.5); p=getmaxy()-p; return p; }
  • 15. Displaying a Point void main() { ginit(); putpixel(dpx(50.2),dpy(70.7),15); getch(); gexit(); }