-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 18, 2016
0 parents
commit 68254fc
Showing
501 changed files
with
6,515 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
background-color: #666; | ||
} | ||
#canvas { | ||
background-color: #fff; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.