MCPcopy Create free account
hub / github.com/NianBroken/Firework_Simulator / update

Function update

js/script.js:1237–1341  ·  view source on GitHub ↗
(frameTime, lag)

Source from the content-addressed store, hash-verified

1235
1236//帧绘制回调
1237function update(frameTime, lag) {
1238 if (!isRunning()) return;
1239
1240 const width = stageW;
1241 const height = stageH;
1242 const timeStep = frameTime * simSpeed;
1243 const speed = simSpeed * lag;
1244
1245 updateGlobals(timeStep, lag);
1246
1247 const starDrag = 1 - (1 - Star.airDrag) * speed;
1248 const starDragHeavy = 1 - (1 - Star.airDragHeavy) * speed;
1249 const sparkDrag = 1 - (1 - Spark.airDrag) * speed;
1250 const gAcc = (timeStep / 1000) * GRAVITY;
1251 COLOR_CODES_W_INVIS.forEach((color) => {
1252 // 绘制星花
1253 const stars = Star.active[color];
1254 for (let i = stars.length - 1; i >= 0; i = i - 1) {
1255 const star = stars[i];
1256 // Only update each star once per frame. Since color can change, it's possible a star could update twice without this, leading to a "jump".
1257 if (star.updateFrame === currentFrame) {
1258 continue;
1259 }
1260 star.updateFrame = currentFrame;
1261
1262 star.life -= timeStep;
1263 //星花生命周期结束回收实例
1264 if (star.life <= 0) {
1265 stars.splice(i, 1);
1266 Star.returnInstance(star);
1267 } else {
1268 const burnRate = Math.pow(star.life / star.fullLife, 0.5);
1269 const burnRateInverse = 1 - burnRate;
1270
1271 star.prevX = star.x;
1272 star.prevY = star.y;
1273 star.x += star.speedX * speed;
1274 star.y += star.speedY * speed;
1275 // Apply air drag if star isn't "heavy". The heavy property is used for the shell comets.
1276 //如果星形不是“heavy”,应用空气阻力。重的性质被用于壳彗星。
1277 if (!star.heavy) {
1278 star.speedX *= starDrag;
1279 star.speedY *= starDrag;
1280 } else {
1281 star.speedX *= starDragHeavy;
1282 star.speedY *= starDragHeavy;
1283 }
1284 star.speedY += gAcc;
1285
1286 if (star.spinRadius) {
1287 star.spinAngle += star.spinSpeed * speed;
1288 star.x += Math.sin(star.spinAngle) * star.spinRadius * speed;
1289 star.y += Math.cos(star.spinAngle) * star.spinRadius * speed;
1290 }
1291
1292 if (star.sparkFreq) {
1293 star.sparkTimer -= timeStep;
1294 while (star.sparkTimer < 0) {

Callers

nothing calls this directly

Calls 3

isRunningFunction · 0.85
updateGlobalsFunction · 0.85
renderFunction · 0.85

Tested by

no test coverage detected