@@ -149,7 +149,7 @@ canvas—it contains the current picture as well as the selected color
149149property).
150150
151151(((class attribute)))(((CSS)))We wrap the canvas and the controls in
152- `<div>` elements with classes to be able to add some styling, such as
152+ `<div>` elements with classes so we can add some styling, such as
153153a gray border around the picture.
154154
155155== Tool selection ==
@@ -158,7 +158,7 @@ a gray border around the picture.
158158tag))))The first control we add is the `<select>` element that
159159allows the user to pick a drawing ((tool)). As with `controls`, we
160160will use an object to collect the various tools so that we do not
161- have to hard-code them all in one place and we can add more tools later.
161+ have to hard-code them all in one place and can add more tools later.
162162This object associates the names of the tools with the function that
163163should be called when they are selected and the canvas is clicked.
164164
@@ -187,7 +187,7 @@ controls.tool = function(cx) {
187187
188188(((preventDefault method)))(((selection)))(((option (HTML
189189tag))))(((mousedown event)))The tool field is populated with
190- `<option>` elements for all tools that have been defined and a
190+ `<option>` elements for all tools that have been defined, and a
191191`"mousedown"` handler on the canvas element takes care of calling the
192192function for the current tool, passing it both the ((event object))
193193and the drawing ((context)) as arguments. It also calls
@@ -197,7 +197,7 @@ not cause the browser to select parts of the page.
197197(((relativePos function)))(((event object)))(((getBoundingClientRect
198198method)))(((clientX property)))(((clientY property)))The most basic
199199tool is the ((line tool)), which allows the user to draw lines with
200- the ((mouse)). To be able to put the line ends in the right place, we
200+ the ((mouse)). To put the line ends in the right place, we
201201need to be able to find the canvas-relative ((coordinates)) that a
202202given mouse event corresponds to. The `getBoundingClientRect` method,
203203briefly mentioned in link:13_dom.html#boundingRect[Chapter 13], can
@@ -287,8 +287,8 @@ mouse's old and new position, using whatever `strokeStyle` and
287287through to `trackDrag`. The normal way to run tools won't pass a third
288288argument, so when using the line tool, that argument will hold
289289`undefined`, and nothing happens at the end of the mouse drag. The
290- argument is there to allow us to implement the “ erase” tool on top of
291- the “ line” tool with very little additional code.
290+ argument is there to allow us to implement the erase tool on top of
291+ the line tool with very little additional code.
292292
293293// include_code
294294
@@ -311,7 +311,7 @@ color is overlaid on the existing color at that spot. If the ((color)) is
311311opaque, it will simply replace the old color, but if it is
312312partially transparent, the two will be mixed.
313313
314- The “ erase” tool sets `globalCompositeOperation` to
314+ The erase tool sets `globalCompositeOperation` to
315315`"destination-out"`, which has the effect of erasing the pixels we
316316touch, making them transparent again.
317317
@@ -408,7 +408,7 @@ simple HTML document:
408408data:text/html,<h1 style="color:red">Hello!</h1>
409409----
410410
411- Such URLs are useful for various tasks, such as including small
411+ Data URLs are useful for various tasks, such as including small
412412images directly in a ((style sheet)) file. They also allow us to link
413413to files that we created on the client side, in the browser, without
414414first moving them to some server.
@@ -602,7 +602,7 @@ base the font size on the current brush size. The minimum size is 7
602602pixels because text smaller than that is unreadable.
603603
604604(((spray paint tool)))(((random number)))Another indispensable tool
605- for drawing amateurish computer graphics is the “ spray paint” tool.
605+ for drawing amateurish computer graphics is the spray paint tool.
606606This one draws dots in random locations under the ((brush)) as long as
607607the mouse is held down, creating denser or less dense speckling
608608based on how fast or slow the mouse moves.
@@ -812,14 +812,14 @@ pixelAt(cx, 10, 10);
812812// → [255, 0, 0, 255]
813813----
814814
815- The arguments to `getImageData` indicate the starting x and y
816- coordinates of the rectangle we want to retrieve, followed by its
815+ The arguments to `getImageData` indicate the starting x- and
816+ y- coordinates of the rectangle we want to retrieve, followed by its
817817width and height.
818818
819819(((transparent)))Ignore transparency during this exercise and look
820820only at the first three values for a given pixel. Also, do not worry
821821about updating the color field when the user picks a color. Just make
822- sure that the drawing context's `fillStyle` and `strokeStyle` get set
822+ sure that the drawing context's `fillStyle` and `strokeStyle` are set
823823to the color under the mouse cursor.
824824
825825(((rgb (CSS))))Remember that these properties accept any color that
@@ -874,8 +874,8 @@ to a tricky problem. Make sure you have plenty of time and
874874((patience)) before starting to work on this exercise, and do not get
875875discouraged by initial failures.
876876
877- (((bucket fill)))A “ flood fill” tool colors the pixel under the mouse
878- and the whole group of pixels around it that have the same color. For
877+ (((bucket fill)))A flood fill tool colors the pixel under the mouse
878+ and the surrounding pixels of the same color. For
879879the purpose of this exercise, we will consider such a group to include
880880all pixels that can be reached from our starting pixel by moving in
881881single-pixel horizontal and vertical steps (not diagonal), without
@@ -898,7 +898,7 @@ out pixel data from the resulting array. The pixels are organized in
898898this array in a similar way to the ((grid)) elements in
899899link:07_elife.html#grid[Chapter 7], one row at a time, except that
900900each pixel is represented by four values. The first value for the
901- pixel at (x,y ) is at position (x + y × width) × 4.
901+ pixel at (_x_,_y_ ) is at position (_x_ + _y_ × width) × 4.
902902
903903(((alpha)))(((transparent)))Do include the fourth (alpha) value this
904904time since we want to be able to tell the difference between empty
@@ -917,12 +917,12 @@ you finish your current walk.
917917
918918(((performance)))(((optimization)))In a normal-sized picture, there are
919919a _lot_ of pixels. Thus, you must take care to do the minimal amount
920- of work required or your program will take a very long to run. For
920+ of work required or your program will take a very long time to run. For
921921example, every walk must ignore pixels seen by previous walks so that
922922it does not redo work that has already been done.
923923
924924(((fillRect method)))I recommend calling `fillRect` for individual
925- pixels when a pixel that should be colored is found and keeping some
925+ pixels when a pixel that should be colored is found, and keeping some
926926data structure that tells you about all the pixels that have already
927927been looked at.
928928
0 commit comments