CSCE 121:509-512 Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 12: A Display Model 1 Based on slides created by Bjarne.

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces
Advertisements

Chapter 15 Functions and graphing Bjarne Stroustrup
Chapter 12 A display model Bjarne Stroustrup
Chapter 13 Graphics classes Bjarne Stroustrup
Chapter 14 Graph class design Bjarne Stroustrup
Chapters 12 and 13 A Display Model and Graphics Classes John Keyser’s Modifications of Slides by Bjarne Stroustrup
Chapter 15 Functions and graphing John Keyser’s Modification of Slides by Bjarne Stroustrup
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Python Programming, 2/e1 CS177: Programming in Multimedia Objects Recitation Topic: Graphics Library.
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
Chapter 5 Creating an Image Map.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 L36 Graphics and Java 2D™ (1). 2 OBJECTIVES  To understand graphics contexts and graphics objects.  To understand and be able to manipulate colors.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Text, Masks, and Live Effects – Lesson 41 Text, Masks, and Live Effects Lesson 4.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
Reporting Aesthetics An ACEware Webinar 1:00-2:00 pm February 14 th, 2008.
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
Adobe InDesign CS5 – Illustrated Unit D: Working with Graphics.
1 Word Lesson 4 Working with Graphic Objects Microsoft Office 2010 Fundamentals Story / Walls.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 14 Graphics class design Hartmut Kaiser
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Ranjeet Department of Physics & Astrophysics University of Delhi Working with Origin.
Graphics and Multimedia Part #2
Chapter 5 Creating an Image Map.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
PROCESSING & JAVA An Introduction to Computing. Objectives Be able to state and apply phases of development Be able to state and describe the goals of.
Chapter 13 Graphics classes Bjarne Stroustrup
Introduction to Flash. Topics What is Flash? What can you do with it? Simple animation Complex interactive web application, such as an online store. Starting.
Log In to your User Start: Photoshop Elements. Start a new document 700x120 pixels with white background. Create a new layer by clicking Layer -> New.
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.
Academic Year, Spring Semester Bilkent University - Faculty of Art, Design and Architecture Department of Communication and Design CS 153 Introduction.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Tkinter Canvas.
CSCE 121: Introduction to Program Design and Concepts, Honors J. Michael Moore Spring 2015 Set 14: Plotting Functions and Data 1.
Introducing Templates and Graphics. 2 Creating Workbooks from Templates Choose a blank workbook or an existing workbook Search for templates at Office.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 13 Graphics classes Hartmut Kaiser
Creating visual interfaces in python
Chapter 14 Graph class design Bjarne Stroustrup
Circle Ellipse HyperbolaParabola Conic Sections. Circles x 2 + y 2 = 16 center: (0,0) radius: Ex. 1 Standard form: (x – h) 2 + (y – k) 2 = r 2.
1 Mapping Coordinates Find the x- and y- coordinates for the images, relative to the x-axis and y-axis In a coordinate pair, the first number is the x-coordinate.
Illustrator For illustrations. Vector Graphics  Can resize shapes without losing quality  Place dots ( anchor points )  Connect the dots with paths.
5. COMPUTING WITH GRAPHICS OBJECTS Dennis Y. W. Liu and Rocky K. C. Chang October 8, 2015 (Adapted from John Zelle’s slides)
CS 115 Lecture 7 Graphics – coordinate systems, Text, Entry, aliases Taken from notes by Dr. Neil Moore.
CSCE Introduction to Program Design and Concepts J. Michael Moore Spring 2015 Set 6: Miscellaneous 1 Based on slides created by Bjarne Stroustrup.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Inserting and Working with Images
Example: Card Game Create a class called “Card”
Python: Simple Graphics and Event-driven Programming
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Basic Graphics Drawing Shapes 1.
CSCE , 510, 511, 512 Introduction to Program Design and Concepts Dr. J
Chapter 2 Graphics Programming with C++ and the Dark GDK Library
Chapter 13 Graphics classes
Chapter 13 Graphics classes
بودجه پیشنهادی سال 1398 شرکت توزیع نیروی برق استان تهران
Inheritance in Graphics
Chapter 12 A display model
Chapter 16 Graphical User Interfaces
Graphics and FLTK CSCE 121 J. Michael Moore
Guidelines for Writing Functions
Chapter 16 Graphical User Interfaces
Presentation transcript:

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 Stroustrup and Jennifer Welch

CSCE 121: Set 12: A Display Model Advantages of Graphics and GUIs Very common Instant feedback Illustrates some generally useful concepts and techniques – Class inheritance especially Fun! 2

CSCE 121: Set 12: A Display Model Display Model Objects (e.g., text boxes and squares) are attached to a window Display engine invokes commands to draw the objects in the window 3 Text Box Square Window Display Engine attach() draw()

CSCE 121: Set 12: A Display Model Display Model Example 4 // some boilerplate int main() { // make a point at coordinates (100,200) Point t1(100,200); // make a basic window Simple_window win(t1,600,400,”Canvas”); // make a polygon with no points initially Polygon poly; // add (300,200), (350,100), and (400,200) to polygon poly.add(Point(300,200)); poly.add(Point(350,100)); poly.add(Point(400,200)); poly.set_color(Color::red); // make the polygon red win.attach(poly); // connect polygon to window // give control to display engine win.wait_for_button(); }

CSCE 121: Set 12: A Display Model The Result 5

CSCE 121: Set 12: A Display Model Graphics/GUI Libraries You will be using some interface classes that Dr. Stroustrup wrote – They interface to a popular GUI (graphical user interface) toolkit called FLTK ( – Instructions in lab for accessing The Stroustrup interface is much simpler than common ones – < 20 classes and < 500 lines of code vs. 370 pages of documentation alone for FLTK – Yet it is complete enough to be able to do interesting things 6

CSCE 121: Set 12: A Display Model Benefits of Using Stroustrup Graphics Library Focus on essentials, don’t get bogged down with bells and whistles Code is portable – Windows, Unix, Mac: FLTK is available for all of these General ideas can be used with any popular graphics/GUI toolkit 7

CSCE 121: Set 12: A Display Model Layered Software Architecture 8 Our code The operating system (e.g. Windows or Linux) Our screen Our interface library A graphics/GUI library (here FLTK)

CSCE 121: Set 12: A Display Model Coordinates y-coordinates increase going down (not up) Coordinates identify pixels on screen 9 0,0 0,99 199,0 50,50 199,99

CSCE 121: Set 12: A Display Model Interface Classes Organization Arrow means “is a kind of” (inheritance) Color, Line_styleand Point are “utility classes” Window is interface to the GUI library, and hence the screen 10 Window Simple_window Shape LinesPolygon Rectangle Text Point Color Line_style Line …

CSCE 121: Set 12: A Display Model Interface Classes Overview Graphics (drawing on the screen): – Color, Line_style, Font, Point – Window, Simple_window – Shape, Text, Polygon, Line, Lines, Rectangle,... – Axis (for plots) GUI (communicating with user) – Button, In_box, Out_box,… 11

CSCE 121: Set 12: A Display Model Boiler Plate for Graphics Programming 12 #include “Graph.h” // header for graphics #include “Simple_window.h” // header for window interface using namespace Graph_lib; // make names available int main() try { // main part of code – see upcoming examples } catch(exception& e) { cerr << “exception: “ << e.what() << ‘\n’; return 1; } catch(...) { cerr << “Some exception\n”; return 2; }

CSCE 121: Set 12: A Display Model Demo Code 1: A Blank Canvas 13 Simple_window win( Point(100,100), // coordinates of top left corner 600,400, // width and height of window “Canvas”); // title win.wait_for_button(); // Display!

CSCE 121: Set 12: A Display Model Demo Code 2: Add an X-Axis 14 win.set_label(“Canvas #2”); // change window’s label Axis xa(Axis::x, // horizontal Point(20,300), // start at (20,300) 280, // 280 pixels long 10, // 10 notches (tick marks) “x axis”); // label win.attach(xa); // attach axis to window win.wait_for_button(); // display

CSCE 121: Set 12: A Display Model Demo Code 3: Add a Y-Axis 15 win.set_label(“Canvas #3”); Axis ya(Axis::y, Point(20,300), 280, 10, “y axis”); ya.set_color(Color::cyan); // choose axis color ya.label.set_color(Color::dark_red); // choose label color win.attach(ya); win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 4: Add a Sine Curve 16 win.set_label(“Canvas #4”); Function sine(sin, // plot sin function 0,100, // range of x-values Point(20,150), // location of the origin 1000, // number of points to plot 50,50); // scaling factors for x and y values win.attach(ya); win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 5: Color, Polygons 17 win.set_label(“Canvas #5”); sine.set_color(Color::blue); Polygon poly; poly.add(Point(300,200)); poly.add(Point(350,100)); poly.add(Point(400,200)); poly.set_color(Color::red); poly.set_style(Line_style::dash); win.attach(poly); win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 6: Add a Rectangle 18 win.set_label(“Canvas #6”); Rectangle r(Point(200,200), // top left point 100,50); // width, height win.attach(r); win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 6.1: Alternate Rectangle 19 win.set_label(“Canvas #6.1”); Closed_polyline poly_rect; poly_rect.add(Point(100,50)); poly_rect.add(Point(200,50)); poly_rect.add(Point(200,100)); poly_rect.add(Point(100,100)); win.attach(poly_rect); win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 6.2: Add to poly_rect 20 win.set_label(“Canvas #6.2”); poly_rect.add(Point(50,75)); // now has 5 points win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 7: Fill and Style 21 win.set_label(“Canvas #7”); r.set_fill_color(Color::yellow); Poly.set_style(Line_style(Line_style::dash,4)); Poly_rect.set_fill_color(Color::green); Poly_rect.set_style(Line_style(Line_style::dash,2));

CSCE 121: Set 12: A Display Model Demo Code 8: Add Text 22 win.set_label(“Canvas #8”); Text t(Point(100,100), // lower left corner of baseline “Hello, graphical world!”); // content win.attach(t); win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 9: Modify Text 23 t.set_font(Font::times_bold); t.set_font_size(20); // height in pixels win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 10: Add Image 24 win.set_label(“Canvas #10”); Image ii(Point(100,50),”image.jpg”); win.attach(ii); win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 11: Move Image 25 win.set_label(“Canvas #11”); ii.move(100,200); // move 100 pixels right, 200 pixels down win.wait_for_button();

CSCE 121: Set 12: A Display Model Demo Code 12: Miscellaneous 26 win.set_label(“Canvas #12”); // center: specify center point and radius Circle c(Point(100,200),50); // ellipse: specify center pt, horizontal and vertical radii Ellipse e(Point(100,200),75,25); e.set_color(Color::dark_red); // mark: specify point where is goes and character Mark m(Point(100,200),’x’); // make a Text object using an ostringstream ostringstream oss; oss <<“screen size: “ << x_max() << “*” << y_max() << “; window size: “ << win.x_max() << “*” << win.y_max(); Text sizes(Point(100,20),oss.str()); // mask out part of this image Image cal(Point(225,225), “snow_cpp.gif”); cal.set_mask(Point(40,40),200,150); // attach c, e, m, sizes, cal and wait for button //...

CSCE 121: Set 12: A Display Model Result 12 27

CSCE 121: Set 12: A Display Model Acknowledgments Slides are based on those for the textbook: 28