SlideShare a Scribd company logo
1 of 38
Download to read offline
Borland Style Graphics
for Dev C++)
Mr. Dave Clausen
La Cañada High School
Mr. Dave Clausen 2
The Text Screen
n The text screen contains 25 lines with a
capacity of holding 80 columns of textual
characters.
n 80 X 25 = 2,000 positions
n But there are actually over 2,000 positions on
a display screen.
n The screen consists of pixels (picture
elements) that it uses to represent the textual
characters and symbols.
Mr. Dave Clausen 3
Graphics Setup
n Here are the steps that you need to follow
to use “Borland Style Graphics” source
code in Dev C++:
1. Tell the compiler that graphics commands
will be used.
2. Initialize the Graphics Screen
3. Close the graphics screen after you have
finished drawing your graphics.
Mr. Dave Clausen 4
Graphics Setup 2
n 1) To tell the compiler that graphics
commands will be used, include the
preprocessor directive:
#include <graphics.h>
Mr. Dave Clausen 5
Graphics Setup 3
• 2) To initialize the graphics screen
initwindow(640,480);
After you are finished drawing, you need to use the
while(!kbhit()); command to leave the picture on
the screen, or use cin.get();
The last choice requires: #include <iostream.h>
• 5) Then close the graphics screen, using:
closegraph( );
Mr. Dave Clausen 6
Fundamentals
of
Graphics
n The Graphics Screen.
n Color Options.
n Graphics Mode.
n Drawing Lines
n Line Style
n Clearing the Screen.
n Plotting Points.
Mr. Dave Clausen 7
n If you have a VGA graphics card or better
in your computer, then the graphics screen
has 640 pixels across and 480 pixels
down.
n 640 X 480 = 307,200 pixels
n The upper left corner is position (0, 0)
n The lower right corner is position
(639, 479)
• Remember, the computer starts counting with
zero.
The Graphics Screen
Mr. Dave Clausen 8
The Graphics Screen
Dimensions
(0, 0) (639, 0)
(0, 479) (639, 479)
Mr. Dave Clausen 9
§ You can select the color of the background.
§ This is done before drawing anything in the
foreground (otherwise your drawing will
disappear.)
§ To select the background color use the
command.
§ setbkcolor(number);
§ Where (number) is a numeric constant from 0
through 15, or the symbolic constant that represents
the color.
Background
Color Options
Mr. Dave Clausen 10
Color Options
n You select a foreground or “drawing” color by
using the following command:
setcolor(number);
• Where (number) is a numeric constant from 0
through 15, or the symbolic constant that
represents the color.
Mr. Dave Clausen 11
Color Names
Here are the color numbers and names:
0 = BLACK
1 = BLUE
2 = GREEN
3 = CYAN
4 = RED
5 = MAGENTA
6 = BROWN
7 = LIGHTGRAY
8 = DARKGRAY
9 = LIGHTBLUE
10 = LIGHTGREEN
11 = LIGHTCYAN
12 = LIGHTRED
13 = LIGHTMAGENTA
14 = YELLOW
15 = WHITE
Mr. Dave Clausen 12
Drawing Lines
§ The Current Pointer.
The current pointer is an invisible pointer
that keeps track of the current pixel
position. It is the equivalent of the visible
cursor in text mode.
Mr. Dave Clausen 13
§ To move the pointer to a location on the
graph without drawing anything, use the
command:
§ moveto (X,Y);
§ This is like PenUp (PU) in LOGO
§ To draw lines from the current pointer’s
position to another point on the graph, use
the command:
§ lineto (X,Y);
§ This is like PenDown (PD) in LOGO or SetXY (x, y)
grtmplte.cpp
Drawing Lines 2
Mr. Dave Clausen 14
Graphics Figures
•Lines
•Rectangles
•Circles
•Arcs
•Ellipses
•Points
Mr. Dave Clausen 15
Lines, The Easy Way
n Instead of using the commands: moveto
and lineto, we can draw a line using one
command:
line(x1, y1, x2, y2);
n The points (x1, y1) describe the beginning
of the line, while (x2, y2) describes the
endpoint of the line.
n The numbers x1, y1, x2, y2 are integers.
Mr. Dave Clausen 16
Rectangles
Rectangles can be drawn in different ways
using lineto, moveto, moverel, and linerel.
But an easier and faster way is using the
Rectangle procedure which draws a rectangle
in the default color and line style with the
upper left at X1, Y1 and lower right X2, Y2.
rectangle (x1, y1, x2, y2);
Mr. Dave Clausen 17
Circles
Circles can be drawn using the circle
procedure.
This draws a circle in the default color and
line style with center at X, Y, radius in the X
direction of Xradius, and corresponding Y
radius.
circle (x, y, radius);
Mr. Dave Clausen 18
Arcs
This procedure draws a circular arc in the
default color and line style based upon a circle
with center X, Y and given X radius.
The arc begins at an angle of StartAngle and
follows the circle to EndAngle. The angles are
measured in degrees from 0 to 360 counter-
clockwise where 0 degrees is directly right.
arc ( x, y, startangle, endangle, radius);
Mr. Dave Clausen 19
Visualizing Arcs
Starting & Ending
Angles
Mr. Dave Clausen 20
Ellipses
Draws an elliptical arc in the default color and
line style based upon an ellipse with center X,
Y and given radii.
The arc begins at an angle to Start Angle and
follows the ellipse to End Angle. The angles
are measured in degrees from 0 to 360 counter-
clockwise where 0 degrees is directly right.
ellipse ( x, y, startangle , endangle, x_radius, y_radius);
Mr. Dave Clausen 21
Plotting Points
§ The Maximum value for X can be
found using:
getmaxx( )
§ The Maximum value for Y can be found
using:
getmaxy( )
§ To Plot a point:
putpixel ( x_value, y_value, color);
For example: putpixel (100, 100, WHITE);
Mr. Dave Clausen 22
Sample Program
n Let’s look at a program with a line,
rectangle, circle, arc, ellipse, and a point.
Objects.cpp
Mr. Dave Clausen 23
Line Style
n Setting the line style.
All lines have a default line mode, but
Turbo C++ allows the user to specify three
characteristics of a line:
style, pattern, and thickness.
n Use the command:
setlinestyle (style, pattern, thickness);
Mr. Dave Clausen 24
Line Style
and
Thickness Names
Here are the names of the line styles and
thickness:
Line Style Thickness
SOLID_LINE NORM_WIDTH
DOTTED_LINE
CENTER_LINE THICK_WIDTH
DASHED_LINE
USERBIT_LINE
Mr. Dave Clausen 25
Line Style Patterns
n The names of the line patterns are:
SOLID_LINE = 0
DOTTED_LINE = 1
CENTER_LINE = 2
DASHED_LINE = 3
Mr. Dave Clausen 26
Filling Patterns
•Selecting Pattern and Color
•Filling Regions
•Getting a Pixel
Mr. Dave Clausen 27
Selecting Pattern
and Color
Use the command SetFillStyle for setting the
pattern and color for the object that you wish
to fill.
setfillstyle ( pattern, color);
Mr. Dave Clausen 28
Pattern Names
Here are the name of available patterns:
Values Causing filling with
EMPTY_FILL Background Color
SOLID_FILL Solid Color
LINE_FILL Horizontal Lines
LTSLASH_FILL Thin diagonal lines
SLASH_FILL Thick diagonal lines
BKSLASH_FILL Thick diagonal backslashes
LTBKSLASH_FILL Light backslashes
HATCH_FILLThin cross hatching
XHATCH_FILL Thick cross hatching
INTERLEAVE_FILL Interleaving lines
WIDE_DOT_FILL Widely spaced dots
CLOSE_DOT_FILL Closely spaced dots
Mr. Dave Clausen 29
Filling Regions
§After selecting a color and pattern,
floodfill is used to fill the desired area.
§floodfill ( x, y, border_color );
§This “paints out” the desired color until it
reaches border color.
§Note: The border color must be the same
color as the color used to draw the shape.
§Also, you can only fill completely
“closed” shapes.
Program10_4.cpp
Mr. Dave Clausen 30
§To draw a filled ellipse:
fillellipse ( xcoordinate, ycoordinate, xradius, yradius);
§ To draw a filled rectangle:
bar (x1, y1, x2, y2);
§To draw a filled 3D rectangle:
bar3d(x1, y1, x2, y2, depth, topflag); //depth is width of
the 3D rectangle, if topflag is non-0 a top is added to the bar
§ To draw a filled section of a circle:
pieslice (x, y, startangle, endangle, xradius);
Filling “Special” Regions
Mr. Dave Clausen 31
Text Output on the Graphics Screen
n To write a literal expression on the
graphics screen using the location
specified by (x, y) use the command:
outtextxy (x, y, “literal expression”);
outtextxy (x, y, string_variable);
Note: These are not “apstring” type
strings. They are C++ standard Strings.
Mr. Dave Clausen 32
n To set the values for the text characteristics, use:
settextstyle ( font, direction, charsize);
Font Direction
DEFAULT_FONT HORIZ_DIR = Left to right
TRIPLEX_FONT VERT_DIR = Bottom to top
SMALL_FONT
SANS_SERIF_FONT Fonts continued
GOTHIC_FONT COMPLEX_FONT
SCRIPT_FONT EUROPEAN_FONT
SIMPLEX_FONT BOLD_FONT
TRIPLEX_SCR_FONT
Text Styles
Mr. Dave Clausen 33
CharSize
1 = Default (normal)
2 = Double Size
3 = Triple Size
4 = 4 Times the normal
5 = 5 Times the normal
….
10 = 10 Times the normal
Text Styles
Font Sizes
Mr. Dave Clausen 34
n To set the way that text is located
around the point specified use the command:
settextjustify (horizontal,vertical);
Horizontal Vertical
LEFT_TEXT TOP_TEXT
CENTER_TEXT BOTTOM_TEXT
RIGHT_TEXT
Program10_2.cpp
Text Justification
Mr. Dave Clausen 35
Clearing the Screen
n Here is the way to clear the graphics
screen.
n When in graphics mode use:
cleardevice( ); //#include <graphics.h>
Mr. Dave Clausen 36
n Returns the height, in pixels, of string S if it
were to be written on the graphics screen
using the current defaults.
textheight (S string);
n Returns the width, in pixels, of string S if it
were to be written on the graphics screen
using the current defaults.
textwidth (S string);
Text
Height & Width
Mr. Dave Clausen 37
Getting a Pixel
n To return the color number corresponding to
the color located at the point: X, Y use the
command:
getpixel (x, y);
Mr. Dave Clausen 38
Useful Non Graphic Commands
n kbhit()
• checks to see if a keystroke is currently
available
• If a keystroke is available, returns a nonzero
integer.
• If a keystroke is not available, returns a zero.
n Any available keystrokes can be retrieved
with getch().

More Related Content

Similar to borland-style-graphics-for-dev-c.pdf

GrADS_reference_card.pdf
GrADS_reference_card.pdfGrADS_reference_card.pdf
GrADS_reference_card.pdfManoj MG
 
Powerpointpresentation.c
Powerpointpresentation.cPowerpointpresentation.c
Powerpointpresentation.cMaqbool Ur Khan
 
Javascript Art for Kids - Library Program
Javascript Art for Kids - Library ProgramJavascript Art for Kids - Library Program
Javascript Art for Kids - Library ProgramRino Landa
 
ch03g-graphics.ppt
ch03g-graphics.pptch03g-graphics.ppt
ch03g-graphics.pptMahyuddin8
 
computer graphics lab manual 2013-converted.pdf
computer graphics lab manual 2013-converted.pdfcomputer graphics lab manual 2013-converted.pdf
computer graphics lab manual 2013-converted.pdfSyedSajjadShah3
 
Geometry unit 7.1
Geometry unit 7.1Geometry unit 7.1
Geometry unit 7.1Mark Ryder
 
Basics of Digital Images
Basics of  Digital ImagesBasics of  Digital Images
Basics of Digital ImagesSaad Al-Momen
 
IntroductionToMathematica.pptx
IntroductionToMathematica.pptxIntroductionToMathematica.pptx
IntroductionToMathematica.pptxMuhammadImran1347
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
InDesign: Colors
InDesign: ColorsInDesign: Colors
InDesign: ColorsSam Georgi
 

Similar to borland-style-graphics-for-dev-c.pdf (20)

Códigos ESC P - EPSON
Códigos ESC P - EPSONCódigos ESC P - EPSON
Códigos ESC P - EPSON
 
GrADS_reference_card.pdf
GrADS_reference_card.pdfGrADS_reference_card.pdf
GrADS_reference_card.pdf
 
Introduction to Processing
Introduction to ProcessingIntroduction to Processing
Introduction to Processing
 
Powerpointpresentation.c
Powerpointpresentation.cPowerpointpresentation.c
Powerpointpresentation.c
 
Javascript Art for Kids - Library Program
Javascript Art for Kids - Library ProgramJavascript Art for Kids - Library Program
Javascript Art for Kids - Library Program
 
Finger detection
Finger detectionFinger detection
Finger detection
 
ch03g-graphics.ppt
ch03g-graphics.pptch03g-graphics.ppt
ch03g-graphics.ppt
 
computer graphics lab manual 2013-converted.pdf
computer graphics lab manual 2013-converted.pdfcomputer graphics lab manual 2013-converted.pdf
computer graphics lab manual 2013-converted.pdf
 
Geometry unit 7.1
Geometry unit 7.1Geometry unit 7.1
Geometry unit 7.1
 
Basics of Digital Images
Basics of  Digital ImagesBasics of  Digital Images
Basics of Digital Images
 
canvas.pptx
canvas.pptxcanvas.pptx
canvas.pptx
 
Implementation
ImplementationImplementation
Implementation
 
Auto cad for fashion design by v.s. bhati
Auto cad for fashion design by v.s. bhatiAuto cad for fashion design by v.s. bhati
Auto cad for fashion design by v.s. bhati
 
IntroductionToMathematica.pptx
IntroductionToMathematica.pptxIntroductionToMathematica.pptx
IntroductionToMathematica.pptx
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Java session14
Java session14Java session14
Java session14
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
Codeware
CodewareCodeware
Codeware
 
InDesign: Colors
InDesign: ColorsInDesign: Colors
InDesign: Colors
 
Mine sweeper
Mine sweeperMine sweeper
Mine sweeper
 

Recently uploaded

WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2
 

Recently uploaded (20)

WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 

borland-style-graphics-for-dev-c.pdf

  • 1. Borland Style Graphics for Dev C++) Mr. Dave Clausen La Cañada High School
  • 2. Mr. Dave Clausen 2 The Text Screen n The text screen contains 25 lines with a capacity of holding 80 columns of textual characters. n 80 X 25 = 2,000 positions n But there are actually over 2,000 positions on a display screen. n The screen consists of pixels (picture elements) that it uses to represent the textual characters and symbols.
  • 3. Mr. Dave Clausen 3 Graphics Setup n Here are the steps that you need to follow to use “Borland Style Graphics” source code in Dev C++: 1. Tell the compiler that graphics commands will be used. 2. Initialize the Graphics Screen 3. Close the graphics screen after you have finished drawing your graphics.
  • 4. Mr. Dave Clausen 4 Graphics Setup 2 n 1) To tell the compiler that graphics commands will be used, include the preprocessor directive: #include <graphics.h>
  • 5. Mr. Dave Clausen 5 Graphics Setup 3 • 2) To initialize the graphics screen initwindow(640,480); After you are finished drawing, you need to use the while(!kbhit()); command to leave the picture on the screen, or use cin.get(); The last choice requires: #include <iostream.h> • 5) Then close the graphics screen, using: closegraph( );
  • 6. Mr. Dave Clausen 6 Fundamentals of Graphics n The Graphics Screen. n Color Options. n Graphics Mode. n Drawing Lines n Line Style n Clearing the Screen. n Plotting Points.
  • 7. Mr. Dave Clausen 7 n If you have a VGA graphics card or better in your computer, then the graphics screen has 640 pixels across and 480 pixels down. n 640 X 480 = 307,200 pixels n The upper left corner is position (0, 0) n The lower right corner is position (639, 479) • Remember, the computer starts counting with zero. The Graphics Screen
  • 8. Mr. Dave Clausen 8 The Graphics Screen Dimensions (0, 0) (639, 0) (0, 479) (639, 479)
  • 9. Mr. Dave Clausen 9 § You can select the color of the background. § This is done before drawing anything in the foreground (otherwise your drawing will disappear.) § To select the background color use the command. § setbkcolor(number); § Where (number) is a numeric constant from 0 through 15, or the symbolic constant that represents the color. Background Color Options
  • 10. Mr. Dave Clausen 10 Color Options n You select a foreground or “drawing” color by using the following command: setcolor(number); • Where (number) is a numeric constant from 0 through 15, or the symbolic constant that represents the color.
  • 11. Mr. Dave Clausen 11 Color Names Here are the color numbers and names: 0 = BLACK 1 = BLUE 2 = GREEN 3 = CYAN 4 = RED 5 = MAGENTA 6 = BROWN 7 = LIGHTGRAY 8 = DARKGRAY 9 = LIGHTBLUE 10 = LIGHTGREEN 11 = LIGHTCYAN 12 = LIGHTRED 13 = LIGHTMAGENTA 14 = YELLOW 15 = WHITE
  • 12. Mr. Dave Clausen 12 Drawing Lines § The Current Pointer. The current pointer is an invisible pointer that keeps track of the current pixel position. It is the equivalent of the visible cursor in text mode.
  • 13. Mr. Dave Clausen 13 § To move the pointer to a location on the graph without drawing anything, use the command: § moveto (X,Y); § This is like PenUp (PU) in LOGO § To draw lines from the current pointer’s position to another point on the graph, use the command: § lineto (X,Y); § This is like PenDown (PD) in LOGO or SetXY (x, y) grtmplte.cpp Drawing Lines 2
  • 14. Mr. Dave Clausen 14 Graphics Figures •Lines •Rectangles •Circles •Arcs •Ellipses •Points
  • 15. Mr. Dave Clausen 15 Lines, The Easy Way n Instead of using the commands: moveto and lineto, we can draw a line using one command: line(x1, y1, x2, y2); n The points (x1, y1) describe the beginning of the line, while (x2, y2) describes the endpoint of the line. n The numbers x1, y1, x2, y2 are integers.
  • 16. Mr. Dave Clausen 16 Rectangles Rectangles can be drawn in different ways using lineto, moveto, moverel, and linerel. But an easier and faster way is using the Rectangle procedure which draws a rectangle in the default color and line style with the upper left at X1, Y1 and lower right X2, Y2. rectangle (x1, y1, x2, y2);
  • 17. Mr. Dave Clausen 17 Circles Circles can be drawn using the circle procedure. This draws a circle in the default color and line style with center at X, Y, radius in the X direction of Xradius, and corresponding Y radius. circle (x, y, radius);
  • 18. Mr. Dave Clausen 18 Arcs This procedure draws a circular arc in the default color and line style based upon a circle with center X, Y and given X radius. The arc begins at an angle of StartAngle and follows the circle to EndAngle. The angles are measured in degrees from 0 to 360 counter- clockwise where 0 degrees is directly right. arc ( x, y, startangle, endangle, radius);
  • 19. Mr. Dave Clausen 19 Visualizing Arcs Starting & Ending Angles
  • 20. Mr. Dave Clausen 20 Ellipses Draws an elliptical arc in the default color and line style based upon an ellipse with center X, Y and given radii. The arc begins at an angle to Start Angle and follows the ellipse to End Angle. The angles are measured in degrees from 0 to 360 counter- clockwise where 0 degrees is directly right. ellipse ( x, y, startangle , endangle, x_radius, y_radius);
  • 21. Mr. Dave Clausen 21 Plotting Points § The Maximum value for X can be found using: getmaxx( ) § The Maximum value for Y can be found using: getmaxy( ) § To Plot a point: putpixel ( x_value, y_value, color); For example: putpixel (100, 100, WHITE);
  • 22. Mr. Dave Clausen 22 Sample Program n Let’s look at a program with a line, rectangle, circle, arc, ellipse, and a point. Objects.cpp
  • 23. Mr. Dave Clausen 23 Line Style n Setting the line style. All lines have a default line mode, but Turbo C++ allows the user to specify three characteristics of a line: style, pattern, and thickness. n Use the command: setlinestyle (style, pattern, thickness);
  • 24. Mr. Dave Clausen 24 Line Style and Thickness Names Here are the names of the line styles and thickness: Line Style Thickness SOLID_LINE NORM_WIDTH DOTTED_LINE CENTER_LINE THICK_WIDTH DASHED_LINE USERBIT_LINE
  • 25. Mr. Dave Clausen 25 Line Style Patterns n The names of the line patterns are: SOLID_LINE = 0 DOTTED_LINE = 1 CENTER_LINE = 2 DASHED_LINE = 3
  • 26. Mr. Dave Clausen 26 Filling Patterns •Selecting Pattern and Color •Filling Regions •Getting a Pixel
  • 27. Mr. Dave Clausen 27 Selecting Pattern and Color Use the command SetFillStyle for setting the pattern and color for the object that you wish to fill. setfillstyle ( pattern, color);
  • 28. Mr. Dave Clausen 28 Pattern Names Here are the name of available patterns: Values Causing filling with EMPTY_FILL Background Color SOLID_FILL Solid Color LINE_FILL Horizontal Lines LTSLASH_FILL Thin diagonal lines SLASH_FILL Thick diagonal lines BKSLASH_FILL Thick diagonal backslashes LTBKSLASH_FILL Light backslashes HATCH_FILLThin cross hatching XHATCH_FILL Thick cross hatching INTERLEAVE_FILL Interleaving lines WIDE_DOT_FILL Widely spaced dots CLOSE_DOT_FILL Closely spaced dots
  • 29. Mr. Dave Clausen 29 Filling Regions §After selecting a color and pattern, floodfill is used to fill the desired area. §floodfill ( x, y, border_color ); §This “paints out” the desired color until it reaches border color. §Note: The border color must be the same color as the color used to draw the shape. §Also, you can only fill completely “closed” shapes. Program10_4.cpp
  • 30. Mr. Dave Clausen 30 §To draw a filled ellipse: fillellipse ( xcoordinate, ycoordinate, xradius, yradius); § To draw a filled rectangle: bar (x1, y1, x2, y2); §To draw a filled 3D rectangle: bar3d(x1, y1, x2, y2, depth, topflag); //depth is width of the 3D rectangle, if topflag is non-0 a top is added to the bar § To draw a filled section of a circle: pieslice (x, y, startangle, endangle, xradius); Filling “Special” Regions
  • 31. Mr. Dave Clausen 31 Text Output on the Graphics Screen n To write a literal expression on the graphics screen using the location specified by (x, y) use the command: outtextxy (x, y, “literal expression”); outtextxy (x, y, string_variable); Note: These are not “apstring” type strings. They are C++ standard Strings.
  • 32. Mr. Dave Clausen 32 n To set the values for the text characteristics, use: settextstyle ( font, direction, charsize); Font Direction DEFAULT_FONT HORIZ_DIR = Left to right TRIPLEX_FONT VERT_DIR = Bottom to top SMALL_FONT SANS_SERIF_FONT Fonts continued GOTHIC_FONT COMPLEX_FONT SCRIPT_FONT EUROPEAN_FONT SIMPLEX_FONT BOLD_FONT TRIPLEX_SCR_FONT Text Styles
  • 33. Mr. Dave Clausen 33 CharSize 1 = Default (normal) 2 = Double Size 3 = Triple Size 4 = 4 Times the normal 5 = 5 Times the normal …. 10 = 10 Times the normal Text Styles Font Sizes
  • 34. Mr. Dave Clausen 34 n To set the way that text is located around the point specified use the command: settextjustify (horizontal,vertical); Horizontal Vertical LEFT_TEXT TOP_TEXT CENTER_TEXT BOTTOM_TEXT RIGHT_TEXT Program10_2.cpp Text Justification
  • 35. Mr. Dave Clausen 35 Clearing the Screen n Here is the way to clear the graphics screen. n When in graphics mode use: cleardevice( ); //#include <graphics.h>
  • 36. Mr. Dave Clausen 36 n Returns the height, in pixels, of string S if it were to be written on the graphics screen using the current defaults. textheight (S string); n Returns the width, in pixels, of string S if it were to be written on the graphics screen using the current defaults. textwidth (S string); Text Height & Width
  • 37. Mr. Dave Clausen 37 Getting a Pixel n To return the color number corresponding to the color located at the point: X, Y use the command: getpixel (x, y);
  • 38. Mr. Dave Clausen 38 Useful Non Graphic Commands n kbhit() • checks to see if a keystroke is currently available • If a keystroke is available, returns a nonzero integer. • If a keystroke is not available, returns a zero. n Any available keystrokes can be retrieved with getch().