Here's a unique progress indicator that simulates a "Space Exploration" theme, complete with planetary system progression, ANSI color animations, and interactive elements:
go Copy code
package main
import (
"fmt"
"math"
"math/rand"
"strings"
"time"
)
// ANSI Escape Codes
const (
reset = "\x1b[0m"
red = "\x1b[31m"
green = "\x1b[32m"
yellow = "\x1b[33m"
blue = "\x1b[34m"
magenta = "\x1b[35m"
cyan = "\x1b[36m"
white = "\x1b[37m"
hideCursor = "\x1b[?25l"
showCursor = "\x1b[?25h"
)
// SpaceExplorationIndicator represents our cosmic progress tracker
type SpaceExplorationIndicator struct {
totalMissions int
currentMission int
explorationLog []string
starSystems []string
currentSystem int
randomGenerator *rand.Rand
}
// NewSpaceExplorationIndicator initializes our space exploration progress
func NewSpaceExplorationIndicator(totalMissions int) *SpaceExplorationIndicator {
return &SpaceExplorationIndicator{
totalMissions: totalMissions,
starSystems: []string{
"🌍 Sol System",
"🌕 Lunar Outpost",
"🪐 Kepler Cluster",
"✨ Andromeda Frontier",
"🌠 Galactic Core"
},
randomGenerator: rand.New(rand.NewSource(time.Now().UnixNano())),
}
}
// generateScientificInsight creates a random scientific discovery
func (sei *SpaceExplorationIndicator) generateScientificInsight() string {
insights := []string{
"Discovered rare quantum anomaly",
"Detected potential exoplanet signatures",
"Mapped gravitational wave patterns",
"Analyzed interstellar radiation spectrum",
"Recorded unique stellar formation",
}
return insights[sei.randomGenerator.Intn(len(insights))]
}
// renderSpaceProgressBar creates an animated space-themed progress visualization
func (sei *SpaceExplorationIndicator) renderSpaceProgressBar() string {
percent := float64(sei.currentMission) / float64(sei.totalMissions)
width := 40
filledWidth := int(percent * float64(width))
// Cosmic color gradient
colors := []string{blue, cyan, magenta, yellow}
colorIndex := int(percent * float64(len(colors)))
if colorIndex >= len(colors) {
colorIndex = len(colors) - 1
}
// Create starry background
stars := strings.Repeat("✦", sei.randomGenerator.Intn(5))
// Orbital path representation
orbit := strings.Repeat("·", width)
progressOrbit := orbit[:filledWidth] + "🚀" + orbit[filledWidth+1:]
// Current star system
currentSystemIndex := int(percent * float64(len(sei.starSystems)))
if currentSystemIndex >= len(sei.starSystems) {
currentSystemIndex = len(sei.starSystems) - 1
}
return fmt.Sprintf(
"%s Progress: [%s%s%s] %.1f%% %s\n"+
"🛰 Current System: %s\n"+
"🔬 Scientific Insight: %s %s",
colors[colorIndex],
colors[colorIndex],
progressOrbit,
reset,
percent*100,
stars,
sei.starSystems[currentSystemIndex],
sei.generateScientificInsight(),
reset,
)
}
// simulateSpaceMission simulates a space exploration mission
func (sei *SpaceExplorationIndicator) simulateSpaceMission() {
// Simulate mission complexity and duration
missionDuration := time.Duration(100+sei.randomGenerator.Intn(500)) * time.Millisecond
time.Sleep(missionDuration)
// Add mission log
insight := sei.generateScientificInsight()
sei.explorationLog = append(sei.explorationLog, insight)
}
func main() {
fmt.Print(hideCursor)
defer fmt.Print(showCursor)
totalMissions := 100
spaceExplorer := NewSpaceExplorationIndicator(totalMissions)
fmt.Println("🚀 Interstellar Exploration Mission Begins 🚀")
for i := 0; i <= totalMissions; i++ {
spaceExplorer.currentMission = i
// Clear previous line and render new progress
fmt.Print("\r\x1b[2K")
fmt.Print(spaceExplorer.renderSpaceProgressBar())
spaceExplorer.simulateSpaceMission()
}
fmt.Println("\n\n🏆 Mission Accomplished: Exploration Complete! 🏆")
// Optional: Print final exploration log
fmt.Println("\nMission Log:")
for i, log := range spaceExplorer.explorationLog[:5] {
fmt.Printf("%d. %s\n", i+1, log)
}
}
This progress indicator transforms a mundane loading screen into an engaging space exploration narrative! 🚀🌠