Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Update 07-wave-2.html #5

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
24a330f
Update 07-wave-2.html
shuizhongyueming Nov 20, 2014
f89141f
+ 新增custom目录用来尝试把整个项目用es6实现
shuizhongyueming May 27, 2018
85c1883
+ 新增xtras/keycode.js
shuizhongyueming May 28, 2018
9fb213a
+ 完成ch03的classes部分的转换
shuizhongyueming May 28, 2018
e5872e0
+ utils 新增parseColor
shuizhongyueming May 29, 2018
b433fa5
完成ch03/04-wave-1.html改写
shuizhongyueming May 29, 2018
4cd5690
完成ch03/05-pulse.html改写
shuizhongyueming May 29, 2018
00723c0
完成ch03/06-random.html的改写
shuizhongyueming May 29, 2018
e7db20b
完成 ch03/07-wave-2.html 和 ch03/08-circle.html 的改写
shuizhongyueming May 29, 2018
52e97af
+ 优化ch03/08-circle.html代码,避免冗余的位置设定
shuizhongyueming May 29, 2018
5ad25d5
格式化代码
shuizhongyueming May 30, 2018
dec8772
+ 新增ch04/assets
shuizhongyueming May 30, 2018
32e17ce
完成curve相关的五个例子的改写
shuizhongyueming May 30, 2018
7b54966
Merge branch 'master' of https://github.com/shuizhongyueming/html5-an…
shuizhongyueming May 30, 2018
9b8b8d7
+ 完成ch04里面gradient部分改写
shuizhongyueming May 31, 2018
a9ef217
a 完a ch04/13-invert-color.html 的改写
shuizhongyueming Jun 2, 2018
588b847
新增ch05, 完成classes转换
shuizhongyueming Jun 3, 2018
37b2a50
完成ch05的所有例子的转换
shuizhongyueming Jun 4, 2018
58ab4d2
新增ch06,加上classes
shuizhongyueming Jun 5, 2018
74d737c
补充ball.js里面欠缺的两个属性vx和vy
shuizhongyueming Jun 5, 2018
7832e4a
+ 完成ch06/01-removal.html的改写
shuizhongyueming Jun 5, 2018
cb1f9e6
+ 完成04-bouncing-1.html的改写
shuizhongyueming Jun 6, 2018
47093ae
+ utils 加上rectContainsPoint和circleContainsPoint
shuizhongyueming Jun 7, 2018
c40f5d1
新增ch08
shuizhongyueming Jun 9, 2018
6578e6a
完成ch08的01到11的例子的改写
shuizhongyueming Jun 10, 2018
a53f828
完成ch08的12到15的例子的改写
shuizhongyueming Jun 11, 2018
6d58d00
+ 恢复15的例子
shuizhongyueming Jun 12, 2018
7a03bf1
新增ch09
shuizhongyueming Jun 16, 2018
90030a2
调整rectContainsPoint的实现
shuizhongyueming Jun 19, 2018
68bdf3f
修复box的依赖问题
shuizhongyueming Jun 19, 2018
0817ce8
完成demo ch09/01-object-hit-test.html 的改写
shuizhongyueming Jun 19, 2018
54071a4
+ 补充utils里面缺少的intersects方法
shuizhongyueming Jun 20, 2018
b43d2f5
完成ch09的 03 - 08的改写
shuizhongyueming Jun 23, 2018
0cbaed6
+ ch10 完成 01 - 08的改写
shuizhongyueming Jun 24, 2018
4fe3333
完成ch10 09和10的改写
shuizhongyueming Jun 25, 2018
dce6222
新增ch11
shuizhongyueming Jun 25, 2018
0f478ae
完成ch11 01到03的改写
shuizhongyueming Jun 25, 2018
d1a42b8
完成ch11/04的改写,但是无法解决误差累积的问题
shuizhongyueming Jun 26, 2018
40f0eac
+ 修复ch11/04里面计算误差的问题
shuizhongyueming Jun 26, 2018
78f887b
新增ch12
shuizhongyueming Jun 26, 2018
a4326d4
完成ch12 01到03的改写
shuizhongyueming Jun 27, 2018
2ee7ec2
新增colorToRGB方法改写
shuizhongyueming Jul 3, 2018
4311d6b
完成ch12 04 - 08的改写
shuizhongyueming Jul 3, 2018
e2f80e9
新增ch13,完成classes segment的改写
shuizhongyueming Jul 5, 2018
6a94c8d
完成ch13的01到05的改写
shuizhongyueming Jul 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions custom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
尝试以ES6的方式重写所有的例子
28 changes: 28 additions & 0 deletions custom/examples/ch02/04-mouse-position.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Mouse Position</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>
<aside>Open debugging console in web browser and click mouse.</aside>

<!-- <script src="../include/utils.js"></script> -->
<script type="module">
import {captureMouse} from '../include/utils.js'
window.onload = function () {
var canvas = document.getElementById('canvas'),
mouse = captureMouse(canvas);

canvas.addEventListener('mousedown', function () {
console.log("x: " + mouse.x + ", y: " + mouse.y);
}, false);
};
</script>
</body>
</html>
41 changes: 41 additions & 0 deletions custom/examples/ch02/08-key-names.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Key Names</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<aside>Open debugging console in web browser and press arrow key.</aside>

<script type="module">
import keycode from '../../xtras/keycode.js'
window.onload = function () {

function onKeyboardEvent (event) {
switch (event.keyCode) {
case keycode.UP:
console.log("up!");
break;
case keycode.DOWN:
console.log("down!");
break;
case keycode.LEFT:
console.log("left!");
break;
case keycode.RIGHT:
console.log("right!");
break;
default:
console.log(event.keyCode);
}
}

window.addEventListener('keydown', onKeyboardEvent, false);
};
</script>
</body>
</html>
39 changes: 39 additions & 0 deletions custom/examples/ch03/01-rotate-to-mouse.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Rotate to Mouse</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>
<aside>Move mouse on canvas element.</aside>

<script type="module">
import {captureMouse} from '../include/utils.js'
import Arrow from './classes/arrow.js'
window.onload = () => {
const canvas = document.getElementById('canvas')
const context = canvas.getContext('2d')
let mouse = captureMouse(canvas)
let arrow = new Arrow()
arrow.x = canvas.width / 2
arrow.y = canvas.height / 2

;(function drawFrame () {
window.requestAnimationFrame(drawFrame, canvas)
context.clearRect(0, 0, canvas.width, canvas.height)

const dx = mouse.x - arrow.x
const dy = mouse.y - arrow.y

arrow.rotation = Math.atan2(dy, dx)
arrow.draw(context)
}())
};
</script>
</body>
</html>
42 changes: 42 additions & 0 deletions custom/examples/ch03/02-bobbing-1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bobbing 1</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>

<script type="module">
import '../include/utils.js';
import Ball from './classes/ball.js'
window.onload = function () {
const canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
ball = new Ball();
const {width, height} = canvas;
const centerY = height / 2;
const range = 100;
let angle = 0;
const angleSpeed = 0.05;

ball.x = width / 2;
ball.y = centerY;

;(function draw(){
window.requestAnimationFrame(draw, canvas);
context.clearRect(0, 0, width, height);

angle += angleSpeed;
ball.y = centerY + Math.sin(angle) * range;

ball.draw(context);
}());
};
</script>
</body>
</html>
44 changes: 44 additions & 0 deletions custom/examples/ch03/04-wave-1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bobbing 1</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>

<script type="module">
import '../include/utils.js';
import Ball from './classes/ball.js'
window.onload = function () {
const canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
ball = new Ball();
const {width, height} = canvas;
const centerY = height / 2;
const range = 100;
let angle = 0;
const angleSpeed = 0.05;
const speedX = 1;

ball.x = 0;
ball.y = centerY;

;(function draw(){
window.requestAnimationFrame(draw, canvas);
context.clearRect(0, 0, width, height);

angle += angleSpeed;
ball.y = centerY + Math.sin(angle) * range;
ball.x += speedX;

ball.draw(context);
}());
};
</script>
</body>
</html>
42 changes: 42 additions & 0 deletions custom/examples/ch03/05-pulse.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bobbing 1</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>

<script type="module">
import '../include/utils.js';
import Ball from './classes/ball.js'
window.onload = function () {
const canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
ball = new Ball();
const {width, height} = canvas;
const range = 0.8;
const scaleBase = 1;
let angle = 0;
const angleSpeed = 0.05;

ball.x = width / 2;
ball.y = height / 2;

;(function draw(){
window.requestAnimationFrame(draw, canvas);
context.clearRect(0, 0, width, height);

angle += angleSpeed;
ball.scaleX = ball.scaleY = scaleBase + Math.sin(angle) * range;

ball.draw(context);
}());
};
</script>
</body>
</html>
47 changes: 47 additions & 0 deletions custom/examples/ch03/06-random.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bobbing 1</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>

<script type="module">
import '../include/utils.js';
import Ball from './classes/ball.js'
window.onload = function () {
const canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
ball = new Ball();
const {width, height} = canvas;
const centerX = width / 2;
const centerY = height / 2;
const range = 50;
let angleX = 0;
let angleY = 0;
const angleSpeedX = 0.07;
const angleSpeedY = 0.11;

ball.x = 0;
ball.y = centerY;

;(function draw(){
window.requestAnimationFrame(draw, canvas);
context.clearRect(0, 0, width, height);

angleX += angleSpeedX;
angleY += angleSpeedY;
ball.x = centerX + Math.cos(angleX) * range;
ball.y = centerY + Math.sin(angleY) * range;

ball.draw(context);
}());
};
</script>
</body>
</html>
53 changes: 53 additions & 0 deletions custom/examples/ch03/07-wave-2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bobbing 1</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>

<script type="module">
import '../include/utils.js';
window.onload = function () {
const canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
const {width, height} = canvas;
const centerY = height / 2;
let posX = 0;
let posY = centerY;
let angle = 0;
const angleSpeed = 0.05;
const speedX = 1;
const range = 50;

// 宽度太小,曲线不会很平滑
context.lineWidth = 2;

;(function draw(){
window.requestAnimationFrame(draw, canvas);

// canvas的坐标系不一样
// Y轴越大越向下
// 为了使得曲线一开始走正向
// 需要反向的函数波形
angle -= angleSpeed;

context.beginPath();
context.moveTo(posX, posY);

posX += speedX;
posY = centerY + Math.sin(angle) * range;

context.lineTo(posX, posY);
context.stroke();

}());
};
</script>
</body>
</html>
41 changes: 41 additions & 0 deletions custom/examples/ch03/08-circle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bobbing 1</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>

<script type="module">
import '../include/utils.js';
import Ball from './classes/ball.js'
window.onload = function () {
const canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
ball = new Ball();
const {width, height} = canvas;
const centerX = width / 2;
const centerY = height / 2;
const range = 100;
let angle = 0;
const angleSpeed = 0.05;

;(function draw(){
window.requestAnimationFrame(draw, canvas);
context.clearRect(0, 0, width, height);

ball.x = centerX + Math.cos(angle) * range;
ball.y = centerY + Math.sin(angle) * range;
angle += angleSpeed;

ball.draw(context);
}());
};
</script>
</body>
</html>
Loading