func main() { z := zalgo.NewCorrupter(os.Stdout) z.Zalgo = func(n int, r rune, z *zalgo.Corrupter) bool { z.Up += 0.1 z.Middle += complex(0.01, 0.01) z.Down += complex(real(z.Down)*0.1, 0) return false } z.Up = complex(0, 0.2) z.Middle = complex(0, 0.2) z.Down = complex(0.001, 0.3) rd := bufio.NewReader(os.Stdin) for { line, _, err := rd.ReadLine() if err != nil { break } fmt.Fprintln(z, string(line)) } }
// NewZalgoFormatterrrrrr gives you a new Zalgo formatterrrrrr...! func NewZalgoFormatterrrrrr() *ZalgoFormatter { pain := bytes.NewBuffer(nil) z := zalgo.NewCorrupter(pain) z.Zalgo = func(n int, z *zalgo.Corrupter) { z.Up += 0.1 z.Middle += complex(0.01, 0.01) z.Down += complex(real(z.Down)*0.1, 0) } return &ZalgoFormatter{ victim: &logrus.TextFormatter{}, pain: pain, z: z, } }
func Example_1() { z := zalgo.NewCorrupter(os.Stdout) z.Zalgo = func(n int, r rune, z *zalgo.Corrupter) bool { z.Up += 0.1 z.Middle += complex(0.01, 0.01) z.Down += complex(real(z.Down)*0.1, 0) return false } z.Up = complex(0, 0.2) z.Middle = complex(0, 0.2) z.Down = complex(0.001, 0.3) fmt.Fprintln(z, invoke) // Output: // Eternal happiness. }
// Draw returns a string representing a millipede and an error if any func (m *Millipede) Draw() (string, error) { // --skin support skin, err := Skins.GetByName(m.Skin) if err != nil { return "", err } // --reverse support if m.Reverse { err = skin.SetDirection(DirectionDown) if err != nil { return "", err } } // --width support err = skin.SetWidth(int(m.Width)) if err != nil { return "", err } // build the millipede body var body []string body = []string{m.getPadding(0) + skin.GetHead()} for x := uint64(0); x < m.Size; x++ { body = append(body, m.getPadding(x)+skin.NextPede()) } tail := skin.GetTail() if tail != "" { body = append(body, m.getPadding(m.Size-1)+tail) } // --reverse support if m.Reverse { for i, j := 0, len(body)-1; i < j; i, j = i+1, j-1 { body[i], body[j] = body[j], body[i] } } // --center support if m.Center { w, _, err := terminal.GetSize(0) if err == nil { var maxWidth int for _, line := range body { if len(line) > maxWidth { maxWidth = utf8.RuneCount([]byte(line)) } } if maxWidth < w { leftMarginSize := (w / 2) - (maxWidth / 2) margin := strings.Repeat(" ", leftMarginSize) for idx, line := range body { body[idx] = margin + line } } } } // --chameleon and --rainbow support for idx, line := range body { colors := []string{"red", "green", "yellow", "blue", "magenta", "cyan", "white"} fgColor := "" bgColor := "" // --chameleon support if m.Chameleon { fgColor = "black" } // --rainbow if m.Rainbow { bgColor = colors[idx%len(colors)] if m.Chameleon { fgColor = bgColor fgColor = "black" } } if fgColor != "" || bgColor != "" { paddingSize := len(line) - len(strings.TrimSpace(line)) line = strings.Repeat(" ", paddingSize) + ansi.Color(line[paddingSize:], fgColor+":"+bgColor) } if m.PadRight { line = line + strings.Repeat(" ", int(m.Curve)) } body[idx] = line } output := strings.Join(body, "\n") // --zalgo support if m.Zalgo { buf := new(bytes.Buffer) z := zalgo.NewCorrupter(buf) z.Zalgo = func(n int, r rune, z *zalgo.Corrupter) bool { if string(r) == " " || r == 10 { z.Up = 0 z.Middle = 0 z.Down = 0 } else { if z.Up == 0 { z.Up = complex(0, 0.2) z.Middle = complex(0, 0.2) z.Down = complex(0.001, 0.3) } z.Up += 0.1 z.Middle += complex(0.1, 0.2) z.Down += 0.1 } return false } fmt.Fprintln(z, output) output = buf.String() } return output, nil }