i needs latitude longitude input, it does not generate output right now
Browse files- index.html +8 -0
- script.js +106 -40
- style.css +5 -0
index.html
CHANGED
|
@@ -46,6 +46,14 @@
|
|
| 46 |
<input type="text" id="mapName" class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-primary-500">
|
| 47 |
</div>
|
| 48 |
<div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
<label class="block text-gray-700 dark:text-gray-300 mb-2">Star Density</label>
|
| 50 |
<select id="starDensity" class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-primary-500">
|
| 51 |
<option value="low">Low (100 stars)</option>
|
|
|
|
| 46 |
<input type="text" id="mapName" class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-primary-500">
|
| 47 |
</div>
|
| 48 |
<div>
|
| 49 |
+
<label class="block text-gray-700 dark:text-gray-300 mb-2">Latitude</label>
|
| 50 |
+
<input type="number" id="latitude" min="-90" max="90" step="0.0001" value="0" class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-primary-500">
|
| 51 |
+
</div>
|
| 52 |
+
<div>
|
| 53 |
+
<label class="block text-gray-700 dark:text-gray-300 mb-2">Longitude</label>
|
| 54 |
+
<input type="number" id="longitude" min="-180" max="180" step="0.0001" value="0" class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-primary-500">
|
| 55 |
+
</div>
|
| 56 |
+
<div>
|
| 57 |
<label class="block text-gray-700 dark:text-gray-300 mb-2">Star Density</label>
|
| 58 |
<select id="starDensity" class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-primary-500">
|
| 59 |
<option value="low">Low (100 stars)</option>
|
script.js
CHANGED
|
@@ -3,11 +3,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 3 |
const previewButton = document.getElementById('previewButton');
|
| 4 |
const starMapContainer = document.getElementById('starMapContainer');
|
| 5 |
const mapNameInput = document.getElementById('mapName');
|
|
|
|
|
|
|
| 6 |
const starDensitySelect = document.getElementById('starDensity');
|
| 7 |
const constellationStyleSelect = document.getElementById('constellationStyle');
|
| 8 |
-
|
| 9 |
-
previewButton.addEventListener('click', function() {
|
| 10 |
const mapName = mapNameInput.value || 'Unnamed Star Map';
|
|
|
|
|
|
|
| 11 |
// Clear previous content
|
| 12 |
starMapContainer.innerHTML = '';
|
| 13 |
|
|
@@ -24,14 +27,62 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 24 |
feather.replace();
|
| 25 |
}, 1500);
|
| 26 |
});
|
| 27 |
-
function generateStarMap() {
|
| 28 |
const containerWidth = starMapContainer.offsetWidth;
|
| 29 |
const containerHeight = starMapContainer.offsetHeight;
|
| 30 |
const mapName = mapNameInput.value || 'Unnamed Star Map';
|
|
|
|
|
|
|
| 31 |
const starDensity = starDensitySelect.value;
|
| 32 |
const constellationStyle = constellationStyleSelect.value;
|
| 33 |
|
| 34 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
const constellations = [
|
| 36 |
{ name: "Orion", stars: [[0.3,0.2],[0.35,0.25],[0.4,0.3],[0.45,0.35],[0.5,0.4]] },
|
| 37 |
{ name: "Ursa Major", stars: [[0.6,0.1],[0.65,0.15],[0.7,0.2],[0.75,0.25],[0.8,0.3]] },
|
|
@@ -45,49 +96,64 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 45 |
case 'high': starCount = 300; break;
|
| 46 |
default: starCount = 150;
|
| 47 |
}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
const star = document.createElement('div');
|
| 52 |
-
star.className = 'star';
|
| 53 |
-
|
| 54 |
-
// Random position
|
| 55 |
-
const left = Math.random() * containerWidth;
|
| 56 |
-
const top = Math.random() * containerHeight;
|
| 57 |
-
|
| 58 |
-
// Random size
|
| 59 |
-
const size = Math.random() * 3 + 1;
|
| 60 |
-
|
| 61 |
-
star.style.width = `${size}px`;
|
| 62 |
-
star.style.height = `${size}px`;
|
| 63 |
-
star.style.left = `${left}px`;
|
| 64 |
-
star.style.top = `${top}px`;
|
| 65 |
-
|
| 66 |
-
// Random animation delay
|
| 67 |
-
star.style.animationDelay = `${Math.random() * 2}s`;
|
| 68 |
-
|
| 69 |
-
starMapContainer.appendChild(star);
|
| 70 |
-
}
|
| 71 |
-
// Generate constellation stars (brighter and larger)
|
| 72 |
-
constellations.forEach(constellation => {
|
| 73 |
-
constellation.stars.forEach(starPos => {
|
| 74 |
const star = document.createElement('div');
|
| 75 |
-
star.className = '
|
| 76 |
|
| 77 |
-
const left =
|
| 78 |
-
const top =
|
|
|
|
| 79 |
|
| 80 |
-
star.style.width =
|
| 81 |
-
star.style.height =
|
| 82 |
star.style.left = `${left}px`;
|
| 83 |
star.style.top = `${top}px`;
|
| 84 |
-
star.style.
|
| 85 |
|
| 86 |
starMapContainer.appendChild(star);
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
constellations.forEach(constellation => {
|
| 92 |
const stars = constellation.stars;
|
| 93 |
for (let i = 0; i < stars.length - 1; i++) {
|
|
|
|
| 3 |
const previewButton = document.getElementById('previewButton');
|
| 4 |
const starMapContainer = document.getElementById('starMapContainer');
|
| 5 |
const mapNameInput = document.getElementById('mapName');
|
| 6 |
+
const latitudeInput = document.getElementById('latitude');
|
| 7 |
+
const longitudeInput = document.getElementById('longitude');
|
| 8 |
const starDensitySelect = document.getElementById('starDensity');
|
| 9 |
const constellationStyleSelect = document.getElementById('constellationStyle');
|
| 10 |
+
previewButton.addEventListener('click', function() {
|
|
|
|
| 11 |
const mapName = mapNameInput.value || 'Unnamed Star Map';
|
| 12 |
+
const latitude = parseFloat(latitudeInput.value) || 0;
|
| 13 |
+
const longitude = parseFloat(longitudeInput.value) || 0;
|
| 14 |
// Clear previous content
|
| 15 |
starMapContainer.innerHTML = '';
|
| 16 |
|
|
|
|
| 27 |
feather.replace();
|
| 28 |
}, 1500);
|
| 29 |
});
|
| 30 |
+
async function generateStarMap() {
|
| 31 |
const containerWidth = starMapContainer.offsetWidth;
|
| 32 |
const containerHeight = starMapContainer.offsetHeight;
|
| 33 |
const mapName = mapNameInput.value || 'Unnamed Star Map';
|
| 34 |
+
const latitude = parseFloat(latitudeInput.value) || 0;
|
| 35 |
+
const longitude = parseFloat(longitudeInput.value) || 0;
|
| 36 |
const starDensity = starDensitySelect.value;
|
| 37 |
const constellationStyle = constellationStyleSelect.value;
|
| 38 |
|
| 39 |
+
// Clear previous content
|
| 40 |
+
starMapContainer.innerHTML = '';
|
| 41 |
+
|
| 42 |
+
// Add loading state
|
| 43 |
+
const loadingText = document.createElement('div');
|
| 44 |
+
loadingText.className = 'absolute inset-0 flex items-center justify-center text-white';
|
| 45 |
+
loadingText.textContent = 'Loading celestial data...';
|
| 46 |
+
starMapContainer.appendChild(loadingText);
|
| 47 |
+
|
| 48 |
+
try {
|
| 49 |
+
// Fetch real star data from NASA's exoplanet archive API
|
| 50 |
+
const response = await fetch(`https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=exoplanets&select=ra,dec&format=json`);
|
| 51 |
+
const stars = await response.json();
|
| 52 |
+
|
| 53 |
+
// Filter stars visible from given coordinates
|
| 54 |
+
const visibleStars = stars.filter(star => {
|
| 55 |
+
// Simple visibility calculation based on celestial coordinates
|
| 56 |
+
const starLat = star.dec;
|
| 57 |
+
const starLng = star.ra;
|
| 58 |
+
return Math.abs(starLat - latitude) < 45 &&
|
| 59 |
+
Math.abs(starLng - longitude) < 45;
|
| 60 |
+
});
|
| 61 |
+
|
| 62 |
+
// Generate stars
|
| 63 |
+
visibleStars.forEach(star => {
|
| 64 |
+
const starElement = document.createElement('div');
|
| 65 |
+
starElement.className = 'star';
|
| 66 |
+
|
| 67 |
+
// Convert celestial coordinates to container coordinates
|
| 68 |
+
const x = ((star.ra - longitude + 180) % 360) / 360 * containerWidth;
|
| 69 |
+
const y = ((star.dec - latitude + 90) % 180) / 180 * containerHeight;
|
| 70 |
+
|
| 71 |
+
// Size based on magnitude (simplified)
|
| 72 |
+
const size = 1 + Math.random() * 3;
|
| 73 |
+
|
| 74 |
+
starElement.style.width = `${size}px`;
|
| 75 |
+
starElement.style.height = `${size}px`;
|
| 76 |
+
starElement.style.left = `${x}px`;
|
| 77 |
+
starElement.style.top = `${y}px`;
|
| 78 |
+
starElement.style.animationDelay = `${Math.random() * 2}s`;
|
| 79 |
+
|
| 80 |
+
starMapContainer.appendChild(starElement);
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
// Remove loading text
|
| 84 |
+
starMapContainer.removeChild(loadingText);
|
| 85 |
+
// Real constellations data
|
| 86 |
const constellations = [
|
| 87 |
{ name: "Orion", stars: [[0.3,0.2],[0.35,0.25],[0.4,0.3],[0.45,0.35],[0.5,0.4]] },
|
| 88 |
{ name: "Ursa Major", stars: [[0.6,0.1],[0.65,0.15],[0.7,0.2],[0.75,0.25],[0.8,0.3]] },
|
|
|
|
| 96 |
case 'high': starCount = 300; break;
|
| 97 |
default: starCount = 150;
|
| 98 |
}
|
| 99 |
+
// Add some random stars for density
|
| 100 |
+
const extraStars = starDensity === 'low' ? 50 : starDensity === 'high' ? 200 : 100;
|
| 101 |
+
for (let i = 0; i < extraStars; i++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
const star = document.createElement('div');
|
| 103 |
+
star.className = 'star';
|
| 104 |
|
| 105 |
+
const left = Math.random() * containerWidth;
|
| 106 |
+
const top = Math.random() * containerHeight;
|
| 107 |
+
const size = Math.random() * 2 + 0.5;
|
| 108 |
|
| 109 |
+
star.style.width = `${size}px`;
|
| 110 |
+
star.style.height = `${size}px`;
|
| 111 |
star.style.left = `${left}px`;
|
| 112 |
star.style.top = `${top}px`;
|
| 113 |
+
star.style.animationDelay = `${Math.random() * 2}s`;
|
| 114 |
|
| 115 |
starMapContainer.appendChild(star);
|
| 116 |
+
}
|
| 117 |
+
// Add constellation lines (simplified)
|
| 118 |
+
if (constellationStyle !== 'minimal') {
|
| 119 |
+
// Draw some lines between nearby stars
|
| 120 |
+
for (let i = 0; i < visibleStars.length; i++) {
|
| 121 |
+
for (let j = i + 1; j < Math.min(i + 5, visibleStars.length); j++) {
|
| 122 |
+
const star1 = visibleStars[i];
|
| 123 |
+
const star2 = visibleStars[j];
|
| 124 |
+
|
| 125 |
+
const x1 = ((star1.ra - longitude + 180) % 360) / 360 * containerWidth;
|
| 126 |
+
const y1 = ((star1.dec - latitude + 90) % 180) / 180 * containerHeight;
|
| 127 |
+
const x2 = ((star2.ra - longitude + 180) % 360) / 360 * containerWidth;
|
| 128 |
+
const y2 = ((star2.dec - latitude + 90) % 180) / 180 * containerHeight;
|
| 129 |
+
|
| 130 |
+
const distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
| 131 |
+
if (distance < 100) { // Only connect nearby stars
|
| 132 |
+
const line = document.createElement('div');
|
| 133 |
+
line.className = 'constellation-line';
|
| 134 |
+
|
| 135 |
+
const length = distance;
|
| 136 |
+
const angle = Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI;
|
| 137 |
+
|
| 138 |
+
line.style.width = `${length}px`;
|
| 139 |
+
line.style.left = `${x1}px`;
|
| 140 |
+
line.style.top = `${y1}px`;
|
| 141 |
+
line.style.transform = `rotate(${angle}deg)`;
|
| 142 |
+
|
| 143 |
+
if (constellationStyle === 'classic') {
|
| 144 |
+
line.style.background = 'rgba(255, 255, 255, 0.5)';
|
| 145 |
+
line.style.height = '2px';
|
| 146 |
+
} else { // modern
|
| 147 |
+
line.style.background = 'linear-gradient(90deg, rgba(99,102,241,0.5) 0%, rgba(16,185,129,0.5) 100%)';
|
| 148 |
+
line.style.height = '1.5px';
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
starMapContainer.appendChild(line);
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
// Draw constellation lines
|
| 157 |
constellations.forEach(constellation => {
|
| 158 |
const stars = constellation.stars;
|
| 159 |
for (let i = 0; i < stars.length - 1; i++) {
|
style.css
CHANGED
|
@@ -14,8 +14,13 @@ body {
|
|
| 14 |
border-radius: 50%;
|
| 15 |
box-shadow: 0 0 5px 1px rgba(255, 255, 255, 0.5);
|
| 16 |
animation: twinkle 3s infinite alternate;
|
|
|
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
.constellation-star {
|
| 20 |
position: absolute;
|
| 21 |
background-color: white;
|
|
|
|
| 14 |
border-radius: 50%;
|
| 15 |
box-shadow: 0 0 5px 1px rgba(255, 255, 255, 0.5);
|
| 16 |
animation: twinkle 3s infinite alternate;
|
| 17 |
+
pointer-events: none;
|
| 18 |
}
|
| 19 |
|
| 20 |
+
#starMapContainer {
|
| 21 |
+
position: relative;
|
| 22 |
+
background: radial-gradient(ellipse at center, #1a202c 0%, #000000 100%);
|
| 23 |
+
}
|
| 24 |
.constellation-star {
|
| 25 |
position: absolute;
|
| 26 |
background-color: white;
|