Skip to content

Instantly share code, notes, and snippets.

@bashbunni
Created July 20, 2022 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bashbunni/d5b8feb3e35d9cc47ef87eeb414c3b29 to your computer and use it in GitHub Desktop.
Save bashbunni/d5b8feb3e35d9cc47ef87eeb414c3b29 to your computer and use it in GitHub Desktop.
Gradiant Background Text
package main
import (
"fmt"
"image/color"
"github.com/charmbracelet/lipgloss"
"github.com/lucasb-eyer/go-colorful"
"github.com/muesli/gamut"
)
const historyA = "The Romans learned from the Greeks that quinces slowly cooked with honey would “set” when cool. The Apicius gives a recipe for preserving whole quinces, stems and leaves attached, in a bath of honey diluted with defrutum: Roman marmalade. Preserves of quince and lemon appear (along with rose, apple, plum and pear) in the Book of ceremonies of the Byzantine Emperor Constantine VII Porphyrogennetos."
func main() {
colors := gamut.Tints(lipgloss.Color("#7D56F4"), len(historyA))
fmt.Print(gradientBox(colors, historyA))
}
func gradientBox(colors []color.Color, words string) string {
boxStyle := lipgloss.NewStyle().
Align(lipgloss.Left).
Foreground(lipgloss.Color("#FAFAFA"))
var output string
for i, char := range words {
color, _ := colorful.MakeColor(colors[i%len(colors)])
output += boxStyle.Copy().Background(lipgloss.Color(color.Hex())).Render(string(char))
}
return output + "\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment