笔记十(重要公式阶段总结)

来源:互联网 发布:2016网络对战射击游戏 编辑:程序博客网 时间:2024/06/11 20:01

对前面笔记中所用到的重要公式做个阶段性总结:

1、三角学基础函数

sine of angle = opposite / hypotenusecosine of angle = adjacent / hypotenusetangent of angle = opposite / adjacent

2、角度与弧度相互转换

 radians = degrees * Math.PI / 180 degrees = radians * 180 / Math.PI

3、旋转(按指向鼠标总结)

dx = mouse.x - object.x;dy = mouse.y - object.y;object.rotation = Math.atan2(dy,dx) * 180 / Math.PI;

4、创建波

(function drawFrame(){    window.requestAnimationFrame(drawFrame , canvas);    value = center + Math.sin(angle) * range;    angle += speed;}());

5、创建圆形

(function drawFrame(){    window.requestAnimationFrame(drawFrame , canvas);    xposition = centerX + Math.cos(angle) * radius;    yposition = centerY + Math.sin(angle) * radius;    angle += speed;}());

6、创建椭圆形

(function drawFrame(){    window.requestAnimationFrame(drawFrame , canvas);    xposition = centerX + Math.cos(angle) * radiusX;    yposition = centerY + Math.sin(angle) * radiusY;    angle += speed;}());

7、勾股定理获取两点距离

dx = x2 - x1;dy = y2 - y1;dist = Math.sqrt(dx * dx + dy * dy);

参见《HTML5+Javascript动画基础》。

0 0
原创粉丝点击