Skip to content

Commit 0de41f9

Browse files
committed
js functions and 2d animations
1 parent 703e78d commit 0de41f9

File tree

6 files changed

+113
-0
lines changed

6 files changed

+113
-0
lines changed

learning-js-functions/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Learning JavaScript Functions
2+
3+
> [https://www.youtube.com/watch?v=jEx9V4uUcg0](https://www.youtube.com/watch?v=jEx9V4uUcg0)
4+
5+
Install [io.js](https://iojs.org/en/index.html).
6+
7+
Within this folder run the terminal command `npm install` to install the
8+
`devDependencies`.
9+
10+
Then run `npm start` to start up a development server on `http://localhost:9966`

learning-js-functions/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
var context = {
4+
type: 'grizzly',
5+
says: 'grr'
6+
}
7+
8+
bear = bear.bind(context)
9+
10+
//var says = bear.apply(context, ['grr', 'grizzly'])
11+
var says = bear()
12+
console.log(says)
13+
14+
// var bear = function() {
15+
// return 'The ' + arguments[0] + ' bear says: ' + arguments[1]
16+
// }
17+
18+
function bear() {
19+
console.log(this)
20+
return 'The ' + this.type + ' bear says: ' + this.says
21+
}

learning-js-functions/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "learning-js-functions",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "budo index.js --live-plugin"
8+
},
9+
"author": "Kyle Robinson Young <[email protected]> (http://dontkry.com)",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"budo": "^2.1.2",
13+
"watchify": "^3.1.0"
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 2D Animations with Canvas and JavaScript
2+
3+
> [https://www.youtube.com/watch?v=TpRYLEFu4Mc](https://www.youtube.com/watch?v=TpRYLEFu4Mc)
4+
5+
Install [io.js](https://iojs.org/en/index.html).
6+
7+
Within this folder run the terminal command `npm install` to install the
8+
`devDependencies`.
9+
10+
Then run `npm start` to start up a development server on `http://localhost:9966`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var canvas = document.createElement('canvas')
2+
document.body.appendChild(canvas)
3+
4+
canvas.width = window.screen.width
5+
canvas.height = window.screen.height
6+
7+
var context = canvas.getContext('2d')
8+
9+
//context.fillStyle = 'red'
10+
//context.fillRect(0, 0, 100, 100)
11+
12+
// context.fillStyle = 'green'
13+
// context.fillRect(200, 0, 100, 100)
14+
15+
var x = 0
16+
var y = 0
17+
window.requestAnimationFrame(function loop() {
18+
//x += 1
19+
//y += .5
20+
21+
context.clearRect(0, 0, canvas.width, canvas.height)
22+
23+
context.fillStyle = 'red'
24+
context.fillRect(x, 0, 100, 100)
25+
26+
context.fillStyle = 'green'
27+
context.fillRect(200, y, 100, 100)
28+
29+
window.requestAnimationFrame(loop)
30+
})
31+
32+
33+
document.addEventListener('mousedown', function(event) {
34+
if (event.button === 0) {
35+
x += 10
36+
}
37+
if (event.button === 2) {
38+
y += 10
39+
}
40+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "my-project",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "budo index.js --live"
8+
},
9+
"author": "Kyle Robinson Young <[email protected]> (http://dontkry.com)",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"budo": "^3.0.4",
13+
"watchify": "^3.1.0"
14+
},
15+
"dependencies": {
16+
}
17+
}

0 commit comments

Comments
 (0)