Particle Explosion
Runnable Cesium example: Particle Explosion. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:用 burst 做周期性爆散
要点:emissionRate 归零,靠 ParticleBurst 在指定时间一次性抛出大量粒子
依赖:CesiumJS 1.121 · jsDelivr CDN,火星贴图由 canvas 生成
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>爆炸粒子</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Widgets/widgets.css">
<style>
html,body{height:100%;margin:0}
body{background:#0e1116;color:#e6e8ec;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif}
#c{height:100%}
.hud{position:absolute;left:12px;top:12px;z-index:5;background:rgba(23,28,35,.92);
border:1px solid #2a313b;border-radius:6px;padding:9px 12px;font-size:12px;
color:#a2a9b6;width:252px}
.hud b{color:#e6e8ec;font-weight:600}
.hud .row{margin-top:7px}
.hud button{font:inherit;font-size:12px;padding:3px 9px;border-radius:4px;cursor:pointer;
border:1px solid #343b46;background:#1d232b;color:#cfd6e2;margin-top:8px}
.cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="hud">
<div><b>爆散</b></div>
<div class="row">每 2.5 秒一组,单组最多 240 粒</div>
<div class="row">重力让火星落回地面</div>
<div class="row"><button id="once">清空现有火星</button></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Cesium.js"></script>
<script>
(function () {
'use strict';
var viewer = new Cesium.Viewer('c', {
baseLayer: false,
baseLayerPicker: false, geocoder: false, homeButton: false,
sceneModePicker: false, navigationHelpButton: false,
animation: false, timeline: false, fullscreenButton: false,
infoBox: false, selectionIndicator: false
});
var scene = viewer.scene;
scene.globe.baseColor = Cesium.Color.fromCssColorString('#1c2733');
scene.backgroundColor = Cesium.Color.fromCssColorString('#0e1116');
scene.skyBox.show = false;
scene.sun.show = false;
scene.moon.show = false;
if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;
/* 火星贴图:小白点带柔边 */
function sparkTexture() {
var c = document.createElement('canvas');
c.width = c.height = 32;
var ctx = c.getContext('2d');
var g = ctx.createRadialGradient(16, 16, 0, 16, 16, 16);
g.addColorStop(0, 'rgba(255,255,255,1)');
g.addColorStop(0.45, 'rgba(255,240,190,0.9)');
g.addColorStop(1, 'rgba(255,200,120,0)');
ctx.fillStyle = g;
ctx.fillRect(0, 0, 32, 32);
return c;
}
var TEX = sparkTexture();
/* 重力 + 阻力,方向都在局部坐标系里 */
function gravity(particle, dt) {
particle.velocity.z -= 42 * dt;
particle.velocity.x *= 0.985;
particle.velocity.y *= 0.985;
particle.velocity.z *= 0.995;
}
function makeSystem(lng, lat) {
var matrix = Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(lng, lat, 240)
);
return new Cesium.ParticleSystem({
image: TEX,
startColor: Cesium.Color.fromCssColorString('#fff6cf').withAlpha(1),
endColor: Cesium.Color.fromCssColorString('#ff4d22').withAlpha(0.0),
startScale: 1.0,
endScale: 0.5,
minimumParticleLife: 1.1,
maximumParticleLife: 2.0,
minimumSpeed: 45,
maximumSpeed: 150,
imageSize: new Cesium.Cartesian2(14, 14),
emissionRate: 0,
emitter: new Cesium.SphereEmitter(2.0),
modelMatrix: matrix,
lifetime: 5.0,
loop: true,
bursts: [
new Cesium.ParticleBurst({ time: 0.2, minimum: 160, maximum: 240 }),
new Cesium.ParticleBurst({ time: 2.7, minimum: 160, maximum: 240 })
],
updateCallback: gravity
});
}
var systems = [];
[[116.382, 39.902], [116.397, 39.902]].forEach(function (p) {
var s = makeSystem(p[0], p[1]);
systems.push(s);
scene.primitives.add(s);
});
/* 爆点下的圆台标记 */
[[116.382, 39.902], [116.397, 39.902]].forEach(function (p) {
viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(p[0], p[1], 20),
cylinder: {
length: 40, topRadius: 26, bottomRadius: 34,
material: Cesium.Color.fromCssColorString('#3a2a24')
}
});
});
/* 清空已抛出的火星,等下一组 burst 重新开始 */
document.getElementById('once').addEventListener('click', function () {
systems.forEach(function (s) {
if (typeof s.removeAllParticles === 'function') s.removeAllParticles();
});
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.376, 39.892, 900),
orientation: {
heading: Cesium.Math.toRadians(10),
pitch: Cesium.Math.toRadians(-12),
roll: 0
},
duration: 0
});
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.