Skip to content

Instantly share code, notes, and snippets.

@AmirMahdyJebreily
Last active October 4, 2025 12:19
Show Gist options
  • Select an option

  • Save AmirMahdyJebreily/f8995f2d5e84f0db425de44de907c9cd to your computer and use it in GitHub Desktop.

Select an option

Save AmirMahdyJebreily/f8995f2d5e84f0db425de44de907c9cd to your computer and use it in GitHub Desktop.
braille_animation_loding.go
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
int main() {
const uint16_t base = 0x2800;
const long delay_ns = 75 * 1000000L;
const char *clear = "\r\x1b[2K";
const uint8_t patterns[8] = {
0b110100,
0b100110,
0b100111,
0b000111,
0b001011,
0b011001,
0b111001,
0b111000
};
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = delay_ns;
uint8_t i = 0;
while(1) {
printf("%s", clear);
uint16_t codepoint = base + patterns[i];
if(codepoint <= 0x7F) {
putchar(codepoint);
} else if(codepoint <= 0x7FF) {
putchar(0xC0 | (codepoint >> 6));
putchar(0x80 | (codepoint & 0x3F));
} else {
putchar(0xE0 | (codepoint >> 12));
putchar(0x80 | ((codepoint >> 6) & 0x3F));
putchar(0x80 | (codepoint & 0x3F));
}
fflush(stdout);
nanosleep(&ts, NULL);
i = (i + 1) & 7;
}
return 0;
}
package main
import (
"os"
"syscall"
)
const (
base uint16 = 0x2800
delayMs = 75
clear = "\r\x1b[2K"
)
func nanosleep(ms int64) {
tv := syscall.NsecToTimeval(ms * 1_000_000)
syscall.Select(0, nil, nil, nil, &tv)
}
func main() {
patterns := [8]byte{
0b110100,
0b100110,
0b100111,
0b000111,
0b001011,
0b011001,
0b111001,
0b111000,
}
for i := uint8(0); ; i = (i + 1) & 7 {
os.Stdout.WriteString(clear)
os.Stdout.WriteString(string(rune(base + uint16(patterns[i]))))
nanosleep(delayMs)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment