Created
July 20, 2025 03:18
-
-
Save EncodeTheCode/3954de51fbff30efa64447edbf387a78 to your computer and use it in GitHub Desktop.
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
import glfw | |
from OpenGL.GL import * | |
import time | |
# Configuration | |
INITIAL_WINDOW_WIDTH = 800 | |
INITIAL_WINDOW_HEIGHT = 600 | |
CROSSHAIR_COLOR = (0.2, 1.0, 0.2, 1.0) # Syphon Filter green RGBA | |
# Ghost settings | |
GHOST_LIFETIME = 0.5 # seconds before a ghost fully fades | |
GHOST_SPAWN_INTERVAL = 0.1 # seconds between ghost spawns | |
MAX_GHOSTS = 50 # cap total ghosts in list | |
MAX_GHOST_DISTANCE = 150 # pixels: only draw ghosts within this distance | |
# Crosshair geometry (all in pixels) | |
CENTER_HALF = 5 # half-length of central crosshair | |
BOX_GAP = 8 # gap between center cross and box | |
BOX_EXT_X = 30 # horizontal half-size of outer box | |
BOX_EXT_Y = 15 # vertical half-size of outer box (reduced height) | |
SIDE_TICK_LENGTH = 10 # length of horizontal ticks on box sides | |
CONNECTOR_LENGTH = 10 # length of vertical connectors at top/bottom | |
LINE_THICKNESS = 2 | |
# Dynamic state | |
mouse_x = INITIAL_WINDOW_WIDTH / 2 | |
mouse_y = INITIAL_WINDOW_HEIGHT / 2 | |
ghosts = [] # list of (x, y, timestamp) | |
window_width = INITIAL_WINDOW_WIDTH | |
window_height = INITIAL_WINDOW_HEIGHT | |
last_spawn_time = 0.0 | |
def mouse_move_callback(window, xpos, ypos): | |
global mouse_x, mouse_y | |
mouse_x = xpos | |
mouse_y = window_height - ypos | |
def window_size_callback(window, width, height): | |
global window_width, window_height | |
window_width, window_height = width, height | |
glViewport(0, 0, width, height) | |
glMatrixMode(GL_PROJECTION) | |
glLoadIdentity() | |
glOrtho(0, width, 0, height, -1, 1) | |
glMatrixMode(GL_MODELVIEW) | |
glLoadIdentity() | |
def init_window(): | |
if not glfw.init(): | |
raise Exception("glfw cannot be initialized!") | |
glfw.window_hint(glfw.RESIZABLE, glfw.TRUE) | |
window = glfw.create_window( | |
INITIAL_WINDOW_WIDTH, | |
INITIAL_WINDOW_HEIGHT, | |
"Crosshair Ghost Trails", | |
None, None | |
) | |
if not window: | |
glfw.terminate() | |
raise Exception("glfw window cannot be created!") | |
glfw.make_context_current(window) | |
glfw.set_cursor_pos_callback(window, mouse_move_callback) | |
glfw.set_window_size_callback(window, window_size_callback) | |
fb_w, fb_h = glfw.get_framebuffer_size(window) | |
window_size_callback(window, fb_w, fb_h) | |
glEnable(GL_BLEND) | |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) | |
return window | |
def draw_crosshair(x, y, color): | |
"""Draws an enhanced Syphon Filter style box crosshair centered at (x,y).""" | |
r, g, b, a = color | |
glColor4f(r, g, b, a) | |
glLineWidth(LINE_THICKNESS) | |
# Precompute extents | |
half_c = CENTER_HALF | |
gap = BOX_GAP | |
bx = BOX_EXT_X | |
by = BOX_EXT_Y | |
# Central crosshair | |
glBegin(GL_LINES) | |
glVertex2f(x - half_c, y) | |
glVertex2f(x + half_c, y) | |
glVertex2f(x, y - half_c) | |
glVertex2f(x, y + half_c) | |
glEnd() | |
# Outer box (rectangle) | |
glBegin(GL_LINE_LOOP) | |
glVertex2f(x - bx - gap, y - (by // 2) - gap) | |
glVertex2f(x - bx - gap, y + (by // 2) + gap) | |
glVertex2f(x + bx + gap, y + (by // 2) + gap) | |
glVertex2f(x + bx + gap, y - (by // 2) - gap) | |
glEnd() | |
# Side ticks (horizontal lines) outside box sides | |
glBegin(GL_LINES) | |
# left side tick | |
lx = x - bx - gap | |
glVertex2f(lx - SIDE_TICK_LENGTH/2, y) | |
glVertex2f(lx + SIDE_TICK_LENGTH/2, y) | |
# right side tick | |
rx = x + bx + gap | |
glVertex2f(rx - SIDE_TICK_LENGTH/2, y) | |
glVertex2f(rx + SIDE_TICK_LENGTH/2, y) | |
glEnd() | |
# Connectors (vertical lines at top center/bottom center) | |
glBegin(GL_LINES) | |
# top connector (vertical) | |
glVertex2f(x, y + by + gap) | |
glVertex2f(x, (y - 35) + (by + 0) + (gap + 40) + (CONNECTOR_LENGTH * 2)) | |
# bottom connector | |
glVertex2f(x, y - by - gap) | |
glVertex2f(x, (y - 105) - (by - 115) - (gap - gap * 2) - CONNECTOR_LENGTH) | |
glEnd() | |
def main(): | |
global last_spawn_time | |
window = init_window() | |
while not glfw.window_should_close(window): | |
glClear(GL_COLOR_BUFFER_BIT) | |
now = time.time() | |
# Spawn new ghost at controlled intervals | |
if now - last_spawn_time >= GHOST_SPAWN_INTERVAL: | |
ghosts.append((mouse_x, mouse_y, now)) | |
last_spawn_time = now | |
if len(ghosts) > MAX_GHOSTS: | |
ghosts.pop(0) | |
# Draw and prune ghosts | |
alive = [] | |
max_dist_sq = MAX_GHOST_DISTANCE * MAX_GHOST_DISTANCE | |
for gx, gy, ts in ghosts: | |
age = now - ts | |
if age < GHOST_LIFETIME: | |
dx = gx - mouse_x | |
dy = gy - mouse_y | |
if dx*dx + dy*dy <= max_dist_sq: | |
alpha = (1.0 - age / GHOST_LIFETIME) * CROSSHAIR_COLOR[3] | |
draw_crosshair(gx, gy, | |
(CROSSHAIR_COLOR[0], | |
CROSSHAIR_COLOR[1], | |
CROSSHAIR_COLOR[2], | |
alpha)) | |
alive.append((gx, gy, ts)) | |
ghosts[:] = alive | |
# Draw live crosshair on top | |
draw_crosshair(mouse_x, mouse_y, CROSSHAIR_COLOR) | |
glfw.swap_buffers(window) | |
glfw.poll_events() | |
glfw.terminate() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment