Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 18, 2016
0 parents commit 68254fc
Show file tree
Hide file tree
Showing 501 changed files with 6,515 additions and 0 deletions.
Binary file added 9781430263371/README.pdf
Binary file not shown.
12 changes: 12 additions & 0 deletions 9781430263371/chapter1/bouncing-ball.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bouncing ball</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="canvas" width="700" height="500"></canvas>
<script src= "bouncing-ball.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions 9781430263371/chapter1/bouncing-ball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');

var radius = 20;
var color = "#0000ff";
var g = 0.1; // acceleration due to gravity
var x = 50; // initial horizontal position
var y = 50; // initial vertical position
var vx = 2; // initial horizontal speed
var vy = 0; // initial vertical speed

window.onload = init;

function init() {
setInterval(onEachStep, 1000/60); // 60 fps
};

function onEachStep() {
vy += g; // gravity increases the vertical speed
x += vx; // horizontal speed increases horizontal position
y += vy; // vertical speed increases vertical position

if (y > canvas.height - radius){ // if ball hits the ground
y = canvas.height - radius; // reposition it at the ground
vy *= -0.8; // then reverse and reduce its vertical speed
}
if (x > canvas.width + radius){ // if ball goes beyond canvas
x = -radius; // wrap it around
}
drawBall(); // draw the ball
};

function drawBall() {
with (context){
clearRect(0, 0, canvas.width, canvas.height);
fillStyle = color;
beginPath();
arc(x, y, radius, 0, 2*Math.PI, true);
closePath();
fill();
};
};
6 changes: 6 additions & 0 deletions 9781430263371/chapter1/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
background-color: #666;
}
#canvas {
background-color: #fff;
}
16 changes: 16 additions & 0 deletions 9781430263371/chapter10/attractors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Attractors</title>
<link rel="stylesheet" href="./includes/style3.css">
</head>
<body>
<canvas id="canvas_bg" width="800" height="600"></canvas>
<canvas id="canvas" width="800" height="600"></canvas>
<script src= "./objects/vector2D.js"></script>
<script src= "./objects/forces.js"></script>
<script src= "./objects/ball.js"></script>
<script src= "attractors.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions 9781430263371/chapter10/attractors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions 9781430263371/chapter10/black-holes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Black holes</title>
<link rel="stylesheet" href="./includes/style1.css">
</head>
<body>
<canvas id="canvas_bg" width="800" height="600"></canvas>
<canvas id="canvas" width="800" height="600"></canvas>
<script src= "./objects/vector2D.js"></script>
<script src= "./objects/forces.js"></script>
<script src= "./objects/ball.js"></script>
<script src= "./objects/triangle.js"></script>
<script src= "./objects/graph.js"></script>
<script src= "rocket.js"></script>
<script src= "black-holes.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions 9781430263371/chapter10/black-holes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions 9781430263371/chapter10/central-forces.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Central forces</title>
<link rel="stylesheet" href="./includes/style1.css">
</head>
<body>
<canvas id="canvas_bg" width="700" height="500"></canvas>
<canvas id="canvas" width="700" height="500"></canvas>
<script src= "./objects/graph.js"></script>
<script src= "./objects/vector2D.js"></script>
<script src= "./objects/forces.js"></script>
<script src= "./objects/ball.js"></script>
<script src= "central-forces.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions 9781430263371/chapter10/central-forces.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions 9781430263371/chapter10/electric-field-examples.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Electric field examples</title>
<link rel="stylesheet" href="./includes/style1.css">
</head>
<body>
<canvas id="canvas_bg" width="700" height="500"></canvas>
<canvas id="canvas" width="700" height="500"></canvas>
<script src= "./objects/graph.js"></script>
<script src= "./objects/vector2D.js"></script>
<script src= "./objects/forces.js"></script>
<script src= "./objects/ball.js"></script>
<script src= "electric-field-examples.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions 9781430263371/chapter10/electric-field-examples.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions 9781430263371/chapter10/electric-field.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Electric field</title>
<link rel="stylesheet" href="./includes/style1.css">
</head>
<body>
<canvas id="canvas_bg" width="800" height="600"></canvas>
<canvas id="canvas" width="800" height="600"></canvas>
<script src= "./objects/vector2D.js"></script>
<script src= "./objects/forces.js"></script>
<script src= "./objects/ball.js"></script>
<script src= "./objects/graph.js"></script>
<script src= "electric-field.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions 9781430263371/chapter10/electric-field.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions 9781430263371/chapter10/force-fields.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Force fields</title>
<link rel="stylesheet" href="./includes/style1.css">
</head>
<body>
<canvas id="canvas_bg" width="800" height="600"></canvas>
<canvas id="canvas" width="800" height="600"></canvas>
<script src= "./objects/vector2D.js"></script>
<script src= "./objects/forces.js"></script>
<script src= "./objects/ball.js"></script>
<script src= "force-fields.js"></script>
</body>
</html>
Loading

0 comments on commit 68254fc

Please sign in to comment.