SlideShare a Scribd company logo
INTRODUCTION
Ali Saadoon Ahmed
Computer Graphics
Lab
How do graphics work in C++
• The functions of C++ are used to implement graphics in a two-dimensional space.
Output can be viewed in a window or on a canvas. In this class, we made use of the
DevC++ IDE since it provides a solid structure upon which to build our drawings.
• To install the graphics library, we can refer to WinBGIm.DevC++ requires graphics.h
and libbgi.a. Next, select project options, then the parameter tab, and paste lbgi -
lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 in a linker tab.
Basic Graphic Programming in C++
Link Dev C++ : https://sourceforge.net/projects/orwelldevcpp/
Link of Graphics header files
https://www.dropbox.com/s/kjk46f5lh5uxn28/Graphics%20in%20Dev%20C++.rar?dl=0
Outtextxy Function
#include<graphics.h>
using namespace std;
main()
{
initwindow(500,500);
outtextxy(100, 200, "My first C++ graphics
program");
getch();
}
A code plot point in C++
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
main()
{
int x=40,y=50,h=10;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:tcbgi");
putpixel(x,y,h);
getch();
}
// C++ Implementation for drawing
line
#include <graphics.h>
main()
{
// gm is Graphics mode which is a computer display
// mode that generates images using pixels.
// DETECT is a macro defined in "graphics.h" header file
int gd = DETECT, gm;
// initgraph initializes the graphics system
// by loading a graphics driver from the disk
initgraph(&gd, &gm, "c:tcbgi");
// line for x1, y1, x2, y2
line(150, 150, 450, 150);
getch();
// close graph function closes the graphics
// mode and deallocates all memory allocated
// by graphics system.
closegraph();
}
Rectangle Function
The rectangle function is used to draw a rectangle between two points on the screen. Its syntax is:
rectangle (x1, y1, x2, y2);
For example, to draw a rectangle between the upper left comer & bottom right corner of the screen (for VGA
monitor), the statement is written as:
rectangle(0, 0, 639, 479);
or
rectangle (639, 479,0, 0);
Point (0, 0) represents the upper left corner of the screen, and point (639, 479) represents the bottom right comer
of the screen.
make a rectangle in c++ using the
rectangle function in graphics mode
#include<graphics.h>
#include<conio.h>
main()
{
int d,m;
d= detect;
initgraph(&d, &m, "c:tcbgi”);
rectangle(100,300,500,200);
getch();
closegraph();
}
Change the color of any shape in c++
#include<graphics.h>
using namespace std;
main()
{
initwindow(500,500);// ‫دالة‬
‫تهيئة‬
‫شاشة‬
‫الرسم‬
setcolor(YELLOW); // ‫اللون‬ ‫تحديد‬ ‫دالة‬
rectangle(40,70,410,290); // ‫المستطيل‬ ‫رسم‬ ‫دالة‬
setfillstyle(SOLID_FILL,YELLOW); // ‫ونوع‬ ‫اللون‬ ‫تعبئة‬ ‫نمط‬ ‫دالة‬
‫اللون‬
floodfill(200,200,YELLOW); // ‫المحدد‬ ‫باللون‬ ‫الشكل‬ ‫ملئ‬ ‫دالة‬
getch();
}
make a circle in c++
#include<graphics.h>
using namespace std;
main()
{
initwindow(500,500);
circle(200,200,100);
getch();
}
Change the color of the circle
#include<graphics.h>
using namespace std;
main()
{
initwindow(500,500);
setcolor(LIGHTMAGENTA);
circle(200,200,100);
setfillstyle(SOLID_FILL,LIGHTMAGENTA);
floodfill(200,200, LIGHTMAGENTA);
getch();
}
Below is the table showing INT VALUES corresponding to Colors :
COLOR INT VALUES
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
Same example
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
setbkcolor(5);//set background color
setcolor(11); //color of time
settextstyle(4, HORIZ_DIR, 8);//font of
time
setcolor(GREEN);
circle(320,240,100);
setcolor(RED);
outtextxy(100,50,“yes, It is circle");
getch();
closegraph();
}
Example Ellipse function
#include<graphics.h>
using namespace std;
main()
{
ellipse(100, 100, 0, 360, 50, 25);
getch();
}
Example Arc function in C++ - Graphics.
#include<graphics.h>
using namespace std;
main()
{
initwindow(500,500);
arc(100, 100, 0, 135, 50); // ‫القوس‬ ‫رسم‬ ‫دالة‬
getch();
}
Bar3d function is used to draw a 2-dimensional rectangular
#include<graphics.h>
using namespace std;
main()
{
initwindow(500,500);
bar3d (100 , 100 , 200 , 200 , 20 , 1);
getch();
}
Exercise Create a WAP to create a Hut
#include<graphics.h>
#include<conio.h>
int main(){
int gd = DETECT,gm;
initgraph(&gd, &gm, "c:TCBGI");
/* Draw Hut */
setcolor(WHITE);
rectangle(150,180,250,300);
rectangle(250,180,420,300);
rectangle(180,250,220,300);
line(200,100,150,180);
line(200,100,250,180);
line(200,100,370,100);
line(370,100,420,180);
/* Fill colours */
setfillstyle(SOLID_FILL, BROWN);
floodfill(152, 182, WHITE);
floodfill(252, 182, WHITE);
setfillstyle(SLASH_FILL, BLUE);
floodfill(182, 252, WHITE);
setfillstyle(HATCH_FILL, GREEN);
floodfill(200, 105, WHITE);
floodfill(210, 105, WHITE);
getch();
closegraph();
}
Exercise WAP to draw stars in the night sky.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
int main() {
int gd = DETECT, gm;
int i, x, y;
initgraph(&gd, &gm, "c:tcbgi");
while(!kbhit())
{
for(i=0; i<=500; i++)
{
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,15); //putpixel(x,y,i);
}
delay(500);
cleardevice();
}
getch();
closegraph(); }
Moving Car Animation.
Code Moving Car Animation.
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>
main() {
int gd = DETECT, gm;
int i, maxx, midy;
initgraph(&gd, &gm, "c:Turboc3BGI");
maxx = getmaxx();
midy = getmaxy()/2;
for(i=0; i< maxx-150; i=i+5)
{
cleardevice();
setcolor(WHITE);
line(0, midy + 37, maxx, midy + 37);
Code Moving Car Animation.
/* Draw Car */
setcolor(YELLOW);
setfillstyle(SOLID_FILL, RED);
line(i, midy + 23, i, midy);
line(i, midy, 40 + i, midy - 20);
line(40 + i, midy - 20, 80 + i, midy - 20);
line(80 + i, midy - 20, 100 + i, midy);
line(100 + i, midy, 120 + i, midy);
line(120 + i, midy, 120 + i, midy + 23);
line(0 + i, midy + 23, 18 + i, midy + 23);
arc(30 + i, midy + 23, 0, 180, 12);
line(42 + i, midy + 23, 78 + i, midy + 23);
arc(90 + i, midy + 23, 0, 180, 12);
line(102 + i, midy + 23, 120 + i, midy + 23);
line(28 + i, midy, 43 + i, midy - 15);
line(43 + i, midy - 15, 57 + i, midy - 15);
line(57 + i, midy - 15, 57 + i, midy);
line(57 + i, midy, 28 + i, midy);
line(62 + i, midy - 15, 77 + i, midy - 15);
line(77 + i, midy - 15, 92 + i, midy);
line(92 + i, midy, 62 + i, midy);
line(62 + i, midy, 62 + i, midy - 15);
floodfill(5 + i, midy + 22, YELLOW);
setcolor(BLUE);
setfillstyle(SOLID_FILL, DARKGRAY);
Code Moving Car Animation.
/* Draw Wheels */
circle(30 + i, midy + 25, 9);
circle(90 + i, midy + 25, 9);
floodfill(30 + i, midy + 25, BLUE);
floodfill(90 + i, midy + 25, BLUE);
delay(100);
}
getch();
closegraph();
}
Pie Chart
Pie Chart. (In this program, we'll draw multiple pie slices using pieslice with a
120-pixel radius and different start and end angles. Using setfillstyle, we change
the pie slice fill color.
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:Turboc3BGI");
int x,y;
settextstyle(BOLD_FONT,HORIZ_DIR,2);
outtextxy(220,10,"PIE CHART");
Pie Chart
//Setting cordinate of center of circle
x = getmaxx()/2;
y = getmaxy()/2;
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1);
setfillstyle(SOLID_FILL, RED);
pieslice(x, y, 0, 60, 120);
outtextxy(x + 140, y - 70, "FOOD");
setfillstyle(SOLID_FILL, YELLOW);
pieslice(x, y, 60, 160, 120);
outtextxy(x - 30, y - 170, "RENT");
setfillstyle(SOLID_FILL, GREEN);
pieslice(x, y, 160, 220, 120);
outtextxy(x - 250, y, "ELECTRICITY");
setfillstyle(SOLID_FILL, BROWN);
pieslice(x, y, 220, 360, 120);
outtextxy(x, y + 150, "SAVINGS");
getch();
closegraph();
}
C++ program to draw the moving
cycle using computer graphics
Code cycle using computer graphics
#include <conio.h>
#include <dos.h>
#include <graphics.h>
// Driver code
int main()
{
int gd = DETECT, gm, i, a;
// Path of the program
initgraph(&gd, &gm, "C:TURBOC3BGI");
Code cycle using computer graphics
// Move the cycle
for (i = 0; i < 600; i++) {
// Upper body of cycle
line(50 + i, 405, 100 + i, 405);
line(75 + i, 375, 125 + i, 375);
line(50 + i, 405, 75 + i, 375);
line(100 + i, 405, 100 + i, 345);
line(150 + i, 405, 100 + i, 345);
line(75 + i, 345, 75 + i, 370);
line(70 + i, 370, 80 + i, 370);
line(80 + i, 345, 100 + i, 345);
Code cycle using computer graphics
// Wheel
circle(150 + i, 405, 30);
circle(50 + i, 405, 30);
// Road
line(0, 436, getmaxx(), 436);
// Stone
rectangle(getmaxx() - i, 436,
650 - i, 431);
// Stop the screen for 10 secs
delay(10);
// Clear the screen
cleardevice();
}
getch();
// Close the graph
closegraph();
}

More Related Content

Similar to bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf

Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
JAINAM KAPADIYA
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
SHAKOOR AB
 
Code for program to draw a circle using mid point circle algorithm in c
Code for program to draw a circle using mid point circle algorithm in cCode for program to draw a circle using mid point circle algorithm in c
Code for program to draw a circle using mid point circle algorithm in c
Ossa2015
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
alldesign
 
Creating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdfCreating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdf
ShaiAlmog1
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
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
ShaiAlmog1
 
Uts
UtsUts
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Uma mohan
 
Program uts
Program utsProgram uts
Program uts
ditaerlita
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
Applet life cycle
Applet life cycleApplet life cycle
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
Mitul Patel
 
Write a program to perform translation.
 Write a program to perform translation. Write a program to perform translation.
Write a program to perform translation.
Shobhit Saxena
 
Write a program to perform translation
Write a program to perform translationWrite a program to perform translation
Write a program to perform translation
Shobhit Saxena
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
PayalJindal19
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41
Bilal Ahmed
 

Similar to bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf (20)

Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
Code for program to draw a circle using mid point circle algorithm in c
Code for program to draw a circle using mid point circle algorithm in cCode for program to draw a circle using mid point circle algorithm in c
Code for program to draw a circle using mid point circle algorithm in c
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
 
Creating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdfCreating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdf
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
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
 
Uts
UtsUts
Uts
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Program uts
Program utsProgram uts
Program uts
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
Write a program to perform translation.
 Write a program to perform translation. Write a program to perform translation.
Write a program to perform translation.
 
Write a program to perform translation
Write a program to perform translationWrite a program to perform translation
Write a program to perform translation
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41
 

Recently uploaded

What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
moosaasad1975
 
Orion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWSOrion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWS
Columbia Weather Systems
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Sérgio Sacani
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
Sérgio Sacani
 
Deep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless ReproducibilityDeep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless Reproducibility
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
S.1 chemistry scheme term 2 for ordinary level
S.1 chemistry scheme term 2 for ordinary levelS.1 chemistry scheme term 2 for ordinary level
S.1 chemistry scheme term 2 for ordinary level
ronaldlakony0
 
Comparative structure of adrenal gland in vertebrates
Comparative structure of adrenal gland in vertebratesComparative structure of adrenal gland in vertebrates
Comparative structure of adrenal gland in vertebrates
sachin783648
 
NuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final versionNuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final version
pablovgd
 
extra-chromosomal-inheritance[1].pptx.pdfpdf
extra-chromosomal-inheritance[1].pptx.pdfpdfextra-chromosomal-inheritance[1].pptx.pdfpdf
extra-chromosomal-inheritance[1].pptx.pdfpdf
DiyaBiswas10
 
In silico drugs analogue design: novobiocin analogues.pptx
In silico drugs analogue design: novobiocin analogues.pptxIn silico drugs analogue design: novobiocin analogues.pptx
In silico drugs analogue design: novobiocin analogues.pptx
AlaminAfendy1
 
Hemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptxHemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptx
muralinath2
 
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdfUnveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Erdal Coalmaker
 
Leaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdfLeaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdf
RenuJangid3
 
general properties of oerganologametal.ppt
general properties of oerganologametal.pptgeneral properties of oerganologametal.ppt
general properties of oerganologametal.ppt
IqrimaNabilatulhusni
 
Richard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlandsRichard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlands
Richard Gill
 
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATIONPRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
ChetanK57
 
nodule formation by alisha dewangan.pptx
nodule formation by alisha dewangan.pptxnodule formation by alisha dewangan.pptx
nodule formation by alisha dewangan.pptx
alishadewangan1
 
GBSN - Microbiology (Lab 4) Culture Media
GBSN - Microbiology (Lab 4) Culture MediaGBSN - Microbiology (Lab 4) Culture Media
GBSN - Microbiology (Lab 4) Culture Media
Areesha Ahmad
 
Chapter 12 - climate change and the energy crisis
Chapter 12 - climate change and the energy crisisChapter 12 - climate change and the energy crisis
Chapter 12 - climate change and the energy crisis
tonzsalvador2222
 
Seminar of U.V. Spectroscopy by SAMIR PANDA
 Seminar of U.V. Spectroscopy by SAMIR PANDA Seminar of U.V. Spectroscopy by SAMIR PANDA
Seminar of U.V. Spectroscopy by SAMIR PANDA
SAMIR PANDA
 

Recently uploaded (20)

What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
 
Orion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWSOrion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWS
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
 
Deep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless ReproducibilityDeep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless Reproducibility
 
S.1 chemistry scheme term 2 for ordinary level
S.1 chemistry scheme term 2 for ordinary levelS.1 chemistry scheme term 2 for ordinary level
S.1 chemistry scheme term 2 for ordinary level
 
Comparative structure of adrenal gland in vertebrates
Comparative structure of adrenal gland in vertebratesComparative structure of adrenal gland in vertebrates
Comparative structure of adrenal gland in vertebrates
 
NuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final versionNuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final version
 
extra-chromosomal-inheritance[1].pptx.pdfpdf
extra-chromosomal-inheritance[1].pptx.pdfpdfextra-chromosomal-inheritance[1].pptx.pdfpdf
extra-chromosomal-inheritance[1].pptx.pdfpdf
 
In silico drugs analogue design: novobiocin analogues.pptx
In silico drugs analogue design: novobiocin analogues.pptxIn silico drugs analogue design: novobiocin analogues.pptx
In silico drugs analogue design: novobiocin analogues.pptx
 
Hemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptxHemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptx
 
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdfUnveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdf
 
Leaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdfLeaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdf
 
general properties of oerganologametal.ppt
general properties of oerganologametal.pptgeneral properties of oerganologametal.ppt
general properties of oerganologametal.ppt
 
Richard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlandsRichard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlands
 
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATIONPRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
 
nodule formation by alisha dewangan.pptx
nodule formation by alisha dewangan.pptxnodule formation by alisha dewangan.pptx
nodule formation by alisha dewangan.pptx
 
GBSN - Microbiology (Lab 4) Culture Media
GBSN - Microbiology (Lab 4) Culture MediaGBSN - Microbiology (Lab 4) Culture Media
GBSN - Microbiology (Lab 4) Culture Media
 
Chapter 12 - climate change and the energy crisis
Chapter 12 - climate change and the energy crisisChapter 12 - climate change and the energy crisis
Chapter 12 - climate change and the energy crisis
 
Seminar of U.V. Spectroscopy by SAMIR PANDA
 Seminar of U.V. Spectroscopy by SAMIR PANDA Seminar of U.V. Spectroscopy by SAMIR PANDA
Seminar of U.V. Spectroscopy by SAMIR PANDA
 

bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf

  • 2. How do graphics work in C++ • The functions of C++ are used to implement graphics in a two-dimensional space. Output can be viewed in a window or on a canvas. In this class, we made use of the DevC++ IDE since it provides a solid structure upon which to build our drawings. • To install the graphics library, we can refer to WinBGIm.DevC++ requires graphics.h and libbgi.a. Next, select project options, then the parameter tab, and paste lbgi - lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 in a linker tab.
  • 3. Basic Graphic Programming in C++ Link Dev C++ : https://sourceforge.net/projects/orwelldevcpp/ Link of Graphics header files https://www.dropbox.com/s/kjk46f5lh5uxn28/Graphics%20in%20Dev%20C++.rar?dl=0
  • 4. Outtextxy Function #include<graphics.h> using namespace std; main() { initwindow(500,500); outtextxy(100, 200, "My first C++ graphics program"); getch(); }
  • 5.
  • 6. A code plot point in C++ #include <stdio.h> #include <conio.h> #include <graphics.h> main() { int x=40,y=50,h=10; int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, "c:tcbgi"); putpixel(x,y,h); getch(); }
  • 7.
  • 8. // C++ Implementation for drawing line #include <graphics.h> main() { // gm is Graphics mode which is a computer display // mode that generates images using pixels. // DETECT is a macro defined in "graphics.h" header file int gd = DETECT, gm; // initgraph initializes the graphics system // by loading a graphics driver from the disk initgraph(&gd, &gm, "c:tcbgi"); // line for x1, y1, x2, y2 line(150, 150, 450, 150); getch(); // close graph function closes the graphics // mode and deallocates all memory allocated // by graphics system. closegraph(); }
  • 9. Rectangle Function The rectangle function is used to draw a rectangle between two points on the screen. Its syntax is: rectangle (x1, y1, x2, y2); For example, to draw a rectangle between the upper left comer & bottom right corner of the screen (for VGA monitor), the statement is written as: rectangle(0, 0, 639, 479); or rectangle (639, 479,0, 0); Point (0, 0) represents the upper left corner of the screen, and point (639, 479) represents the bottom right comer of the screen.
  • 10. make a rectangle in c++ using the rectangle function in graphics mode #include<graphics.h> #include<conio.h> main() { int d,m; d= detect; initgraph(&d, &m, "c:tcbgi”); rectangle(100,300,500,200); getch(); closegraph(); }
  • 11. Change the color of any shape in c++ #include<graphics.h> using namespace std; main() { initwindow(500,500);// ‫دالة‬ ‫تهيئة‬ ‫شاشة‬ ‫الرسم‬ setcolor(YELLOW); // ‫اللون‬ ‫تحديد‬ ‫دالة‬ rectangle(40,70,410,290); // ‫المستطيل‬ ‫رسم‬ ‫دالة‬ setfillstyle(SOLID_FILL,YELLOW); // ‫ونوع‬ ‫اللون‬ ‫تعبئة‬ ‫نمط‬ ‫دالة‬ ‫اللون‬ floodfill(200,200,YELLOW); // ‫المحدد‬ ‫باللون‬ ‫الشكل‬ ‫ملئ‬ ‫دالة‬ getch(); }
  • 12. make a circle in c++ #include<graphics.h> using namespace std; main() { initwindow(500,500); circle(200,200,100); getch(); }
  • 13. Change the color of the circle #include<graphics.h> using namespace std; main() { initwindow(500,500); setcolor(LIGHTMAGENTA); circle(200,200,100); setfillstyle(SOLID_FILL,LIGHTMAGENTA); floodfill(200,200, LIGHTMAGENTA); getch(); }
  • 14. Below is the table showing INT VALUES corresponding to Colors : COLOR INT VALUES BLACK 0 BLUE 1 GREEN 2 CYAN 3 RED 4 MAGENTA 5 BROWN 6 LIGHTGRAY 7 DARKGRAY 8 LIGHTBLUE 9 LIGHTGREEN 10 LIGHTCYAN 11 LIGHTRED 12 LIGHTMAGENTA 13 YELLOW 14 WHITE 15
  • 15. Same example #include<stdio.h> #include<conio.h> #include<graphics.h> main() { int gd=DETECT,gm; initgraph(&gd,&gm," "); setbkcolor(5);//set background color setcolor(11); //color of time settextstyle(4, HORIZ_DIR, 8);//font of time setcolor(GREEN); circle(320,240,100); setcolor(RED); outtextxy(100,50,“yes, It is circle"); getch(); closegraph(); }
  • 16. Example Ellipse function #include<graphics.h> using namespace std; main() { ellipse(100, 100, 0, 360, 50, 25); getch(); }
  • 17. Example Arc function in C++ - Graphics. #include<graphics.h> using namespace std; main() { initwindow(500,500); arc(100, 100, 0, 135, 50); // ‫القوس‬ ‫رسم‬ ‫دالة‬ getch(); }
  • 18. Bar3d function is used to draw a 2-dimensional rectangular #include<graphics.h> using namespace std; main() { initwindow(500,500); bar3d (100 , 100 , 200 , 200 , 20 , 1); getch(); }
  • 19. Exercise Create a WAP to create a Hut #include<graphics.h> #include<conio.h> int main(){ int gd = DETECT,gm; initgraph(&gd, &gm, "c:TCBGI"); /* Draw Hut */ setcolor(WHITE); rectangle(150,180,250,300); rectangle(250,180,420,300); rectangle(180,250,220,300); line(200,100,150,180); line(200,100,250,180); line(200,100,370,100); line(370,100,420,180); /* Fill colours */ setfillstyle(SOLID_FILL, BROWN); floodfill(152, 182, WHITE); floodfill(252, 182, WHITE); setfillstyle(SLASH_FILL, BLUE); floodfill(182, 252, WHITE); setfillstyle(HATCH_FILL, GREEN); floodfill(200, 105, WHITE); floodfill(210, 105, WHITE); getch(); closegraph(); }
  • 20. Exercise WAP to draw stars in the night sky. #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<stdlib.h> int main() { int gd = DETECT, gm; int i, x, y; initgraph(&gd, &gm, "c:tcbgi"); while(!kbhit()) { for(i=0; i<=500; i++) { x=rand()%getmaxx(); y=rand()%getmaxy(); putpixel(x,y,15); //putpixel(x,y,i); } delay(500); cleardevice(); } getch(); closegraph(); }
  • 22. Code Moving Car Animation. #include <stdio.h> #include <graphics.h> #include <conio.h> #include <dos.h> main() { int gd = DETECT, gm; int i, maxx, midy; initgraph(&gd, &gm, "c:Turboc3BGI"); maxx = getmaxx(); midy = getmaxy()/2; for(i=0; i< maxx-150; i=i+5) { cleardevice(); setcolor(WHITE); line(0, midy + 37, maxx, midy + 37);
  • 23. Code Moving Car Animation. /* Draw Car */ setcolor(YELLOW); setfillstyle(SOLID_FILL, RED); line(i, midy + 23, i, midy); line(i, midy, 40 + i, midy - 20); line(40 + i, midy - 20, 80 + i, midy - 20); line(80 + i, midy - 20, 100 + i, midy); line(100 + i, midy, 120 + i, midy); line(120 + i, midy, 120 + i, midy + 23); line(0 + i, midy + 23, 18 + i, midy + 23); arc(30 + i, midy + 23, 0, 180, 12); line(42 + i, midy + 23, 78 + i, midy + 23); arc(90 + i, midy + 23, 0, 180, 12); line(102 + i, midy + 23, 120 + i, midy + 23); line(28 + i, midy, 43 + i, midy - 15); line(43 + i, midy - 15, 57 + i, midy - 15); line(57 + i, midy - 15, 57 + i, midy); line(57 + i, midy, 28 + i, midy); line(62 + i, midy - 15, 77 + i, midy - 15); line(77 + i, midy - 15, 92 + i, midy); line(92 + i, midy, 62 + i, midy); line(62 + i, midy, 62 + i, midy - 15); floodfill(5 + i, midy + 22, YELLOW); setcolor(BLUE); setfillstyle(SOLID_FILL, DARKGRAY);
  • 24. Code Moving Car Animation. /* Draw Wheels */ circle(30 + i, midy + 25, 9); circle(90 + i, midy + 25, 9); floodfill(30 + i, midy + 25, BLUE); floodfill(90 + i, midy + 25, BLUE); delay(100); } getch(); closegraph(); }
  • 25. Pie Chart Pie Chart. (In this program, we'll draw multiple pie slices using pieslice with a 120-pixel radius and different start and end angles. Using setfillstyle, we change the pie slice fill color. #include <graphics.h> #include <conio.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "c:Turboc3BGI"); int x,y; settextstyle(BOLD_FONT,HORIZ_DIR,2); outtextxy(220,10,"PIE CHART");
  • 26. Pie Chart //Setting cordinate of center of circle x = getmaxx()/2; y = getmaxy()/2; settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1); setfillstyle(SOLID_FILL, RED); pieslice(x, y, 0, 60, 120); outtextxy(x + 140, y - 70, "FOOD"); setfillstyle(SOLID_FILL, YELLOW); pieslice(x, y, 60, 160, 120); outtextxy(x - 30, y - 170, "RENT"); setfillstyle(SOLID_FILL, GREEN); pieslice(x, y, 160, 220, 120); outtextxy(x - 250, y, "ELECTRICITY"); setfillstyle(SOLID_FILL, BROWN); pieslice(x, y, 220, 360, 120); outtextxy(x, y + 150, "SAVINGS"); getch(); closegraph(); }
  • 27. C++ program to draw the moving cycle using computer graphics
  • 28. Code cycle using computer graphics #include <conio.h> #include <dos.h> #include <graphics.h> // Driver code int main() { int gd = DETECT, gm, i, a; // Path of the program initgraph(&gd, &gm, "C:TURBOC3BGI");
  • 29. Code cycle using computer graphics // Move the cycle for (i = 0; i < 600; i++) { // Upper body of cycle line(50 + i, 405, 100 + i, 405); line(75 + i, 375, 125 + i, 375); line(50 + i, 405, 75 + i, 375); line(100 + i, 405, 100 + i, 345); line(150 + i, 405, 100 + i, 345); line(75 + i, 345, 75 + i, 370); line(70 + i, 370, 80 + i, 370); line(80 + i, 345, 100 + i, 345);
  • 30. Code cycle using computer graphics // Wheel circle(150 + i, 405, 30); circle(50 + i, 405, 30); // Road line(0, 436, getmaxx(), 436); // Stone rectangle(getmaxx() - i, 436, 650 - i, 431); // Stop the screen for 10 secs delay(10); // Clear the screen cleardevice(); } getch(); // Close the graph closegraph(); }