js模拟自然生命进化动画代码
代码语言:html
所属分类:动画
代码描述:js模拟自然生命进化动画代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>自然界生命进化模拟</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #0a0a1a;
color: #e0e0e0;
font-family: 'Courier New', monospace;
overflow: hidden;
user-select: none;
}
#canvas {
display: block;
background: radial-gradient(ellipse at center, #0d1b2a 0%, #050810 100%);
}
#ui {
position: fixed;
top: 10px;
right: 10px;
width: 260px;
background: rgba(10,15,30,0.92);
border: 1px solid #1a3a5c;
border-radius: 10px;
padding: 12px;
z-index: 100;
box-shadow: 0 0 20px rgba(0,100,255,0.15);
max-height: 95vh;
overflow-y: auto;
}
#ui::-webkit-scrollbar { width: 4px; }
#ui::-webkit-scrollbar-track { background: #0a0f1e; }
#ui::-webkit-scrollbar-thumb { background: #1a4a7a; border-radius: 2px; }
#ui h2 {
text-align: center;
color: #4af;
font-size: 14px;
margin-bottom: 10px;
letter-spacing: 2px;
text-transform: uppercase;
border-bottom: 1px solid #1a3a5c;
padding-bottom: 8px;
}
.section {
margin-bottom: 10px;
background: rgba(255,255,255,0.02);
border-radius: 6px;
padding: 8px;
border: 1px solid rgba(100,150,255,0.08);
}
.section-title {
font-size: 10px;
color: #6af;
letter-spacing: 1px;
margin-bottom: 6px;
text-transform: uppercase;
}
.param {
display: flex;
align-items: center;
margin-bottom: 5px;
gap: 6px;
}
.param label {
font-size: 10px;
color: #aaa;
flex: 1;
white-space: nowrap;
}
.param input[type=range] {
flex: 1.5;
height: 3px;
accent-color: #4af;
cursor: pointer;
}
.param span {
font-size: 10px;
color: #4af;
min-width: 30px;
text-align: right;
}
.btn {
width: 100%;
padding: 6px;
margin-bottom: 4px;
border: 1px solid #1a4a7a;
background: rgba(20,60,120,0.3);
color: #4af;
border-radius: 5px;
cursor: pointer;
font-size: 11px;
font-family: inherit;
transition: all 0.2s;
letter-spacing: 1px;
}
.btn:hover { background: rgba(30,80,160,0.5); border-color: #4af; }
.btn.active { background: rgba(50,120,220,0.4); border-color: #6cf; color: #fff; }
.btn-row { display: flex; gap: 4px; }
.btn-row .btn { margin-bottom: 0; }
#stats {
position: fixed;
top: 10px;
left: 10px;
background: rgba(10,15,30,0.88);
border: 1px solid #1a3a5c;
border-radius: 10px;
padding: 10px 14px;
font-size: 11px;
line-height: 1.8;
z-index: 100;
min-width: 180px;
}
#stats .stat-row { display: flex; justify-content: space-between; gap: 20px; }
#stats .val { color: #4af; font-weight: bold; }
.era-badge {
text-align: center;
padding: 3px 8px;
border-radius: 12px;
font-size: 10px;
margin-bottom: 6px;
font-weight: bold;
letter-spacing: 1px;
}
#legend {
position: fixed;
bottom: 10px;
left: 10px;
background: rgba(10,15,30,0.88);
border: 1px solid #1a3a5c;
border-radius: 10px;
padding: 8px 12px;
font-size: 10px;
z-index: 100;
}
.leg-item { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.leg-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tooltip {
position: fixed;
background: rgba(5,10,25,0.95);
border: 1px solid #2a5a9c;
border-radius: 6px;
padding: 6px 10px;
font-size: 10px;
line-height: 1.7;
pointer-events: none;
z-index: 200;
display: none;
max-width: 160px;
}
#timeline {
position: fixed;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background: rgba(10,15,30,0.88);
border: 1px solid #1a3a5c;
border-radius: 10px;
padding: 6px 14px;
font-size: 10px;
text-align: center;
z-index: 100;
min-width: 300px;
}
#timeline .era-name { color: #4af; font-weight: bold; font-size: 12px; }
#timeline .progress-bar {
width: 100%;
height: 4px;
background: #1a2a4a;
border-radius: 2px;
margin-top: 4px;
overflow: hidden;
}
#timeline .progress-fill {
height: 100%;
background: linear-gradient(90deg, #2a6, #4af, #f84);
border-radius: 2px;
transition: width 0.5s;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="stats">
<div class="era-badge" id="eraBadge">◆ 太古代</div>
<div class="stat-row"><span>🧬 生物数量</span><span class="val" id="popCount">0</span></div>
<div class="stat-row"><span>🌿 植物数量</span><span class="val" id="plantCount">0</span></div>
<div class="stat-row"><span>💀 总灭绝数</span><span class="val" id="extinctCount">0</span></div>
<div class="stat-row"><span>🌍 进化年代</span><span class="val" id="genCount">0</span></div>
<div class="stat-row"><span>⚡ 平均适应度</span><span class="val" id="avgFitness">0</span></div>
<div class="stat-row"><span>🔄 突变次数</span><span class="val" id="mutCount">0</span></div>
</div>
<div id="ui">
<h2>⚙ 进化参数</h2>
<div class="section">
<div class="section-title">🌍 环境设置</div>
<div class="param">
<label>食物丰富度</label>
<input type="range".........完整代码请登录后点击上方下载按钮下载查看















网友评论0