Acceleration
definition, 117
formulas, 469
layman's definition, 117
Animation, 69, 131, 225, 247, 291, 343
frame-by-frame animation, 9, 16
JavaScript timer, 19
rendering and displaying frames, 17
rules, 17
using requestAnimationFrame, 19–20
while loop, 18
dragging an object
around canvas, 158
with motion code, 160
easing, 170
frames
as records, 6
definition, 5
programmed frames, 6
rendering and displaying frames, 16
nontemperal media, 4
pressing and releasing an object
mouse events, 153
using touch events, 156
scripted animation, 17
springing, 180
static animation, 7
temporal media, 4
throwing
definition, 162
drawFrame function, 163
setting velocity, 162
trackVelocity function, 163
time, 4
trigonometry
definition, 36
distance between two points, 62
right-angle triangle, 36
Array.splice method, 133
Billiard ball physics
conservation of momentum, 249–273
mass, 248
momentum, 248
Bouncing off angles, 232
not falling off the edge problem, 240
hit testing, 240
under the line problem, 241–243
Bounding rectangle method, 203
Canvas drawing API
commands, 76
drawing context, 77
drawing curves
with quadraticCurveTo method, 80–81
Canvas element coordinate system, 38–40
Collision detection
between irregular shaped objects, 211
distance-based collision detection, 212
collision-based springing, 216–218
formula, 224
simple collision detection, 212–216
geometric hit testing methods, 202
between object and point, 209–211
multiple-object collision detection, 218
basic collision detection, 219–220
multiple-object springing, 221–224
with circle's bounding box, 209
with rectangle's bounding box, 208
Combining colors, bitwise operators, 72–73
Conservation of momentum, 249
formulas
in JavaScript, 473
in mathematics, 473
in JavaScript, 273
in mathematics, 273
on one axis, 250
on two axis, 255
angle of collision, 256
checkCollision function, 258
one-dimensional collision, 256
plug-and-play momentum formula, 258
two-dimensional collision, 256
Coordinate rotation
advanced coordinate rotation
rotation angle, 228
formulas, 472
in third dimension, 371
simple coordinate rotation
angle and radius calculation, 227
positioning the object, 226
3D basics
bouncing
perspectives
in JavaScript, 347
techniques, 346
velocity and acceleration, 350–352
z axis
left-hand coordinate system, 345
right-hand coordinate system, 344
Distance-based collision detection
formulas, 472
3D lighting
clamping, 419
lightMag, 422
3D solid, backface culling and depth
sorting, 427
triangle constructor method, 419
vectors
cross product, 421
dot product, 421
3D lines and fills
modeling 3D solids, 401
Point3D class, 387
point definition, 383
schematic representation, 386
with invisible points, 386
shapes
3D spinning letter E, 393
3D spinning square, 392
plotting points, graph paper, 392
square, 389
using triangles
advantages, 395
benefits, 396
complex polygon, 395
definition, 397
surface normal, 395
Drawframe function, 57
Easing
advanced easing, 179
formulas, 471
proportional motion, 170
simple easing
alpha component, 179
calculations, 173
illusion of motion, 170
on colors, 179
schematic representation, 171
strategies, 171
target rotation, 178
verbose syntaxes, 172
Enhanced depth sorting, 417–418
Environmental boundaries, 132
steps, 142
strategies, 141
vs. screen wrapping, 141
setting up boundaries, 132–133
Forward kinematics (FK)
walk cycle, 302
programming
moving single segment, 293–298
Frame-by-frame animation, 9, 16
Friction
angular velocity, 147
definition, 146
scaled-back velocity code, 147
velocity multiplication, 148–149
Geometric hit testing methods, 202
GetBounds method, 202
Gravity
description, 277
formulas, 473
gravitational force
collision detection and reaction, 280–281
gravitational constant, 277–279
slingshot effect, 279
Hit testing, 201
HTML5
CSS stylessheet, 14
features, 10
performance, 11
utils.js script, 14
Hypotenuse, 40
Inverse kinematics (IK)
dragging method
with multiple segments, 322–326
with single segments, 320, 321–322
law of cosines, 335
formula, 339
in JavaScript, 339
reaching method
for an object, 332
for the mouse, 326
interaction, 333
multiple segment reaching, 332–334
with single segments, 319, 320–321
JavaScript
HTML5 (see HTML5)
objects, 20
name property, 21
prototypes, 22
user interaction, 23
events and event handlers, 23–24
Kinematics
definition, 291
forward kinematics, 292
inverse kinematics, 292
Law of cosines, formula, 474
LineTo and moveTo method
create multiple curves, 82
closed curves, 87
context.quadraticCurveTo methods, 83
smooth multiple curves, 85
with midpoints, 84
drawing curves
quadraticCurveTo method, 80
through control point, 81
Listeners and handlers
addEventListener method, 24
mousemove, 24
removeEventListener method, 24
touch events, 29
Mass, 248
Matrix
canvas transforms
affine transformation, 437
context.save() and
context.restore() methods, 439
identity matrix, 438
skewing, 439
definition, 431
multiplication, 433
Momentum, 248
Multiple-object collision detection
Quadratic Bézier curve, 80
Rendering techniques
canvas element
drawing context, 77
clearRect method, 77
line style properties, 78
color, canvas element
color utility functions, 74–76
extracting component colors, 73
hexadecimal color values, 70–71
transparency, 74
lineTo and moveTo method, 78–80
arc method, 87
arcTo method, 87
bezierCurveTo method, 87
multiple curves creation, 82–87
quadraticCurveTo method, 80–82
loading and drawing images, 91
context.drawImage method, 92
using image elements, 92
setting gradient color stops, 89–91
Speeds, and centers, 56
Springing, 282
line drawing and gravity additions, 185
to a moving target, 184
multiple objects
three objects connected, 196
two objects connected, 193
nodes
offsetting the target, 191–193
Throwing
definition, 162
drawFrame function, 163
setting velocity, 162
trackVelocity function, 163
Trig functions
arcsine, 45
Trigonometry
canvas coordinate system, 38–40
context.rotate(angle)method, 37
measurements, 37
definition, 36
distance between two points, 62
right-angle triangle, 36
smooth up and down motion, 52–54
waves
User interaction
dragging an object
pressing and releasing an object, 153
mouse events, 154
throwing (see Throwing)
Utils.intersects function, 205
Velocity
and vectors, 106
magnitude and direction, 107, 111
negative velocity, 107
concepts, 105
formulas, 469
layman's definition, 105
Walk cycle
beginnings, 303
calfOffsetSlider, 306
calfRangeSlider, 306
drawFrame function, 304
offset definition, 303
speedSlider, 306
thighBaseSlider, 306
thighRangeSlider, 306
18.219.220.22