Www.sirjameel.com Graphics in C language Lecture by Jameel Asghar IT Manager Department of CS&IT NED University of Engineering and Technology, Karachi.

Slides:



Advertisements
Similar presentations
FRACTIONS.
Advertisements

Internet Basics & Way Beyond!
 putpixel function plots a pixel at location (x, y) of specified color.  Declaration :- void putpixel(int x, int y, int color);
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
BGI graphics library And Visual Studio.
Borland Style Graphics for Dev C++)
Graphics in MS-DOS Environment LEE HUN HEE. 1.Real Coordinate and Windows Coordinate ● Real Coordinate ->(x,y) ● Windows Coordinate ->(wx,wy) ∴ (x,y)->(wx,wy)
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Introduction to Programming
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
Lecture # 11 JavaScript Graphics. Scalable Vector Graphics (SVG) Scalable Vector Graphics (SVG), as the name implies, are - scalable (without pixelation):
1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details Graphics Objects.
Civil 114 Civil Engineering Drawing AutoCAD
TEKS 8.6 (A,B) & 8.7 (A,D) This slide is meant to be a title page for the whole presentation and not an actual slide. 8.6 (A) Generate similar shapes using.
Introduction to C language
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
How to Sketch a Horizontal Line
1 Getting Started: C-Revisions and Introduction to Graphics Next: Simulation Essentials, Memory Handling.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
1 Using XSLT and XPath to Generate SVG Roger L. Costello XML Technologies.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Week 2 Book Chapter 1 RGB Color codes. 2 2.Additive Color Mixing RGB The mixing of “ light ” Primary: Red, Green, Blue The complementary color “ White.
It’s a Designer Original Josef Guarin Block 3 Geometry H.
Graphics and Multimedia Part #2
GRAPHICS AND MOUSE PROGRAMMING IN C. Turbo C has a good collection of graphics libraries. If you know the basics of C, you can easily learn graphics programming.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 12: A Display Model 1 Based on slides created by Bjarne.
Chapter 15Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Tkinter Canvas.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Fall UI Design and Implementation1 Lecture 6: Output.
Images Part 11 dbg. 2 Images The form and several controls can display a number of different types of image files in the BackgroundImage Property. These.
+ This step by step tutorial demonstrates drawing a keyboard illustration using rectangles, grids, move and transform effects.
On to 3D Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
- draw a diameter - make a radius - join diameter and radius -join other end of diameter and radius - put in any angle for one of the angles formed - fill.
Introduction to Illustrator
Background templates for PowerPoint slides
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Marina Abramovic Polaroid (Advanced)
Basic Graphics Drawing Shapes 1.
Lecture No 9 Graphics.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
بسم الله الرحمن الرحیم مركز بهمن استاندارد- مديريت ارزيابي و مانيتورينگ كيفي.
Order of Operations Problems
TAB ONE TAB TWO TAB THREE TAB FOUR TAB FIVE
Order of Operations Problems
Chapter 2 Graphics Programming with C++ and the Dark GDK Library
موضوع بحث: تعریف علم اصول جلسه 43.
اشاره به نتایج قیاس های فقهی گاهی، حکم شرعی است
علم اصول، «نفس قواعد» است نه «علم به قواعد»
نظریات پیرامون «تمایز علوم»
نظریات پیرامون «تمایز علوم» بررسی دلایل عدم احتیاج علوم به موضوع
Let’s Write a Graphics Program
نظریات پیرامون «تمایز علوم» بررسی دلایل احتیاج علوم به موضوع
first line of text goes here
spotLIGHT TEXT Ppt宝藏 提供下载 (Intermediate)
13-14 лекция Графикалық режим.
نظریات پیرامون «تمایز علوم» بررسی دلایل احتیاج علوم به موضوع
قاعده لا ضرر، تنها در شبهات حکمیه جاری است
جلسه 34.
1 ج : اشاره بعضی از اصولیون به تعریف ترکیبی آخوند با «یک لفظ»
Presentation transcript:

Graphics in C language Lecture by Jameel Asghar IT Manager Department of CS&IT NED University of Engineering and Technology, Karachi

Text mode vs Graphics mode of C Text ModeGraphics Mode Basic Unit is characterBasic Unit is pixel 80 columns, 50 rows640 columns, 480 rows

My First program/drawing a line #include main() { int gd=DETECT, gm; initgraph(&gd, &gm, “C:/TC/bgi”); line(0,0,200,200); getch(); closegraph(); }

Drawing a Circle #include main() { int gd=DETECT, gm; initgraph(&gd, &gm, “C:/TC/bgi”); circle(320,240,100); getch(); closegraph(); }

circle(320,240,100); Explanation A Circle takes a total of 3 arguments. The first two arguments are used to define center of the circle in x and y co-ordinates. Since screen has a size of 640 pixels in x-axis, so 320 is the center of x-axis. And screen has the size of 480 pixels in y-axis, so 240 is the center of y-axis. Third argument of the circle is its radius in pixels. In our example the radius of the circle is 100 pixels.

Some other shapes in graphics.h library.

arc(midx, midy,starting-angle,ending-angle,radius);

arc(midx, midy,starting-angle,ending-angle,radius); Explanation: – Arc is used to draw circular arc – Arc takes 5 arguments, all of the int type. – First two arguments define the center of the arc to place on the screen. – Third and Fourth arguments are starting and ending angles of the arc. – Fifth argument is the radius of the arc in pixels.

arc(midx, midy,starting-angle,ending-angle,radius); arc(320,240,0,180,100); – The above code generates an arc in the mid of the screen, angled from 0 to 180(making a half circle facing downwards), having radius of the 100 pixels.

arc(midx, midy,starting-angle,ending-angle,radius); arc(320,240,180,0,100); – The above code generates an arc in the mid of the screen, angled from 0 to 180(making a half circle facing upwards), having radius of the 100 pixels.

ractangle(left, top,right, bottom);

ractangle(left, top,right, bottom); Explanation: – Rectangle is used to draw an empty rectangle. – It takes 4 arguments all of int type. – First two arguments are left-top corner of the rectangle, and last two arguments are right bottom corner of the rectangle.

ractangle(left, top,right, bottom); ractangle(100,100,200, 200); – Output: (100,100) (200,200)

bar(left, top,right, bottom);

bar(left, top,right, bottom); Explanation: – bar is used to draw a rectangle filled with given pattern. – We use function setfillstyle(Style, Color); to give any of the style/pattern to the bar – It takes 4 arguments all of int type. – First two arguments are left-top corner of the rectangle, and last two arguments are right bottom corner of the rectangle.

setfillstyle(STYLE,COLOR);

setfillstyle(STYLE,COLOR); Explanation: – The setfillstyle(STYLE,COLOR); sets the fill pattern and color. – Total of 13 styles are available to C-Compiler, which are as under: EMPTY_FILL, SOLID_FILL, LINE_FILL, LTSLASH_FILL, SLASH_FILL, BKSLASH_FILL, LTBKSLASH_FILL, HATCH_FILL, XHATCH_FILL, INTERLEAVE_FILL, WIDE_DOT_FILL, CLOSE_DOT_FILL, USER_FILL. We can specify the color of the object either by writing directly color name all in CAPITAL LETTERS like RED, GREEN, or by writing a corresponding equillent number of the color, like 0 for BLACK, 1 for BLUE and so on. Similarly the fill pattern can also be replaced by their corresponding numbers, ie 0 for EMPTY_FILL, 1 for SOLID_FILL, and so on. Hence setfillstyle(SOLID_FILL, BLUE); is equall to setfillstyle(1, 1); Both will yield the same result.

setfillstyle(STYLE,COLOR); Example1: setfillstyle(EMPTY_FILL,BLUE); bar(20,20,100,200); Example2: setfillstyle(SOLID_FILL,BLUE); bar(20,20,100,200);

Similarly try other styles and colors and Enjoy!

ellipse(midx, midy,starting-angle,ending-angle,radius-x, radius-y);

ellipse(midx, midy,starting-angle,ending-angle,radius-x, radius-y); Explanation: – Ellipse is used to draw an elliptical arc. – Ellipse takes 6 arguments, all of the int type. – First two arguments define the center of the ellipse to place on the screen.(ie x and y co-ordinates) – Third and Fourth arguments are starting and ending angles of the ellipse. – Fifth argument is the radius of the ellipse in x-axis, and sixth argument is the radius of the ellipse in y-axis.

ellipse(midx, midy,starting-angle,ending-angle,radius-x, radius-y); Example1: ellipse(320,240,0,360,50,100);

ellipse(midx, midy,starting-angle,ending-angle,radius-x, radius-y); Example2: ellipse(320,240,0,360,100,100);

ellipse(midx, midy,starting-angle,ending-angle,radius-x, radius-y); Example3: ellipse(320,240,0,360,100,50);

ellipse(midx, midy,starting-angle,ending-angle,radius-x, radius-y); Example4: ellipse(320,240,0,180,100,50);

ellipse(midx, midy,starting-angle,ending-angle,radius-x, radius-y); Example5: ellipse(320,240,180,0,100,50);

fillellipse(midx, midy,radius-x, radius-y);

fillellipse(midx, midy,radius-x, radius-y); Explanation: – Fillellipse is used to draw and fill and ellipse with given style and color. – Fillellipse takes 4 arguments, all of the int type. – First two arguments define the center of the ellipse to place on the screen.(ie x and y co-ordinates) – Third argument is the radius of the ellipse in x-axis, and fourth argument is the radius of the ellipse in y- axis.

fillellipse(midx, midy,radius-x, radius-y); Example1: setfillstyle(EMPTY_FILL,BLUE); Fillelipse(320,240,100,100) Example2: setfillstyle(SOLID_FILL,BLUE); Bar(320,240,100,100);

fillellipse(midx, midy,radius-x, radius-y); Example3: setfillstyle(EMPTY_FILL,BLUE); Fillelipse(320,240,50,100) Example4: setfillstyle(SOLID_FILL,BLUE); Bar(320,240,50,100);

fillellipse(midx, midy,radius-x, radius-y); Example5: setfillstyle(EMPTY_FILL,BLUE); Fillelipse(320,240,100,50) Example6: setfillstyle(SOLID_FILL,BLUE); Bar(320,240,100,50);

Setting font/text Style and Size settextstyle(Style, Horizontal/Vertical, Size); outtextxy(x-position, y-position, Text)

settextstyle(Font, Direction, Size); outtextxy(x-position, y-position, Text) Explanation: – Settextstyle sets the Font Style, Direction and size of the Text written in outtextxy function. – Available Font Styles in C Compiler are as under: Font StyleValueMeaning DEFAULT_FONT08x8 bit-mapped font TRIPLEX_FONT1Stroked triplex font SMALL_FONT2Stroked small font SANS_SERIF_FONT3Stroked sans-serif font GOTHIC_FONT4Stroked gothic font

settextstyle(Font, Direction, Size); outtextxy(x-position, y-position, Text) – There are two available Directions for settextstyle. NameValueDirection HORIZ_DIR0Left to Right VERT_DIR1Bottom to Top

settextstyle(Font, Direction, Size); outtextxy(x-position, y-position, Text) Example1: settextstyle(DEFAULT_FONT, HORIZ_DIR,1); outtextxy(320,240,”Hello World”); The above code will generate an output “Hello World”, written in default font/simple font, having horizontal direction, and text size of 1. It will be displayed in the mid of the output window.

settextstyle(Font, Direction, Size); outtextxy(x-position, y-position, Text) NOTE: – You can also use number value instead of Font name and direction. – Hence: settextstyle(DEFAULT_FONT, HORIZ_DIR,1); is same as: settextstyle(0, 0,1);