Iterate on pixel buffer in telnet package

This commit is contained in:
Alexandre Iooss 2020-10-14 22:07:24 +02:00
parent d26562d43d
commit e63d4bf170
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
1 changed files with 8 additions and 5 deletions

View File

@ -158,12 +158,15 @@ func StartASCIIArtStream(streamID string, reader io.ReadCloser) {
}
// Convert image to ASCII
for j := 0; j < Cfg.Height; j++ {
for i := 0; i < Cfg.Width; i++ {
textBuff.WriteByte(asciiChars[pixelBuff[Cfg.Width*j+i]/22])
textBuff.WriteByte(asciiChars[pixelBuff[Cfg.Width*j+i]/22])
for i, pixel := range pixelBuff {
if i%Cfg.Width == 0 {
// New line
textBuff.WriteByte('\n')
}
textBuff.WriteByte('\n')
// Print two times the character to make a square
textBuff.WriteByte(asciiChars[pixel/22])
textBuff.WriteByte(asciiChars[pixel/22])
}
*(currentMessage[streamID]) = textBuff.String()