Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

圆点抖动问题 #37

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

圆点抖动问题 #37

wants to merge 5 commits into from

Conversation

stefenson
Copy link

@stefenson stefenson commented Jun 25, 2018

#2

只改了src里面的CanvasNest.js,dist目录跟lib目录不知道是干啥的就没动……

原谅我js写的少Orz……

@hustcc hustcc changed the title PR请求 圆点抖动问题 Jun 25, 2018
@hustcc
Copy link
Owner

hustcc commented Jun 25, 2018

你不 build 一下,怎么知道是不是生效的?

@stefenson
Copy link
Author

主要是不知道怎么Build……233

我对js项目真的不太熟悉……改动的地方应该是都进去了,应该不会有问题 ^_^||

@hustcc
Copy link
Owner

hustcc commented Jun 25, 2018

npm i

npm run build

然后打开 index.html 就可以测试了!

我来帮你测试下吧!

@hustcc
Copy link
Owner

hustcc commented Jun 25, 2018

测试过了,直接爆炸了,小点的移动速度很快。感觉是加速度错了!

@stefenson
Copy link
Author

又提交了一下,刚刚点重绘的位置不对,放到里层for循环了,所以才炸了Orz

@stefenson
Copy link
Author

测试了一下应该没问题了~

@hustcc
Copy link
Owner

hustcc commented Jun 25, 2018

感觉上还是有点问题,最后形成圈很慢,我还没有能理解你的代码思路。

@stefenson
Copy link
Author

stefenson commented Jun 25, 2018

嗯,是还有问题,主要是没有考虑两个速度分量应该怎么分配

简单来说现在的加速度变化只取决于点到中心距离关于max/2的比例,然后用这个系数同时处理纵向和横向的加速度,加速度与速度方向关系是如果下一秒点要向外部移动那么就是反的否则是正的。

但其实这样是不对的,只是近似处理成了飞向中心时加速,远离中心时减速的效果。

减速的速度偏移与点到中心的距离有关。

基本思路是这样的。

@laine001
Copy link

圆点的颜色,为什么修改了源码却不生效啊???

r.y += r.ya; // 移动
r.xa *= r.x > width || r.x < 0 ? -1 : 1;
r.ya *= r.y > height || r.y < 0 ? -1 : 1; // 碰到边界,反向反弹
context.fillRect(r.x - 0.5, r.y - 0.5, 1, 1); // 绘制一个宽高为1的点

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是这里设置point的颜色吗?添加fillStyle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants