Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 找到反弹的峰值_Javascript_Canvas_Html5 Canvas - Fatal编程技术网

Javascript 找到反弹的峰值

Javascript 找到反弹的峰值,javascript,canvas,html5-canvas,Javascript,Canvas,Html5 Canvas,我想捕捉反弹的峰值Y位置。所以每次球反弹时,我想捕捉它在反弹时达到的最高Y轴值 所以我知道第一个值是球的起始Y位置。但是,我不确定如何捕获后续值 ***请全屏运行该示例 “严格使用”; //待办事项 //-让球旋转 //-把球挤扁 //-增加速度线 //-仅清除球,而不是整个画布 (功能(){ const canvas=document.getElementsByClassName('canvas')[0], c=canvas.getContext('2d'); // ------------

我想捕捉反弹的峰值Y位置。所以每次球反弹时,我想捕捉它在反弹时达到的最高Y轴值

所以我知道第一个值是球的起始Y位置。但是,我不确定如何捕获后续值

***请全屏运行该示例

“严格使用”;
//待办事项
//-让球旋转
//-把球挤扁
//-增加速度线
//-仅清除球,而不是整个画布
(功能(){
const canvas=document.getElementsByClassName('canvas')[0],
c=canvas.getContext('2d');
// -----------------------------------
//将画布调整为全屏
// -----------------------------------
addEventListener('resize',resizeCanvas,false);
函数resizeCanvas(){
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
// ---------
//变数
// ---------
循环变异系数=40,
CircleLight=circleRadius*2,
x=(canvas.width/2)-circleRadius,//球的初始x位置
y=(canvas.height/2)-circleRadius,//球的初始y位置
坠落高度=y,
vx=0,//速度
vy=0,//速度
地面高度=圆周高度,
反弹点=[],
重力=0.8,
阻尼=0.5,
拉力强度=0.04,
分段=4,
bezieCircleFormula=(4/3)*Math.tan(Math.PI/(2*段)),//http://stackoverflow.com/a/27863181/2040509
点偏移={
阳性:贝塞尔圆公式*circleRadius,
负片:circleRadius-(bezieCircleFormula*circleRadius)
},
//每边有3个点,贝塞尔1,圆点,贝塞尔2
//下面按顺时针顺序列出了这些参数。
//所以顶部有:左贝塞尔,圆点,右贝塞尔
//右有:上贝塞尔、圆点、下贝塞尔
圆圈点={
顶部:[
[x+点偏移量。负,y],
[x+circleRadius,y],
[x+点偏移。正+圆,y]
],
对:[
[x+圆灯,y+点偏移。负],
[x+弧光,y+弧光],
[x+圆形灯光,y+点偏移。正+圆形]
],
底部:[
[x+点偏移。正+圆,y+圆],
[x+circleRadius,y+CircleLight],
[x+点偏移量。负数,y+圆形光]
],
左:[
[x,y+点偏移。正+圆偏移],
[x,y+circleRadius],
[x,y+点偏移。负]
]
};
// --------------------
//球挤压函数
// --------------------
//对于'side',可以通过'top','right','bottom','left`
//对于'amount',使用整数
功能挤压(侧面,挤压安装){
for(设i=0;i// begin with an overly large seed for the minimum Y value
var minY=1000000;

// whenever the circle changes position, save the minimum of minY & currentY
minY=Math.min(minY,currentY);