package main import ( "math/rand" "time" rl "github.com/gen2brain/raylib-go/raylib" ) type Particle struct { Pos rl.Vector2 Vel rl.Vector2 Size float32 } var particles []Particle var topColor = rl.Color{R: 0x20, G: 0x0F, B: 0x3C, A: 0xFF} // #200F3C top var bottomColor = rl.Color{R: 0x3B, G: 0x0B, B: 0x42, A: 0xFF} // #3B0B42 bottom var particleColor = rl.Color{R: 0xD4, G: 0xB0, B: 0xB5, A: 0x80} // D4B0B5 with some transparency var rng = rand.New(rand.NewSource(time.Now().UnixNano())) // Local RNG func InitBackground(width, height int) { particles = make([]Particle, 100) for i := range particles { particles[i].Pos = rl.Vector2{X: float32(rng.Intn(width)), Y: float32(rng.Intn(height))} particles[i].Vel = rl.Vector2{X: (rng.Float32() - 0.5) * 0.2, Y: (rng.Float32() - 0.5) * 0.2} particles[i].Size = rng.Float32()*1.5 + 0.5 // Particles size ~0.5-2.0 } } func UpdateBackground(screenWidth, screenHeight int) { deltaTime := rl.GetFrameTime() // Time in seconds since the last frame for i := range particles { particles[i].Pos.X += particles[i].Vel.X * deltaTime * 60 // Adjust for frame rate particles[i].Pos.Y += particles[i].Vel.Y * deltaTime * 60 // Wrap around screen if particles[i].Pos.X < 0 { particles[i].Pos.X += float32(screenWidth) } else if particles[i].Pos.X > float32(screenWidth) { particles[i].Pos.X -= float32(screenWidth) } if particles[i].Pos.Y < 0 { particles[i].Pos.Y += float32(screenHeight) } else if particles[i].Pos.Y > float32(screenHeight) { particles[i].Pos.Y -= float32(screenHeight) } } } func DrawBackground(screenWidth, screenHeight int) { // Draw vertical gradient rl.DrawRectangleGradientV(0, 0, int32(screenWidth), int32(screenHeight), topColor, bottomColor) // Draw particles for _, p := range particles { rl.DrawCircleV(p.Pos, p.Size, particleColor) } }