From e63d4bf1708291d03890ea9e417f65fd6808a36f Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Wed, 14 Oct 2020 22:07:24 +0200 Subject: [PATCH] Iterate on pixel buffer in telnet package --- stream/telnet/telnet.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stream/telnet/telnet.go b/stream/telnet/telnet.go index 89ebfcc..b2ba9d6 100644 --- a/stream/telnet/telnet.go +++ b/stream/telnet/telnet.go @@ -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()