Created
July 20, 2022 21:19
-
-
Save bashbunni/d5b8feb3e35d9cc47ef87eeb414c3b29 to your computer and use it in GitHub Desktop.
Gradiant Background Text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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