《making things move 》第三章

本章节深入探讨了《Making Things Move》第三章的内容,重点介绍了角度与弧度的转换、正弦波和余弦波的概念及其在Flash中的应用,并通过实例展示了如何利用这些原理实现动态效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

《making things move 》第三章
下载地址: http://www.nshen.net/blog/article.asp?id=495
暂时放弃手头正在写的枯燥的flex。。等apollo出来后再完成吧
开始读 《making things move 》了,希望能坚持下去,看书写笔记是个好习惯,不过实在没空写长篇读书总结,但会尽量把每章关键部分记录下来
今天开个头:

第一章 写animation的概念。。。这个。有机会再看

第二章 基础中的基础 写过as的都懂

从第三章开始 这章的内容虽然以前都见过,但很多其实没有真正的理解,看了Peters讲解会有更深的领悟...
chapter 3

基本概念:

1弧度大约等于 57.2958 角度

360 度为 2 pi, 180 度就是 pi, 90 度 pi/2,

mc的_rotation 要用角度来付值

角度和弧度转换公式

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

与传统相反:
y轴向下为正方向,顺时针方向是正角

正弦波:

attachments/200610/30_170127_1.gif


你现在可以看到sine 0 是 0. sine 90 角度或 pi/2 弧度 是 1.

sine 180 度 或 pi 弧度, 又是 0 . sine 270 角度, 或 3/2 pi 弧度, 是 −1.

sine 360 角度, 或 2 pi 弧度, 又回到 0 .

正弦波 in Flash
for(angle = 0;angle < Math.PI * 2; angle += .1){
 trace(Math.sin(angle));
}

0与 1之间游荡,但永远不会等于1,或0,是因为使用增量0.1 你永远得不到pi 或pi/2

从现在开始你要习惯使用弧度了~~只有_rotation时候才能用得上角度。。(这跟robert penner的全转成角度再算,形成对比哦)

例子:
angle = 0;
onEnterFrame = function(){
  ball._y = 200 + Math.sin(angle) * 50;
  angle += .1;
}

Media 点这里 显示/隐藏 媒体


余弦波:

attachments/200610/30_223040_2.gif


This shows that the cosine of 0 is 1, and as it moves through to 2 pi radians or 360 degrees, it goes to 0, −1, 0, and then back to 1

例子都在Chapter03文件里

圆行轨迹

正弦余弦共同作用的结果

attachments/200610/30_224254_3.gif


红色正弦线 = Math.sin(angle) * radius; 一周变化-------------- 0,-1,0,1,0
兰色余弦线 = Math.cos(angle) * radius; 一周变化---------------1,0,-1,0,1
angle = 0;
centerX = 270;
centerY = 200;
radius = 100;
speed = .1;

onEnterFrame = function(){
 ball._x = centerX + Math.cos(angle) * radius;
 ball._y = centerY + Math.sin(angle) * radius;
 angle += speed;
}

All the code is doing is using cosine to get the x position and sine to get the y position. You should get very used to those relationships. In Flash, almost any time you are talking about x, you should immediately think cosine, and you should almost always connect y with sine. In fact, spend as much time as you need to fully understand that last bit of code. It is going to be one of the most useful tools in your ActionScript animation toolbox.

椭圆:
angle = 0;
centerX = 270;
centerY = 200;
radiusX = 200;
radiusY = 100;
speed = .1;

onEnterFrame = function(){
  ball._x = centerX + Math.cos(angle) * radiusX;
  ball._y = centerY + Math.sin(angle) * radiusY;
  angle += speed;
}

Media 点这里 显示/隐藏 媒体


atan2 的方便 :给出坐标直接算出弧度

注意从右开始,顺时针是正角
onEnterFrame = function(){
 var dx = _xmouse - arrow._x;
 var dy = _ymouse - arrow._y;
 var radians = Math.atan2(dy, dx);
 arrow._rotation = radians * 180 / Math.PI;
}

Media 点这里 显示/隐藏 媒体
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值