尝试使用HTML,CSS和Javascript创建Codepen示例,
我刚刚添加了一个FPS计数器,但是它没有输出实际的FPS,
而是将其打印为我用作容器的跨度的Infinity。
没有在我的Js中分配Infinity的地方,而不是作为变量,
作为字符串或任何其他数据类型。所以问题是Javascript从哪里得到的?
它是常数吗?它是一个窗口对象吗?还是内置方法?
这是我的Js
var filterStrength = 20;
var frameTime = 0,lastLoop = new Date,thisLoop;
function gameLoop(){
//let frameTime;
var thisFrameTime = (thisLoop=new Date) - lastLoop;
frameTime+= (thisFrameTime - frameTime) / filterStrength;
lastLoop = thisLoop;
}
// Report the fps only every second,to only lightly affect measurements
var fpsOut = document.getElementById('Fps');
setInterval(function(){
fpsOut.innerHTML = (1000/frameTime).toFixed(1) + " fps";
},1000);
const w = innerWidth,h = innerHeight
const amount = 288 // Chng from: 88
function setup() {
v = min(w,h)
createCanvas(w,h)
const Canv = document.getElementsByTagName("canvas")[1];
background(0)
Canv.animate({filter: ["hue-rotate(180deg) blur(1.2px)","hue-rotate(246deg) blur(.34px)"]
//transform: ["rotateZ(0deg)","rotateZ(280deg)"]
},{iterations: Infinity,duration: 2848,direction: "alternate"})
}
function draw() {
colorMode(RGB)
background(0,10)
var t = frameCount/60 + 3/2*PI
t += cos(t)/3*2
const R = v/3
for(let i = 0; i < amount; i++) {
const a = i/amount * PI * (sin(t)+1) + t - 4780 // Changed last value from 0.7
const r = v/45 * tan(i/amount*10*PI) * (cos(t)+1)/2 * 472
const x = w/2 + (R + r) * sin(a)
const y = h/2 - (R + r) * cos(a) /0.8
colorMode(HSB,2*PI,100,100)
stroke(a - t,720,400)
fill(a - t,50,255)
ellipse(x,y,v/a*2,v/R *x)
}
}
可以在此处查看笔:Javascript Experimentation
此外,如何解决此问题,使其真正显示Window或Canvas的FPS ??