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

Function render

js/script.js:1343–1435  ·  view source on GitHub ↗
(speed)

Source from the content-addressed store, hash-verified

1341}
1342
1343function render(speed) {
1344 const { dpr } = mainStage;
1345 const width = stageW;
1346 const height = stageH;
1347 const trailsCtx = trailsStage.ctx;
1348 const mainCtx = mainStage.ctx;
1349
1350 if (skyLightingSelector() !== SKY_LIGHT_NONE) {
1351 colorSky(speed);
1352 }
1353
1354 // Account for high DPI screens, and custom scale factor.
1355 const scaleFactor = scaleFactorSelector();
1356 trailsCtx.scale(dpr * scaleFactor, dpr * scaleFactor);
1357 mainCtx.scale(dpr * scaleFactor, dpr * scaleFactor);
1358
1359 trailsCtx.globalCompositeOperation = "source-over";
1360 trailsCtx.fillStyle = `rgba(0, 0, 0, ${store.state.config.longExposure ? 0.0025 : 0.175 * speed})`;
1361 trailsCtx.fillRect(0, 0, width, height);
1362
1363 mainCtx.clearRect(0, 0, width, height);
1364
1365 // Draw queued burst flashes
1366 // These must also be drawn using source-over due to Safari. Seems rendering the gradients using lighten draws large black boxes instead.
1367 // Thankfully, these burst flashes look pretty much the same either way.
1368 // The language of this project was translated into Chinese by Nianbroken
1369 while (BurstFlash.active.length) {
1370 const bf = BurstFlash.active.pop();
1371
1372 const burstGradient = trailsCtx.createRadialGradient(bf.x, bf.y, 0, bf.x, bf.y, bf.radius);
1373 burstGradient.addColorStop(0.024, "rgba(255, 255, 255, 1)");
1374 burstGradient.addColorStop(0.125, "rgba(255, 160, 20, 0.2)");
1375 burstGradient.addColorStop(0.32, "rgba(255, 140, 20, 0.11)");
1376 burstGradient.addColorStop(1, "rgba(255, 120, 20, 0)");
1377 trailsCtx.fillStyle = burstGradient;
1378 trailsCtx.fillRect(bf.x - bf.radius, bf.y - bf.radius, bf.radius * 2, bf.radius * 2);
1379
1380 BurstFlash.returnInstance(bf);
1381 }
1382
1383 // Remaining drawing on trails canvas will use 'lighten' blend mode
1384 trailsCtx.globalCompositeOperation = "lighten";
1385
1386 // Draw stars
1387 trailsCtx.lineWidth = 3;
1388 trailsCtx.lineCap = isLowQuality ? "square" : "round";
1389 mainCtx.strokeStyle = "#fff";
1390 mainCtx.lineWidth = 1;
1391 mainCtx.beginPath();
1392 COLOR_CODES.forEach((color) => {
1393 const stars = Star.active[color];
1394
1395 trailsCtx.strokeStyle = color;
1396 trailsCtx.beginPath();
1397 stars.forEach((star) => {
1398 if (star.visible) {
1399 trailsCtx.lineWidth = star.size;
1400 trailsCtx.moveTo(star.x, star.y);

Callers 1

updateFunction · 0.85

Calls 3

skyLightingSelectorFunction · 0.85
colorSkyFunction · 0.85
scaleFactorSelectorFunction · 0.85

Tested by

no test coverage detected