-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayer_test.html
More file actions
205 lines (178 loc) · 8.13 KB
/
layer_test.html
File metadata and controls
205 lines (178 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html>
<head>
<title>Layer Rendering Test</title>
</head>
<body>
<h1>SimEarth-Style Layer Rendering Test</h1>
<div>
<button id="terrainBtn" class="active">Terrain (Base)</button>
<button id="waterBtn">Water</button>
<button id="biomesBtn">Biomes</button>
</div>
<canvas id="testCanvas" width="360" height="180" style="border: 1px solid black;"></canvas>
<script>
// Test elevation data (simplified Earth-like)
const testElevation = [
Array(360).fill().map((_, i) => -5000 + Math.sin(i * Math.PI / 180) * 2000), // Ocean trench to coastal
Array(360).fill().map((_, i) => Math.cos(i * Math.PI / 180) * 1000 + 100), // Lowlands
Array(360).fill().map((_, i) => Math.sin(i * Math.PI / 90) * 2000 + 1500), // Mountains
];
// Test biome data
const testBiomes = [
Array(360).fill('ocean'),
Array(360).fill('plains'),
Array(360).fill('mountains'),
];
// Test water data (depths)
const testWater = [
Array(360).fill(1000), // Deep water
Array(360).fill(0), // Land
Array(360).fill(0), // Land
];
// Calculate min/max for normalization
let minElevation = Infinity, maxElevation = -Infinity;
testElevation.forEach(row => {
row.forEach(elev => {
minElevation = Math.min(minElevation, elev);
maxElevation = Math.max(maxElevation, elev);
});
});
console.log('Test elevation range:', minElevation, 'to', maxElevation);
// Layer visibility
let visibleLayers = new Set(['terrain']);
// Color blending utility
function blendColors(baseColor, overlayColor, alpha) {
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
const base = hexToRgb(baseColor);
const overlay = hexToRgb(overlayColor);
if (!base || !overlay) return baseColor;
const r = Math.round(base.r * (1 - alpha) + overlay.r * alpha);
const g = Math.round(base.g * (1 - alpha) + overlay.g * alpha);
const b = Math.round(base.b * (1 - alpha) + overlay.b * alpha);
return '#' + r.toString(16).padStart(2, '0') + g.toString(16).padStart(2, '0') + b.toString(16).padStart(2, '0');
}
// Pure elevation heightmap colors (SimEarth-style)
function getElevationColor(elevationMeters) {
if (elevationMeters === null || elevationMeters === undefined) {
return '#000000';
}
const normalized = (elevationMeters - minElevation) / (maxElevation - minElevation);
if (normalized < 0.2) {
// Very low elevation - dark blue/black (ocean basins)
const intensity = Math.floor(10 + (normalized / 0.2) * 40);
return `rgb(${intensity}, ${intensity}, ${Math.floor(intensity * 1.5)})`;
} else if (normalized < 0.4) {
// Low elevation - dark brown (coastal plains)
const intensity = Math.floor(40 + ((normalized - 0.2) / 0.2) * 60);
return `rgb(${intensity}, ${Math.floor(intensity * 0.7)}, ${Math.floor(intensity * 0.4)})`;
} else if (normalized < 0.6) {
// Mid elevation - brown (plains)
const intensity = Math.floor(100 + ((normalized - 0.4) / 0.2) * 55);
return `rgb(${intensity}, ${Math.floor(intensity * 0.8)}, ${Math.floor(intensity * 0.6)})`;
} else if (normalized < 0.8) {
// High elevation - tan/gray (mountains)
const intensity = Math.floor(155 + ((normalized - 0.6) / 0.2) * 40);
return `rgb(${intensity}, ${intensity}, ${Math.floor(intensity * 0.9)})`;
} else {
// Very high elevation - light gray/white (peaks)
const intensity = Math.floor(195 + ((normalized - 0.8) / 0.2) * 60);
return `rgb(${intensity}, ${intensity}, ${intensity})`;
}
}
// Biome overlay colors
function getBiomeColor(biome) {
switch (biome) {
case 'ocean': return '#001122';
case 'desert': return '#DAA520';
case 'grassland': return '#228B22';
case 'forest': return '#006400';
case 'plains': return '#8B4513';
case 'mountains': return '#696969';
case 'peaks': return '#D3D3D3';
default: return '#8B4513';
}
}
// Render function
function render() {
const canvas = document.getElementById('testCanvas');
const ctx = canvas.getContext('2d');
const width = testElevation[0].length;
const height = testElevation.length;
const scale = 1;
canvas.width = width * scale;
canvas.height = height * scale;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const elevation = testElevation[y][x];
// BASE LAYER: Pure elevation heightmap (ALWAYS rendered)
let color = getElevationColor(elevation);
// LAYER 1: Water overlay (if enabled)
if (visibleLayers.has('water') && testWater[y][x] > 0) {
const waterDepth = testWater[y][x];
const blueIntensity = Math.min(255, 100 + (waterDepth / 1000) * 155);
color = `rgba(0, 0, ${Math.floor(blueIntensity)}, 0.8)`;
}
// LAYER 2: Biome overlay (if enabled)
if (visibleLayers.has('biomes') && testBiomes[y][x]) {
const biome = testBiomes[y][x];
if (biome && biome !== 'ocean') {
const isUnderwater = visibleLayers.has('water') && testWater[y][x] > 0;
if (!isUnderwater) {
color = getBiomeColor(biome);
}
}
}
ctx.fillStyle = color;
ctx.fillRect(x * scale, y * scale, scale, scale);
}
}
console.log('Rendered with layers:', Array.from(visibleLayers));
}
// Button handlers
document.getElementById('terrainBtn').addEventListener('click', () => {
visibleLayers.clear();
visibleLayers.add('terrain');
updateButtons();
render();
});
document.getElementById('waterBtn').addEventListener('click', () => {
if (visibleLayers.has('water')) {
visibleLayers.delete('water');
} else {
visibleLayers.add('water');
}
updateButtons();
render();
});
document.getElementById('biomesBtn').addEventListener('click', () => {
if (visibleLayers.has('biomes')) {
visibleLayers.delete('biomes');
} else {
visibleLayers.add('biomes');
}
updateButtons();
render();
});
function updateButtons() {
document.getElementById('terrainBtn').classList.toggle('active', visibleLayers.has('terrain'));
document.getElementById('waterBtn').classList.toggle('active', visibleLayers.has('water'));
document.getElementById('biomesBtn').classList.toggle('active', visibleLayers.has('biomes'));
}
// Initial render
render();
</script>
<style>
button { margin: 5px; padding: 5px 10px; }
.active { background: #ccc; }
</style>
</body>
</html></content>
<parameter name="filePath">/Users/tam0013/Documents/git/galaxyGame/layer_test.html