Skip to content

Commit 15749a7

Browse files
committed
Proofread Chapter 16
1 parent 04226b1 commit 15749a7

File tree

3 files changed

+53
-29
lines changed

3 files changed

+53
-29
lines changed

Diff for: 16_canvas.txt

+53-29
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ The `<circle>` and `<rect>` tags, which do not exist in HTML, do have
7272
a meaning in SVG—they draw shapes using the style and position
7373
specified by their attributes.
7474

75+
ifdef::book_target[]
76+
77+
The document is displayed like this:
78+
79+
image::img/svg-demo.png[alt="An embedded SVG image",width="4.5cm"]
80+
81+
endif::book_target[]
82+
7583
These tags create ((DOM)) elements, just like ((HTML)) tags. For
7684
example, this changes the `<circle>` element to be ((color))ed cyan
7785
instead:
@@ -124,16 +132,16 @@ through the `getContext` method on the `<canvas>` element.
124132
</script>
125133
----
126134

135+
After creating the context object, the example draws a red
136+
((rectangle)) 100 ((pixel))s wide and 50 pixels high, with its top-left
137+
corner at coordinates (10,10).
138+
127139
ifdef::book_target[]
128140

129-
image::img/canvas_fill.png[alt="A canvas with a rectangle",width="3cm"]
141+
image::img/canvas_fill.png[alt="A canvas with a rectangle",width="2.5cm"]
130142

131143
endif::book_target[]
132144

133-
After creating the context object, the example draws a red
134-
((rectangle)) 100 ((pixel))s wide and 50 pixels high, with its top-left
135-
corner at coordinates (10,10).
136-
137145
(((SVG)))(((coordinates)))Just like in ((HTML)) (and SVG), the
138146
coordinate system that the canvas uses puts (0,0) at the top-left
139147
corner, and the positive y-((axis)) goes down from there. So, (10,10)
@@ -181,6 +189,9 @@ positive number.
181189

182190
ifdef::book_target[]
183191

192+
This code draws two blue squares, using a thicker line for the second
193+
one.
194+
184195
image::img/canvas_stroke.png[alt="Two stroked squares",width="5cm"]
185196

186197
endif::book_target[]
@@ -212,12 +223,6 @@ make a sequence of method calls to describe its shape.
212223
</script>
213224
----
214225

215-
ifdef::book_target[]
216-
217-
image::img/canvas_path.png[alt="Stroking a number of lines",width="2.1cm"]
218-
219-
endif::book_target[]
220-
221226
(((canvas)))(((stroke method)))(((lineTo method)))(((moveTo
222227
method)))(((shape)))This example creates a path with a number of
223228
horizontal ((line)) segments and then strokes it using the `stroke`
@@ -226,6 +231,14 @@ _current_ position. That position is usually the end of the last segment,
226231
unless `moveTo` was called. In that case, the next segment would start
227232
at the position passed to `moveTo`.
228233

234+
ifdef::book_target[]
235+
236+
The path described by the previous program looks like this:
237+
238+
image::img/canvas_path.png[alt="Stroking a number of lines",width="2.1cm"]
239+
240+
endif::book_target[]
241+
229242
(((path,canvas)))(((filling)))(((path,closing)))(((fill method)))When
230243
filling a path (using the `fill` method), each ((shape)) is filled
231244
separately. A path can contain multiple shapes—each `moveTo` motion
@@ -247,17 +260,17 @@ start, and the shape enclosed by the completed path is filled.
247260
</script>
248261
----
249262

263+
This example draws a filled triangle. Note that only two of the triangle's
264+
sides are explicitly drawn. The third, from the bottom-right corner
265+
back to the top, is implied and won't be there when you stroke the
266+
path.
267+
250268
ifdef::book_target[]
251269

252270
image::img/canvas_triangle.png[alt="Filling a path",width="2.2cm"]
253271

254272
endif::book_target[]
255273

256-
This example draws a filled triangle. Note that only two of the triangle's
257-
sides are explicitly drawn. The third, from the bottom-right corner
258-
back to the top, is implied and won't be there when you stroke the
259-
path.
260-
261274
(((stroke method)))(((closePath
262275
method)))(((path,closing)))(((canvas)))You could also use the `closePath` method
263276
to explicitly close a path by adding an actual ((line)) segment back to
@@ -295,6 +308,8 @@ example illustrates this:
295308

296309
ifdef::book_target[]
297310

311+
It produces a path that looks like this:
312+
298313
image::img/canvas_quadraticcurve.png[alt="A quadratic curve",width="2.3cm"]
299314

300315
endif::book_target[]
@@ -328,16 +343,16 @@ illustrate the behavior of such a curve:
328343
</script>
329344
----
330345

346+
The two control points specify the direction at both ends of the
347+
curve. The further they are away from their corresponding point, the
348+
more the curve will “bulge” in that direction.
349+
331350
ifdef::book_target[]
332351

333352
image::img/canvas_beziercurve.png[alt="A bezier curve",width="2.2cm"]
334353

335354
endif::book_target[]
336355

337-
The two control points specify the direction at both ends of the
338-
curve. The further they are away from their corresponding point, the
339-
more the curve will “bulge” in that direction.
340-
341356
(((trial and error)))Such ((curve))s can be hard to work with—it's
342357
not always clear how to find the ((control point))s that provide the
343358
((shape)) you are looking for. Sometimes you can compute
@@ -374,6 +389,8 @@ start of the rounded part.
374389

375390
ifdef::book_target[]
376391

392+
This produces two rounded corners with different radiuses.
393+
377394
image::img/canvas_arc.png[alt="Two arcs with different radii",width="2.3cm"]
378395

379396
endif::book_target[]
@@ -411,19 +428,19 @@ to draw a full circle.
411428
</script>
412429
----
413430

414-
ifdef::book_target[]
415-
416-
image::img/canvas_circle.png[alt="Drawing a circle",width="4.9cm"]
417-
418-
endif::book_target[]
419-
420431
(((moveTo method)))(((arc method)))(((path, canvas)))The resulting picture
421432
contains a ((line)) from the left of the full circle (first call to
422433
`arc`) to the left of the quarter-((circle)) (second call). Like other
423434
path-drawing methods, a line drawn with `arc` is connected to the
424435
previous path segment by default. You'd have to call `moveTo` or
425436
start a new path if you want to avoid this.
426437

438+
ifdef::book_target[]
439+
440+
image::img/canvas_circle.png[alt="Drawing a circle",width="4.9cm"]
441+
442+
endif::book_target[]
443+
427444
[[pie_chart]]
428445
== Drawing a pie chart ==
429446

@@ -469,8 +486,8 @@ people who picked a given choice.
469486
var sliceAngle = (result.count / total) * 2 * Math.PI;
470487
cx.beginPath();
471488
// center=100,100, radius=100
472-
cx.arc(100, 100, 100,
473489
// from current angle, clockwise by slice's angle
490+
cx.arc(100, 100, 100,
474491
currentAngle, currentAngle + sliceAngle);
475492
currentAngle += sliceAngle;
476493
cx.lineTo(100, 100);
@@ -482,6 +499,8 @@ people who picked a given choice.
482499

483500
ifdef::book_target[]
484501

502+
This draws the following chart:
503+
485504
image::img/canvas_pie_chart.png[alt="A pie chart",width="5cm"]
486505

487506
endif::book_target[]
@@ -647,6 +666,9 @@ set a horizontal scale and one to set a vertical scale.
647666

648667
ifdef::book_target[]
649668

669+
Due to the call to `scale`, the circle is drawn three times as wide
670+
and half as high.
671+
650672
image::img/canvas_scale.png[alt="A scaled circle",width="6.6cm"]
651673

652674
endif::book_target[]
@@ -760,7 +782,7 @@ management. They conceptually keep a stack of transformation
760782
stack, and when you call `restore`, the state on top of the stack is
761783
taken off and used as the context's current transformation.
762784

763-
(((branching recursion)))(((branching fractal
785+
(((branching recursion)))(((fractal
764786
example)))(((recursion)))The `branch` function in the following example
765787
illustrates what you can do with a function that changes the
766788
transformation and then calls another function (in this case itself),
@@ -795,6 +817,8 @@ recursion stops when the length drops below 8.
795817

796818
ifdef::book_target[]
797819

820+
The result is a simple fractal.
821+
798822
image::img/canvas_tree.png[alt="A recursive picture",width="5cm"]
799823

800824
endif::book_target[]
@@ -1055,7 +1079,7 @@ CanvasDisplay.prototype.drawPlayer = function(x, y, width,
10551079
};
10561080
----
10571081

1058-
The previous function is called by `drawActors`, which is responsible for
1082+
The `drawPlayer` method is called by `drawActors`, which is responsible for
10591083
drawing all the actors in the game.
10601084

10611085
// include_code

Diff for: img/canvas_game.png

-272 Bytes
Loading

Diff for: img/svg-demo.png

5.11 KB
Loading

0 commit comments

Comments
 (0)