Created
March 11, 2026 05:06
-
-
Save willmcgugan/825d7cebeb82c7d29cfc2edefb946f7c to your computer and use it in GitHub Desktop.
Cursor Logo in the terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """Display the Cursor logo using braille characters with color.""" | |
| def fill_polygon(pixels, polygon): | |
| """Scanline-fill a polygon into a pixel grid.""" | |
| height, width = len(pixels), len(pixels[0]) | |
| n = len(polygon) | |
| y_lo = max(0, int(min(p[1] for p in polygon))) | |
| y_hi = min(height - 1, int(max(p[1] for p in polygon))) | |
| for y in range(y_lo, y_hi + 1): | |
| xs = [] | |
| for i in range(n): | |
| j = (i + 1) % n | |
| ay, by = polygon[i][1], polygon[j][1] | |
| if ay == by: | |
| continue | |
| if y < min(ay, by) or y >= max(ay, by): | |
| continue | |
| ax, bx = polygon[i][0], polygon[j][0] | |
| xs.append(ax + (y - ay) / (by - ay) * (bx - ax)) | |
| xs.sort() | |
| for k in range(0, len(xs) - 1, 2): | |
| x0 = max(0, int(xs[k] + 0.5)) | |
| x1 = min(width - 1, int(xs[k + 1] + 0.5)) | |
| for x in range(x0, x1 + 1): | |
| pixels[y][x] = 1 | |
| def to_braille(pixels): | |
| """Convert pixel grid to rows of braille characters.""" | |
| h, w = len(pixels), len(pixels[0]) | |
| DOTS = [[0x01, 0x08], [0x02, 0x10], [0x04, 0x20], [0x40, 0x80]] | |
| rows = [] | |
| for by in range(0, h, 4): | |
| row = [] | |
| for bx in range(0, w, 2): | |
| v = 0 | |
| for dy in range(4): | |
| for dx in range(2): | |
| if by + dy < h and bx + dx < w and pixels[by + dy][bx + dx]: | |
| v |= DOTS[dy][dx] | |
| row.append(chr(0x2800 + v)) | |
| rows.append(row) | |
| return rows | |
| def gradient_color(t, stops): | |
| """Get interpolated color at position t (0..1) along gradient stops.""" | |
| t = max(0.0, min(1.0, t)) | |
| seg = len(stops) - 1 | |
| i = min(int(t * seg), seg - 1) | |
| f = t * seg - i | |
| return tuple( | |
| int(stops[i][c] + f * (stops[i + 1][c] - stops[i][c])) for c in range(3) | |
| ) | |
| def main(): | |
| W, H = 66, 112 | |
| px = [[0] * W for _ in range(H)] | |
| # Classic pointer arrow — vertices based on the macOS cursor, scaled 5× | |
| cursor = [ | |
| (5, 5), | |
| (5, 95), | |
| (25, 75), | |
| (40, 105), | |
| (55, 100), | |
| (40, 70), | |
| (60, 70), | |
| ] | |
| fill_polygon(px, cursor) | |
| rows = to_braille(px) | |
| stops = [ | |
| (0, 225, 255), | |
| (70, 140, 255), | |
| (150, 80, 245), | |
| (210, 50, 215), | |
| ] | |
| nr = len(rows) | |
| nc = max(len(r) for r in rows) | |
| EMPTY = chr(0x2800) | |
| RST = "\033[0m" | |
| print() | |
| for ri, row in enumerate(rows): | |
| parts = [] | |
| any_fill = False | |
| for ci, ch in enumerate(row): | |
| if ch == EMPTY: | |
| parts.append(" ") | |
| else: | |
| any_fill = True | |
| t = 0.65 * ri / max(1, nr - 1) + 0.35 * ci / max(1, nc - 1) | |
| r, g, b = gradient_color(t, stops) | |
| parts.append(f"\033[38;2;{r};{g};{b}m{ch}") | |
| if any_fill: | |
| print(" " + "".join(parts).rstrip() + RST) | |
| r, g, b = gradient_color(0.35, stops) | |
| print(f"\n \033[1m\033[38;2;{r};{g};{b}mC U R S O R{RST}\n") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment