-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
episode 38. plus it looks like a lot of line endings got changed.
- Loading branch information
Showing
218 changed files
with
12,586 additions
and
11,844 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
CodingMath | ||
========== | ||
|
||
This repo will house any applicable files from the Coding Math videos. | ||
|
||
Site: http://codingmath.com | ||
|
||
YouTube: http://www.youtube.com/user/codingmath | ||
|
||
Support: http://www.patreon.com/codingmath | ||
CodingMath | ||
========== | ||
|
||
This repo will house any applicable files from the Coding Math videos. | ||
|
||
Site: http://codingmath.com | ||
|
||
YouTube: http://www.youtube.com/user/codingmath | ||
|
||
Support: http://www.patreon.com/codingmath |
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
<script type="text/javascript" src="vector.js"></script> | ||
<script type="text/javascript" src="particle.js"></script> | ||
<script type="text/javascript" src="utils.js"></script> | ||
<script type="text/javascript" src="main.js"></script> | ||
<style type="text/css"> | ||
html, body { | ||
margin: 0px; | ||
} | ||
|
||
canvas { | ||
display: block; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
<canvas id="canvas"></canvas> | ||
</body> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
<script type="text/javascript" src="vector.js"></script> | ||
<script type="text/javascript" src="particle.js"></script> | ||
<script type="text/javascript" src="utils.js"></script> | ||
<script type="text/javascript" src="main.js"></script> | ||
<style type="text/css"> | ||
html, body { | ||
margin: 0px; | ||
} | ||
|
||
canvas { | ||
display: block; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
<canvas id="canvas"></canvas> | ||
</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 |
---|---|---|
@@ -1,51 +1,51 @@ | ||
window.onload = function() { | ||
var canvas = document.getElementById("canvas"), | ||
context = canvas.getContext("2d"), | ||
width = canvas.width = window.innerWidth, | ||
height = canvas.height = window.innerHeight, | ||
gun = { | ||
x: 100, | ||
y: height, | ||
angle: -Math.PI / 4 | ||
}; | ||
|
||
draw(); | ||
|
||
document.body.addEventListener("mousedown", onMouseDown); | ||
|
||
function onMouseDown(event) { | ||
document.body.addEventListener("mousemove", onMouseMove); | ||
document.body.addEventListener("mouseup", onMouseUp); | ||
aimGun(event.clientX, event.clientY); | ||
} | ||
|
||
function onMouseMove(event) { | ||
aimGun(event.clientX, event.clientY); | ||
} | ||
|
||
function onMouseUp(event) { | ||
document.body.removeEventListener("mousemove", onMouseMove); | ||
document.body.removeEventListener("mouseup", onMouseUp); | ||
aimGun(event.clientX, event.clientY); | ||
} | ||
|
||
function aimGun(mouseX, mouseY) { | ||
gun.angle = utils.clamp(Math.atan2(mouseY - gun.y, mouseX - gun.x), -Math.PI / 2, -0.3); | ||
draw(); | ||
} | ||
|
||
function draw() { | ||
context.clearRect(0, 0, width, height); | ||
|
||
context.beginPath(); | ||
context.arc(gun.x, gun.y, 24, 0, Math.PI * 2, false); | ||
context.fill(); | ||
|
||
context.save(); | ||
context.translate(gun.x, gun.y); | ||
context.rotate(gun.angle); | ||
context.fillRect(0, -8, 40, 16); | ||
context.restore(); | ||
} | ||
|
||
window.onload = function() { | ||
var canvas = document.getElementById("canvas"), | ||
context = canvas.getContext("2d"), | ||
width = canvas.width = window.innerWidth, | ||
height = canvas.height = window.innerHeight, | ||
gun = { | ||
x: 100, | ||
y: height, | ||
angle: -Math.PI / 4 | ||
}; | ||
|
||
draw(); | ||
|
||
document.body.addEventListener("mousedown", onMouseDown); | ||
|
||
function onMouseDown(event) { | ||
document.body.addEventListener("mousemove", onMouseMove); | ||
document.body.addEventListener("mouseup", onMouseUp); | ||
aimGun(event.clientX, event.clientY); | ||
} | ||
|
||
function onMouseMove(event) { | ||
aimGun(event.clientX, event.clientY); | ||
} | ||
|
||
function onMouseUp(event) { | ||
document.body.removeEventListener("mousemove", onMouseMove); | ||
document.body.removeEventListener("mouseup", onMouseUp); | ||
aimGun(event.clientX, event.clientY); | ||
} | ||
|
||
function aimGun(mouseX, mouseY) { | ||
gun.angle = utils.clamp(Math.atan2(mouseY - gun.y, mouseX - gun.x), -Math.PI / 2, -0.3); | ||
draw(); | ||
} | ||
|
||
function draw() { | ||
context.clearRect(0, 0, width, height); | ||
|
||
context.beginPath(); | ||
context.arc(gun.x, gun.y, 24, 0, Math.PI * 2, false); | ||
context.fill(); | ||
|
||
context.save(); | ||
context.translate(gun.x, gun.y); | ||
context.rotate(gun.angle); | ||
context.fillRect(0, -8, 40, 16); | ||
context.restore(); | ||
} | ||
|
||
}; |
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 |
---|---|---|
@@ -1,48 +1,48 @@ | ||
var particle = { | ||
position: null, | ||
velocity: null, | ||
mass: 1, | ||
radius: 0, | ||
bounce: -1, | ||
friction: 1, | ||
|
||
create: function(x, y, speed, direction, grav) { | ||
var obj = Object.create(this); | ||
obj.position = vector.create(x, y); | ||
obj.velocity = vector.create(0, 0); | ||
obj.velocity.setLength(speed); | ||
obj.velocity.setAngle(direction); | ||
obj.gravity = vector.create(0, grav || 0); | ||
return obj; | ||
}, | ||
|
||
accelerate: function(accel) { | ||
this.velocity.addTo(accel); | ||
}, | ||
|
||
update: function() { | ||
this.velocity.multiplyBy(this.friction); | ||
this.velocity.addTo(this.gravity); | ||
this.position.addTo(this.velocity); | ||
}, | ||
|
||
angleTo: function(p2) { | ||
return Math.atan2(p2.position.getY() - this.position.getY(), p2.position.getX() - this.position.getX()); | ||
}, | ||
|
||
distanceTo: function(p2) { | ||
var dx = p2.position.getX() - this.position.getX(), | ||
dy = p2.position.getY() - this.position.getY(); | ||
|
||
return Math.sqrt(dx * dx + dy * dy); | ||
}, | ||
|
||
gravitateTo: function(p2) { | ||
var grav = vector.create(0, 0), | ||
dist = this.distanceTo(p2); | ||
|
||
grav.setLength(p2.mass / (dist * dist)); | ||
grav.setAngle(this.angleTo(p2)); | ||
this.velocity.addTo(grav); | ||
} | ||
var particle = { | ||
position: null, | ||
velocity: null, | ||
mass: 1, | ||
radius: 0, | ||
bounce: -1, | ||
friction: 1, | ||
|
||
create: function(x, y, speed, direction, grav) { | ||
var obj = Object.create(this); | ||
obj.position = vector.create(x, y); | ||
obj.velocity = vector.create(0, 0); | ||
obj.velocity.setLength(speed); | ||
obj.velocity.setAngle(direction); | ||
obj.gravity = vector.create(0, grav || 0); | ||
return obj; | ||
}, | ||
|
||
accelerate: function(accel) { | ||
this.velocity.addTo(accel); | ||
}, | ||
|
||
update: function() { | ||
this.velocity.multiplyBy(this.friction); | ||
this.velocity.addTo(this.gravity); | ||
this.position.addTo(this.velocity); | ||
}, | ||
|
||
angleTo: function(p2) { | ||
return Math.atan2(p2.position.getY() - this.position.getY(), p2.position.getX() - this.position.getX()); | ||
}, | ||
|
||
distanceTo: function(p2) { | ||
var dx = p2.position.getX() - this.position.getX(), | ||
dy = p2.position.getY() - this.position.getY(); | ||
|
||
return Math.sqrt(dx * dx + dy * dy); | ||
}, | ||
|
||
gravitateTo: function(p2) { | ||
var grav = vector.create(0, 0), | ||
dist = this.distanceTo(p2); | ||
|
||
grav.setLength(p2.mass / (dist * dist)); | ||
grav.setAngle(this.angleTo(p2)); | ||
this.velocity.addTo(grav); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
var utils = { | ||
norm: function(value, min, max) { | ||
return (value - min) / (max - min); | ||
}, | ||
|
||
lerp: function(norm, min, max) { | ||
return (max - min) * norm + min; | ||
}, | ||
|
||
map: function(value, sourceMin, sourceMax, destMin, destMax) { | ||
return lerp(norm(value, sourceMin, sourceMax), destMin, destMax); | ||
}, | ||
|
||
clamp: function(value, min, max) { | ||
return Math.min(Math.max(value, min), max); | ||
} | ||
var utils = { | ||
norm: function(value, min, max) { | ||
return (value - min) / (max - min); | ||
}, | ||
|
||
lerp: function(norm, min, max) { | ||
return (max - min) * norm + min; | ||
}, | ||
|
||
map: function(value, sourceMin, sourceMax, destMin, destMax) { | ||
return lerp(norm(value, sourceMin, sourceMax), destMin, destMax); | ||
}, | ||
|
||
clamp: function(value, min, max) { | ||
return Math.min(Math.max(value, min), max); | ||
} | ||
} |
Oops, something went wrong.