The Essential Guide to HTML5: Using Games to Learn HTML5 and JavaScript 3rd Edition Jeanine Meyer download
The Essential Guide to HTML5: Using Games to Learn HTML5 and JavaScript 3rd Edition Jeanine Meyer download
https://ebookmeta.com/product/the-essential-guide-to-html5-using-
games-to-learn-html5-and-javascript-3rd-edition-jeanine-meyer/
https://ebookmeta.com/product/programming-101-learn-to-code-
using-the-processing-programming-language-2nd-edition-jeanine-
meyer/
https://ebookmeta.com/product/build-your-own-2d-game-engine-and-
create-great-web-games-using-html5-javascript-and-webgl2-kelvin-
sung/
https://ebookmeta.com/product/build-your-own-2d-game-engine-and-
create-great-web-games-using-html5-javascript-and-webgl-1st-
edition-kelvin-sung-jebediah-pavleas-fernando-arnez-jason-pace/
https://ebookmeta.com/product/arithmetic-l-functions-and-
differential-geometric-methods-regulators-iv-may-2016-paris-
progress-in-mathematics-338-pierre-charollois-editor/
Future Grid Scale Energy Storage Solutions Mechanical
and Chemical Technologies and Principles 1st Edition
Ahmad Arabkoohsar
https://ebookmeta.com/product/future-grid-scale-energy-storage-
solutions-mechanical-and-chemical-technologies-and-
principles-1st-edition-ahmad-arabkoohsar/
https://ebookmeta.com/product/galactic-empires-eight-novels-of-
deep-space-adventure-patty-jansen-m-pax-mark-e-cooper-daniel-
arenson-chris-reher-david-vandyke-joseph-lallo-felix-r-savage/
https://ebookmeta.com/product/blood-of-a-gladiator-1st-edition-
ashley-gardner/
https://ebookmeta.com/product/the-poetics-and-hermeneutics-of-
pain-and-pleasure-1st-edition-bootheina-majoul/
https://ebookmeta.com/product/english-grammar-in-use-fifth-
edition-without-exercises-raymond-murphy/
Introduction to Internet of Things in Management
Science and Operations Research Implemented Studies
International Series in Operations Research Management
Science 311
https://ebookmeta.com/product/introduction-to-internet-of-things-
in-management-science-and-operations-research-implemented-
studies-international-series-in-operations-research-management-
science-311/
The Essential Guide to
HTML5
Using Games to Learn HTML5
and JavaScript
Third Edition
Jeanine Meyer
The Essential Guide to HTML5: Using Games to Learn HTML5 and JavaScript
Jeanine Meyer
Purchase, NY, USA
Introduction�����������������������������������������������������������������������������������������������������������xvii
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 479
x
About the Author
Jeanine Meyer is a professor emerita at Purchase College/
SUNY and past coordinator of the Mathematics/Computer
Science Board of Study. Before Purchase, she taught at
Pace University and before that worked as a research staff
member and manager in robotics and manufacturing
research at IBM Research and as a consultant for IBM’s
educational grant programs. She is the author or coauthor
of ten books on topics such as educational uses of multimedia, programming (three
published by Apress/Springer), databases, number theory, and origami.
She earned a PhD in computer science at the Courant Institute at New York
University, an MA in mathematics at Columbia University, and an SB (the college used
the Latin form) in mathematics from the University of Chicago. She is a member of Phi
Beta Kappa, Sigma Xi, Association for Women in Science, and Association for Computing
Machinery, and was a featured reviewer for ACM Computing Reviews.
For Jeanine, programming is both a hobby and a vocation. Every day she plays
computer puzzles online (including Words with Friends, various solitaire card games,
and Duolingo for Spanish, which she views as a game). She also participates in Daf
Yomi, the seven-and-a-half-year study of Talmud, which certainly has puzzle-solving
aspects. She tries The New York Times crossword puzzle many days but does better at the
mini-puzzle, KenKen, and Two Not Touch, in which she sometimes competes with her
children. She enjoys cooking, baking, eating, gardening, travel, and a moderate amount
of walking. She misses her mother, who inspired many family members to take up
piano, and her father, who gave Jeanine a love of puzzles. She is an active volunteer for
progressive causes and candidates.
xi
About the Technical Reviewer
Vadim Atamanenko is a software developer with more
than 20 years of experience. He participates in international
hackathons both as a judge and as a mentor and is a member
of the Harvard Square Business Association.
He has developed many complex solutions in various
business areas that have helped thousands of people
automate manual processes.
Currently he is the CIO at Freedom Holding Corp., but
he still finds time to regularly participate in international IT
conferences.
He enjoys meeting new people and sharing his knowledge. If you have a question for
him, visit https://www.linkedin.com/in/vadim-atamanenko/.
xiii
Acknowledgments
Much appreciation to my students and colleagues at Purchase College/State University
of New York for their inspiration, stimulation, and support; and to family and friends
who indulge me in my use of family photos and video clips for my courses and my books.
Thanks to the crew at Apress and Springer for all their efforts.
xv
Introduction
When it was first released, there was considerable enthusiasm about the new capabilities
of HTML5, and even suggestions that no other technologies or products are necessary to
produce dynamic, engrossing, interactive websites. The excitement has not gone away,
and the new features are still exciting. HTML is HTML5. It now is possible, using just
HTML, Cascading Style Sheets, and JavaScript, to draw lines, arcs, circles, and ovals on
the screen and specify events and event handling to produce animation and respond to
user actions. You can include video and audio on your website with standard controls,
and you can include the video or audio in your application exactly when and where
needed. You can create forms that validate the input and provide immediate feedback
to users. You can use a facility similar to cookies to store information on the client
computer. And you can use new elements, such as headers and footers, to help structure
your documents. HTML, CSS, and JavaScript work together. You can use JavaScript to
create new HTML elements, and this is helped by what can be done with CSS.
This book is based on my teaching practices and past writings. Delving into the
features of a technology or general programming concepts is best done when there is a
need and a context. Games, especially familiar and simple ones, supply the context and
thus the motivation and much of the explanation. When learning a new programming
language, one of my first steps is to program the game of craps. Also, if I can build a
ballistics simulation with animation, such as the slingshot game, and make a video
or audio clip play when a specific condition occurs, I am happy. If I can construct my
own maze of walls, determine ways to provide visual as well as text feedback, and store
information on the player’s computer, I am ecstatic. That’s what we will do in this book.
As you learn how to build these simple games, you’ll build your expertise as well. I hope
you go on to make your own exciting, compelling applications.
This goal of this book, developed with considerable help from the Apress staff and
the technical reviewers, is to introduce you to programming, with the motivation of
implementing interactive websites to share with others.
xvii
Introduction
general sense: what we need to implement the application, independent of any specific
technology. We then focus on the features of HTML5, JavaScript, Cascading Style Sheets, and
general programming methodologies that satisfy the requirements. Finally, we examine the
implementation of each application in detail. I break out the code line by line in a table, with
comments next to each line. In the cases where multiple versions of a game are described,
only the new lines of code may be explained in detail. This isn’t to deprive you of information
but to encourage you to see what is similar and what is different, and to demonstrate how
you can build applications in stages. It certainly is appropriate to consult the commented
programs on an as-needed basis. Each chapter includes suggestions on how to make the
application your own and how to test and upload the application to a website. The summary
at the end of each chapter highlights what you’ve learned and what you’ll find ahead.
The appendix was added in this edition to provide more advanced examples of
creating and manipulating graphics on the screen using algebra and geometry and
Scalar Vector Graphics images.
Layout Conventions
To keep this book as clear as possible, the following text conventions are used throughout:
So, with these formalities out of the way, let’s get started.
xix
Another Random Scribd Document
with Unrelated Content
With the restoration of the Bourbons in 1815, the French
romantic school of literature was ushered into existence; the three
Coriphaes of which were De Lavigne, De Lamartine, and
Chateaubriand. Schiller, Young, and Milton, seemed to have been
their models; but the modern prose writers soon followed the lyric
poets in their imitations of the romantic schools of England and
Germany; and we have since had French pupils of Fielding, Smollet,
Hoffmann, and Jean Paul Richter. Eugene Sue at first imitated
Fennimore Cooper; but he soon gave into the “tendency novels,” on
the Miss Martineau style of treating political and domestic economy.
But his great genius, and the rich resources of his imagination, soon
made him shoot by his dull originals, and he has since grappled
successfully with religion, morals, and politics; in all which combats
he may be said to have come out victorious; for he has nearly, if not
altogether, annihilated his antagonists.
The Feuilleton literature which has grown in proportion to the
decline of essays and memoirs, has opened a new field to the
romantic pens of France, and has made that style of writing popular
with the masses. Since then the abuse of it has passed all bounds;
half a dozen writers have absorbed the Feuilletons of all the large
sheets published in the capital—so that talents less known and
appreciated must content themselves with some feudal tenure under
one of these literary lords; for it must not be imagined that writers
like Sue, Alexandre Dumas, Soulié, &c., do their own works, or are
put to the necessity of even inventing the incidents of their stories.
All this is done for them by their literary vassals, who work for five
francs a day, while their masters, who occasionally correct the
phraseology of some chapter, but whose principal business it is,
when matters come to a crisis, to furnish the dénouement and the
conclusion, to which they put their name, receive hundreds of
thousands for their contributions.
But what the feudal writers of the romantic school of France have
not attempted till lately was to imitate Shakspeare on the stage.
Hitherto the modern dramas of Victor Hugo were more in the melo-
dramatic line, and as such admirably adapted to the taste of the
frequenters of the theatre de la Porte St. Martin. But Victor Hugo
was a brave man, and with the popularity acquired among the
masses, soon forced his way to the French academy, as Lucien
Bonaparte, at the head of his grenadiers, forced the legislative
assembly of the republic to close its sessions. He got in and seated
himself, and has since had strength enough to draw some of his best
friends after him, notwithstanding all the opposition of the classic
Molé, who has even pronounced a discourse against Alfred de Vigny.
Alexandre Dumas, the Créol of the Isle of Bourbon (the French
use the term Créol as a sort of embellishment to a Mulatto) is the
greatest literary factotum of France now living. He imitates every
thing—history, comedy, tragedy, novels, and romance, and will with
great difficulty be kept from “the forty” qui en savant comme quatre.
[1]
His Monte Christo is an imitation of “The Wandering Jew;” his Age
of Louis XIV. and XV., an important commentary on Voltaire; but his
chef d’œuvre we have now before us;—it is nothing less than a new
version of Shakspeare’s Hamlet!
The present Feuilleton literature of France is, properly speaking,
the commercial or shop-keeper literature of the day, in which a few
thoughts abstracted from some greater works are carefully spun out
and disposed of at retail prices; or, to use a still better figure, a
ragout with all sorts of spices, but made from a piece of meat which
has served to appease the appetite of hundreds. There is a perfect
dearth of ideas in all of them, and a morbid desire for ornament.
The form is everywhere more valuable than the substance—the
elegance of style superior to the naked thought. It is the process of
the gold-beater, who, with a single grain of that precious metal,
covers the backs of a whole library.
The taste for Shakspeare is, in France, of recent origin. Since the
performance of Macready on the French boards, Parisian audiences
have become acquainted with ghosts, witches, and the whole
laboratory of philosophical superstition in which the British bard
surpassed all others, ancient and modern. Still Shakspeare remained
unintelligible or unpalatable to many, notwithstanding the learned
reviews of the Revue de deux Mondes, and the Revue de Paris, both
of which strove to show that though in point of abstract genius
Shakspeare may have possessed more than Racine, Voltaire, and
Corneille put together, still he lacked that scenic arrangement, and
that peculiar close connection between cause and effect which
distinguishes the dramatic works of France. “Shakspeare’s Hamlet is
a philosophical dissertation,” said a French writer, “in a dramatic
form.” “There is no reason for Hamlet’s madness”—“none in the
world for Ophelia’s ravings, who ought to spurn the taunts and
insults of her coward lover,” &c.
All these criticisms have moved Alexandre Dumas to try his hand
at the work, and to correct the logic and dramatic arrangement of
“the British savage, who occasionally found a pearl on a dunghill.”
The work of the French Creole is admirable of its kind; but equally
“unintelligible” in regard to the scenic arrangements. Hamlet is as
much a coward in the French play as he is in the English, only a little
less philosophical; and instead of Laertes and the king being killed,
the queen poisoned, and what not, the ghost takes charge of eternal
justice and finishes them off himself. Why he does not do so, in the
first act, immediately after his appearance, is an enigma; but as that
would have saved the remaining four acts—which would not have
answered the views of Alexandre Dumas—it was necessary that
Hamlet—the only character who survives in the French play—should
do some courting, and the queen and king some talking and
feasting, all according to the rules of the French drama. We cannot
refrain, by way of a rich treat, from giving the readers of the
magazine the closing scene of Dumas’s play. It will speak for itself,
and save us the necessity of further comment.
One can see that Dumas snatches a grace beyond the reach of
the usual drama. The ghost acts the part of the Lord’s messenger,
and pronounces sentence on each culprit. The queen is “a woman
here,” and “an angel there;” because she loved much—the king is
too well served in going to the devil, Laertes dies with some hope of
salvation; but Hamlet lives to repent of his sins; having by his
cowardice killed four persons instead of one! This is French stage
logic. As to the language it is the most trite and commonplace, that
one can hear in front of the theatre from the hackmen; and the
tragic muse is certainly not that one of the hallowed nine which
particularly favors the author of Monte Christo.
F. J. G.
THE GLEANER.
She stands, as radiant as the morn
When rosy splendors fill the air:
Her white arms hold the golden corn,
Itself less glowing than her hair.
The Gleaner.
Engraved expressly for Graham’s Magazine
REVIEW OF NEW BOOKS.
We never knew a case where the book was read without giving
delight. Indeed it nestles close to the heart. There is a quaint,
cunning, quiet beauty to it, which wins upon the mind, and gently
forces assent to its excellence. Such a book is balm to a sensitive
and irritable spirit. It is read with some such feeling as might be
excited by a benediction from Chaucer’s good parson. Every one
who desires to “possess himself in much quietness,” whose brain has
been fretted and stung by the morbid creations of the Satanic school
of letters, should devote his days and nights to Isaak Walton, as
Johnson advised the style-monger to devote himself to Addison. The
sweet serenity which breathes through the whole book, joined to the
sly quaint beauty of the expression, cannot fail to charm every mind
not wholly debauched by the “storm-and-pressure” style now in
vogue. The men to whom the book relates, are among the saints of
English literature; men who combined great learning and greater
intellect, with sweetness of disposition and repose of manner. We
can hardly conceive of a reader rising from the perusal of these
“Lives” without having some of their many amenities infused into his
heart.
Transcriber’s Notes:
Table of Contents has been added for reader convenience. Archaic
spellings and hyphenation have been retained. Punctuation has been
corrected without note. Other errors have been corrected as noted
below. For illustrations, some caption text may be missing or
incomplete due to condition of the originals available for preparation
of the eBook.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.