Overview Chapter 12 A display model

Similar documents
Chapter 12 A display model

Chapter 12 A display model

Chapter 12 A display model

Programming: Practice and Core Guidelines

n We have discussed classes in previous lectures n Here, we discuss design of classes n Library design considerations

Parabolic Path to a Best Best-Fit Line:

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

Graphical Interface Object Oriented Programming

Python Programming: An Introduction to Computer Science

Web OS Switch Software

MOTIF XF Extension Owner s Manual

Python Programming: An Introduction to Computer Science

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

Bezier curves. Figure 2 shows cubic Bezier curves for various control points. In a Bezier curve, only

Baan Tools User Management

The number n of subintervals times the length h of subintervals gives length of interval (b-a).

Learning to Shoot a Goal Lecture 8: Learning Models and Skills

Appendix D. Controller Implementation

One advantage that SONAR has over any other music-sequencing product I ve worked

Numerical Methods Lecture 6 - Curve Fitting Techniques

Basic Design Principles

The VSS CCD photometry spreadsheet

Computers and Scientific Thinking

9 x and g(x) = 4. x. Find (x) 3.6. I. Combining Functions. A. From Equations. Example: Let f(x) = and its domain. Example: Let f(x) = and g(x) = x x 4

CS 11 C track: lecture 1

OPC Server ECL Comfort 210/310 OPC Server

condition w i B i S maximum u i

IMP: Superposer Integrated Morphometrics Package Superposition Tool

Intermediate Statistics

EVALUATION OF TRIGONOMETRIC FUNCTIONS

Alpha Individual Solutions MAΘ National Convention 2013

JoLetter 6.7. JoLauterbach Software GmbH. Mail and merge with QuarkXPress. JoLauterbach Software GmbH. Stolzingstraße 4a Bayreuth Germany

Pattern Recognition Systems Lab 1 Least Mean Squares

CS 111: Program Design I Lecture 15: Modules, Pandas again. Robert H. Sloan & Richard Warner University of Illinois at Chicago March 8, 2018

SD vs. SD + One of the most important uses of sample statistics is to estimate the corresponding population parameters.

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

n It s exciting n It s lucrative n It s fun (sometimes!)

Math 10C Long Range Plans

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

Arithmetic Sequences

Global Support Guide. Verizon WIreless. For the BlackBerry 8830 World Edition Smartphone and the Motorola Z6c

Aberrations in Lens & Mirrors (Hecht 6.3)

Area As A Limit & Sigma Notation

Computer Graphics Hardware An Overview

apple Apple Computer, Inc.

Avid Interplay Bundle

Reading. Subdivision curves and surfaces. Subdivision curves. Chaikin s algorithm. Recommended:

IXS-6600-C IXS-6700-C

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Elementary Educational Computer

JavaFX. JavaFX 2.2 Installation Guide Release 2.2 E August 2012 Installation instructions by operating system for JavaFX 2.

Avid recommends that you read all the information in this ReadMe file thoroughly before installing or using any new software release.

This chapter serves as an introductory overview of Excel If you re

A Resource for Free-standing Mathematics Qualifications

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Parametric curves. Reading. Parametric polynomial curves. Mathematical curve representation. Brian Curless CSE 457 Spring 2015

Assignment 5; Due Friday, February 10

. Written in factored form it is easy to see that the roots are 2, 2, i,

South Slave Divisional Education Council. Math 10C

CS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access

3.1 Overview of MySQL Programs. These programs are discussed further in Chapter 4, Database Administration. Client programs that access the server:

Using the Keyboard. Using the Wireless Keyboard. > Using the Keyboard

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

Location Steps and Paths

BEA WebLogic Process Integrator

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013

Texture Mapping. Jian Huang. This set of slides references the ones used at Ohio State for instruction.

Mathematics and Art Activity - Basic Plane Tessellation with GeoGebra

BAAN IVc/BaanERP. Conversion Guide Oracle7 to Oracle8

Creating Test Harnesses and Starter Applications

A Taste of Maya. Character Setup

What does JFC stand for?

CS Polygon Scan Conversion. Slide 1

Reading. Parametric curves. Mathematical curve representation. Curves before computers. Required: Angel , , , 11.9.

Workflow Extensions User Guide. StarTeam 12.0

Consider the following population data for the state of California. Year Population

MANAGED! PREPARE TO BE FEATURES HANDHELD USER DISPLAYS. Specifications MEASUREMENT STABILIZATION INDICATOR

CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists

Math Section 2.2 Polynomial Functions

CSE 111 Bio: Program Design I Class 11: loops

System and Software Architecture Description (SSAD)

Adapter for Mainframe

Security of Bluetooth: An overview of Bluetooth Security

Recursive Procedures. How can you model the relationship between consecutive terms of a sequence?

LifeBook P Series Notebook BIOS BIOS SETUP UTILITY

Computational Geometry

ELEG 5173L Digital Signal Processing Introduction to TMS320C6713 DSK

Performance Plus Software Parameter Definitions

1.2 Binomial Coefficients and Subsets

HP Media Center PC Getting Started Guide

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

TESTING FOR SPATIAL AUTOCORRELATION IN MODEL FITTING. Mike Antolin. November 5, 2007

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

PLEASURE TEST SERIES (XI) - 04 By O.P. Gupta (For stuffs on Math, click at theopgupta.com)

Visualization of Gauss-Bonnet Theorem

BEA Tuxedo. Using the BEA Tuxedo System on Windows NT

Transcription:

Overview Chapter 12 A display model Why graphics? A graphics model Examples Bjare Stroustrup www.stroustrup.com/programmig 3 Why bother with graphics ad GUI? Why bother with graphics ad GUI? It s very commo If you write covetioal PC applicatios, you ll have to do it It s useful Istat feedback Graphig fuctios Displayig results It ca illustrate some geerally useful cocepts ad techiques It ca oly be doe well usig some pretty eat laguage features J Lots of good (small) code examples It ca be o-trivial to get the key cocepts So it s worth teachig If we do t show how it s doe, you might thik it was magic Graphics is fu! 4 5 1

Why Graphics/GUI? Display model Shape WYSIWYG What you see (i your code) is what you get (o your scree) Direct correspodece betwee cocepts, code, ad output Square attach() attach() widow draw() Display Egie Objects (such as graphs) are attached to a widow. The display egie ivokes display commads (such as draw lie from x to y ) for the objects i a widow Objects such as Square cotai vectors of lies, text, etc. for the widow to draw 6 7 Display model A example illustratig the display model The resultig scree it mai() { usig amespace Graph_lib; Poit tl {100,200}; // use our graphics iterface library // a poit (obviously) Simple_widow wi {tl,600,400,"cavas }; // make a simple widow Polygo poly; // make a shape (a polygo, obviously) poly.add(poit{300,200}); // add three poits to the polygo poly.add(poit{350,100}); poly.add(poit{400,200}); poly.set_color(color::red); wi.attach(poly); // make the polygo red (obviously) // coect poly to the widow } wi.wait_for_butto(); // give cotrol to the display egie 8 9 2

Graphics/GUI libraries You ll be usig a few iterface classes we wrote Iterfacig to a popular GUI toolkit GUI == Graphical User Iterface FLTK: www.fltk.org // Fast Light Tool Kit Istallatio, etc. Already istalled o Departmetal machies (erdos, LL612 lab machies) To istall o your persoal computer: See Appedix D ad ask istructor/fried FLTK Our GUI ad graphics classes Project settigs This model is far simpler tha commo toolkit iterfaces The FLTK (very terse) documetatio is 370 pages Our iterface library is ~20 classes ad ~500 lies of code You ca write a lot of code with these classes Ad you ca build more classes o them 10 Graphics/GUI libraries (cot.) The code is portable Widows, Uix, Mac, etc. This model exteds to most commo graphics ad GUI uses The geeral ideas ca be used with ay popular GUI toolkit Oce you uderstad the graphics classes you ca easily lear ay GUI/graphics library Well, relatively easily these libraries are huge 11 Graphics/GUI libraries 0,0 Coordiates 200,0 Our code Our iterface library 50,50 A graphics/gui library (here FLTK) The operatig system (e.g. Widows or Liux) Our scree Ofte called a layered architecture 0,100 200,100 Oddly, y-coordiates grow dowwards // right, dow Coordiates idetify pixels i the widow o the scree You ca resize a widow (chagig x_max() ad y_max()) 12 13 3

Iterface classes Widow Color Lie_style Shape Poit Simple_widow Lie Lies Polygo Rectagle Text A arrow meas is a kid of Color, Lie_style, ad Poit are utility classes used by the other classes Widow is our iterface to the GUI library (which is our iterface to the scree) Curret Iterface classes Color, Lie_style, Fot, Poit, Widow, Simple_widow Shape, Text, Polygo, Lie, Lies, Rectagle, Axis Easy to add (for some defiitio of easy ) Grid, Block_chart, Pie_chart, etc. Later, GUI Butto, I_box, Out_box, 14 15 Demo code 1 A blak cavas // Gettig access to the graphics system (do t forget to istall): #iclude "Simple_widow.h" // stuff to deal with your system s widows #iclude "Graph.h" // graphical shapes usig amespace Graph_lib; // make ames available // i mai(): Simple_widow wi {Poit{100,100},600,400,"Cavas"}; // scree coordiate (100,100) is top left corer of widow // widow size(600 pixels wide by 400 pixels high) // title: Cavas wi.wait_for_butto(); // Display! 16 17 4

Demo code 2 Add a X-axis Axis xa {Axis::x, Poit{20,300}, 280, 10, "x axis"}; // make a Axis // a axis is a kid of Shape // Axis::x meas horizotal // startig at (20,300) // 280 pixels log // 10 otches ( tick marks ) // text x axis wi.set_label("cavas #2"); wi.attach(xa); // attach axis xa to the widow wi.wait_for_butto(); 18 19 Demo code 3 Add a Y-axis (colored) wi.set_label("cavas #3"); Axis ya {Axis::y, Poit{20,300}, 280, 10, "y axis"}; ya.set_color(color::cya); // choose a color for the axis ya.label.set_color(color::dark_red); // choose a color for the text wi.attach(ya); wi.wait_for_butto(); 20 Yes, it s ugly, but this is a programmig course, ot a graphics desig course 21 5

Demo code 4 Add a sie curve wi.set_label("cavas #4"); Fuctio sie {si,0,100,poit{20,150},1000,50,50}; // sie curve // plot si() i the rage [0:100) // with (0,0) at (20,150) // usig 1000 poits // scale x values *50, scale y values *50 // actually, it s a bit more complicated tha this, will explai later wi.attach(sie); wi.wait_for_butto(); 22 23 Demo code 5 Add a triagle (ad color the curve) wi.set_label("cavas #5"); sie.set_color(color::blue); Polygo poly; poly.add(poit{300,200}); poly.add(poit{350,100}); poly.add(poit{400,200}); // I chaged my mid about sie s color // make a polygo (a kid of Shape) // three poits make a triagle poly.set_color(color::red); // chage the color poly.set_style(lie_style::dash); // chage the lie style wi.attach(poly); wi.wait_for_butto(); 24 25 6

Demo code 6 Add a rectagle wi.set_label("cavas #6"); Rectagle r {Poit{200,200}, 100, 50}; // top left poit, width, height wi.attach(r); wi.wait_for_butto(); 26 27 Demo code 6.1 Add a shape that looks like a rectagle Add a shape that looks like a rectagle Closed_polylie poly_rect; poly_rect.add(poit{100,50}); poly_rect.add(poit{200,50}); poly_rect.add(poit{200,100}); poly_rect.add(poit{100,100}); wi.set_label("cavas #6.1"); But is it a rectagle? 28 29 7

We ca add a poit Demo code 6.2 Obviously a polygo poly_rect.add(poit{50,75}); // ow poly_rect has 5 poits wi.set_label("cavas #6.2"); lookig like is ot the same as is 30 31 r.set_fill_color(color::yellow); Add fill // color the iside of the rectagle Add fill poly.set_style(lie_style{lie_style::dash,4}); // make the triagle fat poly_rect.set_fill_color(color::gree); poly_rect.set_style(lie_style{lie_style::dash,2}); wi.set_label("cavas #7"); 32 33 8

Demo Code 8 Add text Text t {Poit{100,100},"Hello, graphical world!"}; // add text // poit is lower left corer o the baselie wi.set_label("cavas #8"); 34 35 Demo Code 9 Text fot ad size Modify text fot ad size t.set_fot(graph_lib::fot::times_bold); t.set_fot_size(20); // height i pixels 36 37 9

Add a image Add a image Image ii {Poit{100,50},"image.jpg"}; // ope a image file wi.attach(ii); wi.set_label("cavas #10"); 38 39 Oops! Move the image The image obscures the other shapes Move it a bit out of the way ii.move(100,200); // move 100 pixels to the right (-100 moves left) // move 200 pixels dow (-200 moves up) wi.set_label("cavas #11"); wi.wait_for_butto(); Note how the parts of a shape that do t fit i the widow are clipped away 40 41 10

Circle c {Poit{100,200},50}; Demo Code 12 // ceter, radius Ellipse e {Poit{100,200}, 75,25}; // ceter, horizotal radius, vertical radius e.set_color(color::dark_red); Mark m {Poit{100,200},'x'}; ostrigstream oss; oss << "scree size: " << x_max() << "*" << y_max() << "; widow size: " << wi.x_max() << "*" << wi.y_max(); Text sizes {Poit{100,20},oss.str()}; Image cal {Poit{225,225}, "sow_cpp.gif"}; cal.set_mask(poit{40,40},200,150); // 320*240 pixel gif // display ceter of image Add shapes, more text wi.set_label("cavas #12"); wi.wait_for_butto(); 42 43 Boiler plate Primitives ad algorithms #iclude "Graph.h" #iclude Simple_widow.h" it mai () try { // the mai part of your code } catch(exceptio& e) { cerr << "exceptio: " << e.what() << '\'; retur 1; } catch (...) { cerr << "Some exceptio\"; retur 2; } // header for graphs // header cotaiig widow iterface The demo shows the use of library primitives Just the primitives Just the use Typically what we display is the result of a algorithm readig data Next lectures 13: Graphics Classes 14: Graphics Class Desig 15: Graphig Fuctios ad Data 16: Graphical User Iterfaces 44 45 11