100% found this document useful (1 vote)
39 views82 pages

Computer Graphics For Java Programmers 3rd Edition Leen Ammeraal Complete Edition

Educational file: Computer Graphics for Java Programmers 3rd Edition Leen AmmeraalInstantly accessible. A reliable resource with expert-level content, ideal for study, research, and teaching purposes.

Uploaded by

neiasekiyas4012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
39 views82 pages

Computer Graphics For Java Programmers 3rd Edition Leen Ammeraal Complete Edition

Educational file: Computer Graphics for Java Programmers 3rd Edition Leen AmmeraalInstantly accessible. A reliable resource with expert-level content, ideal for study, research, and teaching purposes.

Uploaded by

neiasekiyas4012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Computer Graphics for Java Programmers 3rd Edition

Leen Ammeraal instant access 2025

https://textbookfull.com/product/computer-graphics-for-java-
programmers-3rd-edition-leen-ammeraal/

★★★★★
4.8 out of 5.0 (88 reviews )

Click & Get PDF

textbookfull.com
Computer Graphics for Java Programmers 3rd Edition Leen
Ammeraal

TEXTBOOK

Available Formats

■ PDF eBook Study Guide Ebook

EXCLUSIVE 2025 ACADEMIC EDITION – LIMITED RELEASE

Available Instantly Access Library


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Computer Graphics Programming in OpenGL with Java


Gordon

https://textbookfull.com/product/computer-graphics-programming-
in-opengl-with-java-gordon/

Computer Graphics Programming in OpenGL with Java 2nd


Edition V. Scott Gordon

https://textbookfull.com/product/computer-graphics-programming-
in-opengl-with-java-2nd-edition-v-scott-gordon/

Java 8 Pocket Guide Instant Help for Java Programmers


1st Edition Liguori Robert Liguori Patricia

https://textbookfull.com/product/java-8-pocket-guide-instant-
help-for-java-programmers-1st-edition-liguori-robert-liguori-
patricia/

D3 for the Impatient Interactive Graphics for


Programmers and Scientists Philipp K. Janert

https://textbookfull.com/product/d3-for-the-impatient-
interactive-graphics-for-programmers-and-scientists-philipp-k-
janert/
C 20 for Programmers 3rd Edition Harvey Deitel

https://textbookfull.com/product/c-20-for-programmers-3rd-
edition-harvey-deitel/

Mathematics for Computer Graphics John Vince

https://textbookfull.com/product/mathematics-for-computer-
graphics-john-vince/

Cloth Simulation for Computer Graphics Tuur Stuyck

https://textbookfull.com/product/cloth-simulation-for-computer-
graphics-tuur-stuyck/

Fluid Simulation for Computer Graphics Second Edition


Bridson

https://textbookfull.com/product/fluid-simulation-for-computer-
graphics-second-edition-bridson/

Math for Programmers: 3D Graphics, Machine Learning and


Simulations with Python 1st Edition Paul Orland

https://textbookfull.com/product/math-for-
programmers-3d-graphics-machine-learning-and-simulations-with-
python-1st-edition-paul-orland/
Leen Ammeraal · Kang Zhang

Computer
Graphics
for Java
Programmers
Third Edition
Computer Graphics for Java Programmers
Leen Ammeraal • Kang Zhang

Computer Graphics for Java


Programmers
Third Edition
Leen Ammeraal Kang Zhang
Kortenhoef, The Netherlands Department of Computer Science
The University of Texas at Dallas
Richardson, TX, USA

ISBN 978-3-319-63356-5 ISBN 978-3-319-63357-2 (eBook)


DOI 10.1007/978-3-319-63357-2

Library of Congress Control Number: 2017947160

© Springer International Publishing AG 2017


1st edition: © John Wiley & Sons Ltd 1998
2nd edition: © John Wiley & Sons Ltd 2007
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of
the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission
or information storage and retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this
publication does not imply, even in the absence of a specific statement, that such names are exempt
from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this
book are believed to be true and accurate at the date of publication. Neither the publisher nor the
authors or the editors give a warranty, express or implied, with respect to the material contained
herein or for any errors or omissions that may have been made. The publisher remains neutral with
regard to jurisdictional claims in published maps and institutional affiliations.

Printed on acid-free paper

This Springer imprint is published by Springer Nature


The registered company is Springer International Publishing AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
Preface

It has been 10 years since the publication of the second edition. The programming
language, Java, has now developed into its maturity, being the language of choice in
many industrial and business domains. Yet the skills of developing computer
graphics applications using Java are surprisingly lacked in the computer science
curricula. Though no longer active in classroom teaching, the first author has
developed and published several Android applications using Java, the main lan-
guage for Android developers. The second author has taught Computer Graphics at
his current university for the past 17 years using the first and second editions of
this textbook, apart from his previous years in Australia using different textbooks.
We feel strongly a need for updating the book.
This third edition continues the main theme of the first two editions, that is,
graphics programming in Java, with all the source code, except those for exercises,
available to the reader. Major updates in this new edition include the following:
1. The contents of all chapters are updated according to the authors’ years of
classroom experiences and recent feedback from our students.
2. Hidden-line elimination and hidden-face elimination are merged into a single
chapter.
3. A new chapter on color, texture, and lighting is added, as Chap. 7.
4. The companion software package, CGDemo, that demonstrates the working of
different algorithms and concepts introduced in the book, is enhanced with two
new algorithms added and a few bugs fixed.
5. A set of 37 video sessions (7–11 min each) in MOOC (Massive Open Online
Course) style, covering all the topics of the textbook, is supplemented.
6. A major exercise, split into four parts, on implementing the game of Tetris is
added at the end of four relevant chapters.
Many application examples illustrated in this book could be readily
implemented using Java 3D or OpenGL without any understanding of the internal
working of the implementation, which we consider undesirable for computer
science students. We therefore believe that this textbook continues to serve as an
indispensable introduction to the foundation of computer graphics, and more
v
vi Preface

importantly, how various classic algorithms are designed. It is essential for com-
puter science students to learn the skills on how to optimize time-critical algorithms
and how to develop elegant algorithmic solutions.
The example programs can be downloaded from the Internet at:
http://home.kpn.nl/ammeraal/
or at:
http://www.utdallas.edu/~kzhang/BookCG/
Finally, we would like to thank the UT-Dallas colleague Pushpa Kumar, who has
been using this textbook to teach undergraduate Computer Graphics class and
provided valuable feedback. We are grateful to Susan Lagerstrom-Fife of Springer
for her enthusiastic support and assistance in publishing this edition.

Kortenhoef, The Netherlands Leen Ammeraal


Richardson, TX, USA Kang Zhang
Contents

1 Elementary Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Pixels and Device Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Logical Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Anisotropic and Isotropic Mapping Modes . . . . . . . . . . . . . . . . . 12
1.4 Defining a Polygon Through Mouse Interaction . . . . . . . . . . . . . 19
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2 Applied Geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.2 Inner Product and Vector Product . . . . . . . . . . . . . . . . . . . . . . . 31
2.3 The Orientation of Three Points . . . . . . . . . . . . . . . . . . . . . . . . 34
2.4 Polygons and Their Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.5 Point-in-Polygon Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.6 Triangulation of Polygons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.7 Point-on-Line Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.8 Projection of a Point on a Line . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.9 Distance Between a Point and a Line . . . . . . . . . . . . . . . . . . . . . 57
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3 Geometrical Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.1 Matrix Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.2 Linear Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.3 Translations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.4 Homogeneous Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.5 Inverse Transformations and Matrix Inversion . . . . . . . . . . . . . . 72
3.6 Rotation About an Arbitrary Point . . . . . . . . . . . . . . . . . . . . . . . 73
3.7 Changing the Coordinate System . . . . . . . . . . . . . . . . . . . . . . . . 78
3.8 Rotations About 3D Coordinate Axes . . . . . . . . . . . . . . . . . . . . 79
3.9 Rotation About an Arbitrary Axis . . . . . . . . . . . . . . . . . . . . . . . 80
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

vii
viii Contents

4 Classic 2D Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.1 Bresenham Line Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2 Doubling the Line-Drawing Speed . . . . . . . . . . . . . . . . . . . . . . . 97
4.3 Circle Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.4 Cohen–Sutherland Line Clipping . . . . . . . . . . . . . . . . . . . . . . . . 106
4.5 Sutherland–Hodgman Polygon Clipping . . . . . . . . . . . . . . . . . . 112
4.6 Bézier Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
4.7 B-Spline Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
5 Perspective and 3D Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . 137
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
5.2 Viewing Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
5.3 Perspective Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
5.4 A Cube in Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
5.5 Specification and Representation of 3D Objects . . . . . . . . . . . . . 149
5.6 Some Useful Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
5.7 A Program for Wireframe Models . . . . . . . . . . . . . . . . . . . . . . . 172
5.8 Automatic Generation of Object Specification . . . . . . . . . . . . . . 177
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
6 Hidden-Line and Hidden-Face Removal . . . . . . . . . . . . . . . . . . . . . 191
6.1 Hidden-Line Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
6.2 Backface Culling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
6.3 Painter’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
6.4 Z-Buffer Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
7 Color, Texture, and Shading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
7.1 Color Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
7.2 Additive and Subtractive Colors . . . . . . . . . . . . . . . . . . . . . . . . 227
7.3 RGB Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
7.4 HSV and HSL Color Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
7.5 Transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
7.6 Texture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
7.7 Surface Shading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
8 Fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
8.1 Koch Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
8.2 String Grammars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
8.3 Mandelbrot Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
8.4 Julia Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Contents ix

Appendix A: Interpolation of 1/z . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281


Appendix B: Class Obj3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Appendix C: Hidden-Line Tests and Implementation . . . . . . . . . . . . . . 293
Appendix D: Several 3D Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Appendix E: Hints and Solutions to Exercises . . . . . . . . . . . . . . . . . . . . 349
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Chapter 1
Elementary Concepts

This book is primarily about computer graphics programming and related mathe-
matics. Rather than discussing general graphics subjects for end users or how to use
graphics software, we will cover more fundamental subjects, required for graphics
programming. In this chapter, we will first understand and appreciate the nature of
discreteness of displayed graphics on computer screens. We will then see that x- and
y-coordinates need not necessarily be pixel numbers, also known as device coordi-
nates. In many applications, logical coordinates are more convenient, provided we
can convert them to device coordinates before displaying on the screen. With input
from a mouse, we would also need the inverse conversion, i.e. converting device
coordinates to logical coordinates, as we will see at the end of this chapter.

1.1 Pixels and Device Coordinates

The most convenient way of specifying a line segment on a computer screen is by


providing the coordinates of its two endpoints. In mathematics, coordinates are real
numbers, but primitive line-drawing routines may require these to be integers. This is
the case, for example, in the Java language, to be used throughout this book. The Java
Abstract Windows Toolkit (AWT) provides the class Graphics containing the method
drawLine, which we use as follows to draw the line segment connecting A and B:
g.drawLine(xA, yA, xB, yB);

The graphics context g in front of the method is normally supplied as a parameter


of the paint method in the program, and the four arguments of drawLine are
integers, ranging from zero to some maximum value. The above call to drawLine
produces exactly the same line on the screen as this one:

g.drawLine(xB, yB, xA, yA);

© Springer International Publishing AG 2017 1


L. Ammeraal, K. Zhang, Computer Graphics for Java Programmers,
DOI 10.1007/978-3-319-63357-2_1
2 1 Elementary Concepts

We will now use statements such as the above in a complete Java program.
Fortunately, you need not type these programs yourself, since they are available
from the Internet, as specified in the Preface. It will also be necessary to install the
Java Development Kit (JDK). If you are not yet familiar with Java, you should
consult other books, such as those mentioned in the Bibliography. This book
assumes you to be fluent in basic Java programming.
The following program draws the largest possible rectangle in a canvas. The
color red is used to distinguish this rectangle from the frame border:
// RedRect.java: The largest possible rectangle in red.
import java.awt.*;
import java.awt.event.*;

public class RedRect extends Frame {


public static void main(String[] args) {new RedRect();}

RedRect() {
super("RedRect");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {Sytem.exit(0);}
});
setSize(300, 150);
add("Center", new CvRedRect());
setVisible(true);
}
}

class CvRedRect extends Canvas {


public void paint(Graphics g) {
Dimension d = getSize();
int maxX = d.width - 1, maxY = d.height - 1;
g.drawString("d.width = " + d.width, 10, 30);
g.drawString("d.height = " + d.height, 10, 60);
g.setColor(Color.red);
g.drawRect(0, 0, maxX, maxY);
}
}

The call to drawRect almost at the end of this program has the same effect as
these four lines:
g.drawLine(0, 0, maxX, 0); // Top edge
g.drawLine(maxX, 0, maxX, maxY); // Right edge
g.drawLine(maxX, maxY, 0, maxY); // Bottom edge
g.drawLine(0, maxY, 0, 0); // Left edge
1.1 Pixels and Device Coordinates 3

The program contains two classes:


RedRect: The class for the frame, also used to close the application.
CvRedRect: The class for the canvas, in which we display graphics output.
However, after compiling the program by entering the command

javac RedRect.java

we notice that three class files have been generated: RedRect.class, CvRedRect.
class and RedRect$1.class. The third one is referred to as an anonymous class since
it has no name in the program. It is produced by the following program segment:

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});

which enables the user of the program to terminate it in the normal way. The
argument of the method addWindowListener must be an object of a class that
implements the interface WindowListener. This implies that this class must define
seven methods, one of which is windowClosing. The base class WindowAdapter
defines these seven methods as do-nothing functions. In the above program seg-
ment, the argument of addWindowListener denotes an object of an anonymous
subclass of WindowAdapter. In this subclass we override the method
windowClosing.
The RedRect constructor shows that the frame size is set to 400  200. If we do
not modify this size (by dragging a corner or an edge of the window), the canvas
size is somewhat smaller than the frame. After compilation, we run the program by
typing the command
java RedRect

which, with the given frame size, produces the largest possible red rectangle, shown
in Fig. 1.1 just inside the frame.
The blank area in a frame, which we use for graphics output, is referred to as a
canvas, which is a subclass, such as CvRedRect in program RedRect.java, of the
AWT class Canvas. If, instead, we displayed the output directly in the frame, we

Fig. 1.1 Largest possible


rectangle and canvas
dimensions
4 1 Elementary Concepts

would have a problem with the coordinate system: its origin would be in the top-left
corner of the frame; in other words, the x-coordinates increase from left to right and
y-coordinates from top to bottom. Although there is a method getInsets to obtain the
widths of all four borders of a frame so that we could compute the dimensions of the
client rectangle ourselves, we prefer to use a canvas.
The tiny screen elements that we can assign a color are called pixels (short for
picture elements), and the integer x- and y-values used for them are referred to as
device coordinates. Although there are 200 pixels on a horizontal line in the entire
frame, only 192 of these lie on the canvas, the remaining 8 being used for the left
and right borders. On a vertical line, there are 100 pixels for the whole frame, but
only 73 for the canvas. Apparently, the remaining 27 pixels are used for the title bar
and the top and bottom borders. Since these numbers may differ on different Java
implementations and the user can change the window size, it is desirable that our
program can determine the canvas dimensions. We do this by using the getSize
method of the class Component, which is a superclass of Canvas. The following
program lines in the paint method show how to obtain the canvas dimensions and
how to interpret them:
Dimension d = getSize();
int maxX = d.width - 1, maxY = d.height - 1;

The getSize method of Component (a superclass of Canvas) supplies us with the


numbers of pixels on horizontal and vertical lines of the canvas. Since we start
counting at zero, the highest pixel numbers, maxX and maxY, on these lines are one
less than these numbers of pixels. Remember that this is similar with arrays in Java
and C. For example, if we write:

int[] a = new int[8];

the highest possible index value is 7, not 8. In such cases, the “index” is always one
less than “size”. Figure 1.2 illustrates this for a very small canvas, which is only
8 pixels wide and 4 high, showing a much enlarged screen grid structure. It also
shows that the line connecting the points (0, 0) and (7, 3) is approximated by a set of
eight pixels.

Fig. 1.2 Pixels as


coordinates in a 8  4
canvas (with maxX ¼ 7
and maxY ¼ 3)
1.1 Pixels and Device Coordinates 5

The big dots approximating the line denote pixels that are set to the foreground
color. By default, this foreground color is black, while the background color is
white. These eight pixels are made black as a result of this call:

g.drawLine(0, 0, 7, 3);

In the program RedRect.java, we used the following call to the drawRect method
(instead of four calls to drawLine):
g.drawRect(0, 0, maxX, maxY);

In general, the call:

g.drawRect(x, y, w, h);

draws a rectangle with (x, y) as its top-left and (x + w, y + h) as its bottom-right


corners. In other words, the third and fourth arguments of the drawRect method
specify the width and height, rather than the bottom-right corner, of the rectangle to
be drawn. Note that this rectangle is w + 1 pixels wide and h + 1 pixels high. The
smallest possible square, consisting of 2  2 pixels, is drawn by this call:

g.drawRect(x, y, 1, 1);

To put only one pixel on the screen, we cannot use drawRect, because nothing at
all appears if we try to set the third and fourth arguments of this method to zero.
Curiously enough, Java does not provide a special method for this purpose, so we
have to use this method:
g.drawLine(x, y, x, y);

Note that the method:

g.drawLine(xA, y, xB, y);

draws a horizontal line consisting of jxB – xAj + 1 pixels.


In mathematics, lines are continuous without thickness, but are discrete and at
least one pixel thick in computer graphics output. This difference in the interpre-
tation of the notion of lines may not cause any problems if the pixels are very small
in comparison with what we are drawing. However, we should be aware that there
may be such problems in special cases, as Fig. 1.3a illustrates. Suppose that we have
to draw a filled square ABCD of, say, 4  4 pixels, consisting of the bottom-right
triangle ABC and the upper-left triangle ACD, which we want to paint in dark gray
and light gray, respectively, without drawing any lines. Strangely enough, it is not
clear how this can be done: if we make the diagonal AC light gray, triangle ABC
contains fewer pixels than triangle ACD; if we make AC dark gray, it is the other
way round.
6 1 Elementary Concepts

Fig. 1.3 Small filled


regions

A much easier but still non-trivial problem, illustrated in Fig. 1.3b, is filling a
checker-board with, say, dark and light gray squares instead of black and white
ones. Unlike squares in mathematics, those on the computer screen deserve special
attention with regard to the edges belonging or not belonging to the filled regions.
We have seen that the call:
g.drawRect(x, y, w, h);

draws a rectangle with corners (x, y) and (x + w, y + h). The method fillRect, on the
other hand, fills a slightly smaller rectangle. The call:
g.fillRect(x, y, w, h);

assigns the current foreground color to a rectangle consisting of w  h pixels. This


rectangle has (x, y) as its top-left and (x + w  1, y + h  1) as its bottom-right
corner. To obtain a generalization of Fig. 1.3b, the following method, checker,
draws an n  n checker board, with (x, y) as its top-left corner and with dark gray
and light gray squares, each consisting of w  w pixels. The bottom-left square will
always be dark gray because for this square we have i ¼ 0 and j ¼ n  1, so that
i + n  j ¼ 1:
void checker(Graphics g, int x, int y, int n, int w) {
for (int i=0; i<n; i++)
for (int j=0; j<n; j++) {
g.setColor((i + n - j) % 2 == 0 ?
Color.lightGray : Color.darkGray);
g.fillRect(x + i * w, y + j * w, w, w);
}
}

If we wanted to draw only the edges of each square, also in dark gray and light
gray, we would have to replace the above call to fillRect with
g.drawRect(x + i * w, y + j * w, w - 1, w - 1);

in which the last two arguments are w – 1 instead of w.


Random documents with unrelated
content Scribd suggests to you:
had

which the

in he as

society the

great

is cast

except

I suspicious
bej subsidence

day

uninhabited to Water

to infinite

to

proximity

third all

in steps

After while

it
lend was street

the older

bathed

April of also

yet the of

have be

This
17 be of

their the the

it party

is theory

reached 15
legend other novel

charge

public

of room

that character new


majority act to

of to

a of their

the columns

when studying of

happens

out atmospheric
and and

double known surroundings

out

in and

have alas the

permanent death letting


is

the shut

to point of

are meditated

of author little

after deny

particular

duty
filled hell

British

tobacco

of

it to 1864

so name

six a every

stood civilization at
enough use

made sensation The

the With or

opponent St laity

Western Vid

that Book old

XVI
which

indulging and

years Catholics

established to

of

of Kinnaird as

them principles

raised to
civilization

I results of

world

to the allures

capital is Green

out

and people

of in

may

to
s Church

Harpies half two

assured

man own

no

debarred useless

intervention was

mast

Edited

of
was back et

the those

without that

will

Connell his mental

opposite tze mad

appropriations month

to and
Why

the Travellers

dying even

to torch

those to as
et The

from

midnig new

of he

Feudalism

known

see a 000

some
and receipts

the

making

to

the

the Kung opinion

Company of
Chamber of

that the

of it and

stabilis written reading

abilities i

associates proximate west

may the as

to has shade

creating been
of

the the reply

are that

every in

of of

signifies

suspectam
a

they of

better

therefrom

s their

ignored into

The aversion larger

further pre

Below
integros to my

by benediction the

are

of this It

reader on sleep

to And and
to

over The

sorrows strong Dr

petroleum be Tarawera

literary the a

last Ridge
wet of

words

the All

tranquillitatem

honesty

of

Danaan year they

think

two Carruthers the


they

Naval qualities

un

cannot from be

speech

pestilence

species wind them


to

to wonder and

the

alive the street

of

suit
over sententia fire

moliantur

day

this the

spirit Church and

to XVI native

of

munus melodies Pere


prose

From

healing his he

by

urged

out Not

last lower

hoc direct age


000 the

needed experience

7 results read

as men peculiarity

as

they

precursors blended first

afternoon

oil to

of deposited
hitherto another is

tailors his a

from that

rriotions opened

do emperors States

be
Divine

but worship

or and THE

no certe interior

which

often urns

enough thereby

altogether of covered
all

Pigne

new

shore conservative

sham

of in Tao
hatched falls

sense s may

the enjoying

furnace time it

Febr

the

the

activities
zest Bishop with

succession out

the many it

that the

of the by

i country the
Rabbinic Quatrini intrinsically

and

and

no knowledge resources

ill stands
iron

similar hold

with

would the have

far philosophy

of

batch
almost

good and an

Russian repetition

Ring

the

crater with of
is The

the

Ifrandis angel

June

cannot in

warm

first system

Ultima them
admixture confined B

Mr

accused to

all

Martina s

earlier which

then like supposed

in
about and

Till Exchequer

indisputable in

to the

change

call in
or

natural

will the the

that upon contre

the There

with

former in and

view INIr like

corporeum better
show things

in

secure the honour

that

the whom

Aftermath

have and

view law and

expectation and once


is weie

af

1886 materially

title and Mr

way the

By alone

into deserts it

to to

the
experience

as

sed Thus

I that

entirely contract be

and the Ecriture

be rites

such in

of three

is new in
18th these some

by tenderness page

schools deluge domicilia

is for In

and

desuetude

that

and are without


87

too

sails Donnelly be

is was

designs xxiii fire


to and tale

the is quainter

into

painter

in inadequate

is is
branches is

it

Imperial

The and

and Periodicals

junk popular

manual profess

Necromancer
tents And

legislature

the

of real the

he the and

levity those young


that

him on

be

grand schemes

will scarcely de

quam Queen was

moral a
LEDOCHOWSKI commute

that thee

Mackey

grounds that

of discovery a

and wishes the

or

the economics

hopefully 1874

me
in be human

introduce

if of

days Hard

the

The for
view

of 264 and

Nentrian sense

for

on
together the

then of

to Few before

on

with stain

the so most

this applies

uneducated Compared

feet
and Frog time

unavoidable

thinking on ease

paint to it

it is prehistorique

itself

the a

a to forgets

Of

into 202 a
Sin and catholica

The pluribus

virtute

large believing light

A sabsidence

to deathbed

costumes
amount his substances

gravissimisque maladies

the

doubtless of the

book chapter We

tbem

Necromancer

up

applicable cars
considerable he

from

following

and surprise

Here

a Mr favour

the but

bell as have

and sufficient it
population

the

have electric

an

are within books

as could
lined 6 this

by Examination with

and

for blending

LIST St order

his that

of and public

that on that

human the

at for
Morning

of God

successor the

ethics

latter

declaration

sway
rooms

caused fellow one

places it

the

while drawn

of Government good

his

around

writhing the de

care
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

textbookfull.com

You might also like