推荐使用Golangd编辑
gitee上放了成品展示可自行下载观看
不废话直接上代码
package main
import (
"flag"
"fmt"
"math"
"strings"
"time"
)
func main() {
var head string
var tail string
var MYWORD string
var sep string
var zoom float64
flag.StringVar(&head, "head", "There are some words I want to tell you:", "A sentence printed on the head") // 添加开头要写的话
flag.StringVar(&tail, "tail", "\t\t\t\t--- Resss Productions", "A sentence printed on the tail") // 添加结尾要写的话
flag.StringVar(&MYWORD, "words", "Dear, I love you forever!", "The words you want to say") // 爱心中的内容
flag.StringVar(&sep, "sep", " ", "The separator")
flag.Float64Var(&zoom, "zoom", 1.0, "Zoom setting")
flag.Parse()
chars := strings.Split(MYWORD, sep)
time.Sleep(time.Duration(1) * time.Second)
fmt.Println(head)
fmt.Println()
time.Sleep(time.Duration(1) * time.Second)
for _, char := range chars {
allChar := make([]string, 0)
for y := 12 * zoom; y > -12*zoom; y-- {
lst := make([]string, 0)
lstCon := ""
for x := -30 * zoom; x < 30*zoom; x++ {
x2 := float64(x)
y2 := float64(y)
formula := math.Pow(math.Pow(x2*0.04/zoom, 2)+math.Pow(y2*0.1/zoom, 2)-1, 3) - math.Pow(x2*0.04/zoom, 2)*math.Pow(y2*0.1/zoom, 3)
if formula <= 0 {
index := int(x) % len(char)
if index >= 0 {
lstCon += string(char[index])
} else {
lstCon += string(char[int(float64(len(char))-math.Abs(float64(index)))])
}
} else {
lstCon += " "
}
}
lst = append(lst, lstCon)
allChar = append(allChar, lst...)
}
for _, text := range allChar {
fmt.Printf("%s\n", text)
time.Sleep(time.Duration(200) * time.Millisecond) // 每个字符生成的时间为0.2秒
}
}
time.Sleep(time.Duration(1) * time.Second)
fmt.Println("\t\t\t\t", tail)
}