Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

10: A Display Model

Get an empty Simple_window with the size 600 by 400 and a label My window compiled, linked, and run. Note that you have to link the Qt library, #include Graph.h and Simple_window.h in your code, and compile and link Graph.cpp and Window.cpp into your program.

Now add the examples from §10.7 one by one, testing between each added subsection example.

Go through and make one minor change (e.g., in color, in location, or in number of points) to each of the subsection examples.

Why do we use graphics?

When do we try not to use graphics?

Why is graphics interesting for a programmer?

What is a window?

In which namespace do we keep our graphics interface classes (our graphics library)?

What header files do you need to do basic graphics using our graphics library?

What is the simplest window to use?

What is the minimal window?

What’s a window label?

How do you label a window?

How do screen coordinates work? Window coordinates? Mathematical coordinates?

What are examples of simple “shapes” that we can display?

What command attaches a shape to a window?

Which basic shape would you use to draw a hexagon?

How do you write text somewhere in a window?

How would you put a photo of your best friend in a window (using a program you wrote yourself)?

You made a Window object, but nothing appears on your screen. What are some possible reasons for that?

What library do we use to implement our graphics/GUI interface library? Why don’t we use the operating system directly?

Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the Polygon red and the lines of the Rectangle blue.

Draw a 100-by-30 Rectangle and place the text “Howdy!” inside it.

Draw your initials 150 pixels high. Use a thick line. Draw each initial in a different color.

Draw a 3-by-3 tic-tac-toe board of alternating white and red squares.

Draw a red 1/4-inch frame around a rectangle that is three-quarters the height of your screen and two-thirds the width.

What happens when you draw a Shape that doesn’t fit inside its window? What happens when you draw a Window that doesn’t fit on your screen? Write two programs that illustrate these two phenomena.

Draw a two-dimensional house seen from the front, the way a child would: with a door, two windows, and a roof with a chimney. Feel free to add details; maybe have “smoke” come out of the chimney.

Draw the Olympic five rings. If you can’t remember the colors, look them up.

Display an image on the screen, e.g., a photo of a friend. Label the image both with a title on the window and with a caption in the window.

Draw the source file diagram from §10.8.1.

Draw a series of regular polygons, one inside the other. The innermost should be an equilateral triangle, enclosed by a square, enclosed by a pentagon, etc. For the mathematically adept only: let all the points of each N-polygon touch sides of the (N+1)-polygon. Hint: The trigonometric functions are found in <cmath> and module std (PPP2.§24.8).

A superellipse is a two-dimensional shape defined by the equation |x/a|^m + |y/b|^n = 1; where m > 0 and n > 0. Look up superellipse on the Web to get a better idea of what such shapes look like. Write a program that draws “starlike” patterns by connecting points on a superellipse. Take a, b, m, n, and N as arguments. Select N points on the superellipse defined by a, b, m, and n. Make the points equally spaced for some definition of “equal.” Connect each of those N points to one or more other points (if you like you can make the number of points to which to connect a point another argument or just use N–1, i.e., all the other points).

Find a way to add color to the lines from the previous exercise. Make some lines one color and other lines another color or other colors.