|
Python |
Open ghost display
My take on OpenGhost—an open-source Pepper's Ghost holographic display originally designed by Xander Chin. Powered by a Raspberry Pi 5 and a beam splitter cube, it projects crisp, floating visuals. I'm currently building out custom software for it, including a clock, a desk companion, and more features to come!
Right now making a custom desk companion with it's own reactions and animations
import pygame, math, random, datetime, sys
W, H, FPS = 600, 600, 60
pygame.init()
scr = pygame.display.set_mode((W, H))
pygame.display.set_caption("OpenGhost OS")
clk = pygame.time.Clock()
f_f = pygame.font.SysFont("consolas", 24, bold=True)
f_c = pygame.font.SysFont("consolas", 18, bold=True)
f_s = pygame.font.SysFont("consolas", 20, bold=True)
def nth(seq, idx):
for i, x in enumerate(seq):
if i == idx: return x
ch, mir, t = 1, False, 0.0
MODS = {}
fish = (
{"x":200.0,"y":135.0,"d":-1,"l":"<*(((()><","r":"><(((()*>","c":(40,190,255),"s":1.3,"p":0.0,"b":60},
{"x":400.0,"y":195.0,"d":-1,"l":"<º)))><","r":"><(((º>","c":(60,255,110),"s":1.6,"p":1.5,"b":90},
{"x":300.0,"y":265.0,"d":1,"l":"<º)))><","r":"><(((º>","c":(0,225,255),"s":1.4,"p":3.0,"b":120}
)
crab, bubs, food = {"x":300.0,"d":1,"s":0.85}, list(), list()
kelp = ((125,155,.2,12,.032),(162,215,1.4,15,.028),(178,130,2.5,10,.035),(255,145,.8,11,.03),(288,195,2.1,14,.029),(355,135,3.2,10,.034),(420,190,1.1,14,.028),(442,225,2.4,16,.026))
def ch1(act, pos):
global bubs, food
if act == "go":
food += list({"x":nth(pos,0)+random.uniform(-22,22),"y":nth(pos,1),"vy":random.uniform(.65,1.1),"p":random.uniform(0,6.28)} for _ in range(5))
return
if act != "draw": return
for bx,h,ph,amp,fr in kelp:
pv = None
for dy in range(0,h+1,6):
px, py = int(bx+math.sin(t+t+ph-dy*fr)*(amp*(dy/h))), H-dy
if pv: pygame.draw.line(scr,(15,110,40),pv,(px,py),5); pygame.draw.line(scr,(45,235,95),pv,(px,py),3)
if dy>15 and (dy//6)%4==0: pygame.draw.circle(scr,(45,235,95),(px+(-7 if (dy//6)%8==0 else 7),py),2)
pv = (px,py)
if pv: pygame.draw.circle(scr,(110,255,140),pv,3)
cx = crab.get("x") + crab.get("s")*crab.get("d")
crab.update({"x":W-65 if cx>W-65 else (65 if cx<65 else cx),"d":-1 if cx>W-65 else (1 if cx<65 else crab.get("d"))})
scr.blit(f_c.render("'' ''",True,(255,80,95)),f_c.render("'' ''",True,(255,80,95)).get_rect(midbottom=(int(crab.get("x")),H+4)))
scr.blit(f_c.render("v(••)v",True,(255,80,95)),f_c.render("v(••)v",True,(255,80,95)).get_rect(midbottom=(int(crab.get("x")),H-13)))
bubs = list(b for b in bubs if b.get("y")>12)
for b in bubs:
b.update({"x":b.get("x")+math.sin(t*3.5+b.get("p"))*.65,"y":b.get("y")-b.get("s")})
scr.blit(f_c.render(b.get("c"),True,(160,240,255)),(int(b.get("x")),int(b.get("y"))))
food = list(f for f in food if f.get("y")<H-15)
for f in food:
f.update({"x":f.get("x")+math.sin(t*4+f.get("p"))*.45,"y":f.get("y")+f.get("vy")})
pygame.draw.circle(scr,(255,240,130),(int(f.get("x")),int(f.get("y"))),2)
for f in fish:
fx,fy,d,bt = f.get("x"),f.get("y"),f.get("d"),f.get("b")-1
hw = f_f.render(f.get("r") if d==1 else f.get("l"),True,f.get("c")).get_width()//2
nf = min(food,key=lambda fl:math.hypot(fl.get("x")-fx,fl.get("y")-fy),default=None)
if nf and math.hypot(nf.get("x")-fx,nf.get("y")-fy)<240:
dx,dy = nf.get("x")-fx,nf.get("y")-fy; ds = math.hypot(dx,dy)+.01; fx+=(dx/ds)*f.get("s"); fy+=(dy/ds)*f.get("s"); d = 1 if dx>=0 else -1
if ds<22 and nf in food: food.remove(nf); bubs.append({"x":fx+(hw-2)*d,"y":fy-4,"s":1.4,"c":"o","p":random.uniform(0,6.28)})
else: fx+=f.get("s")*d; fy+=math.sin(t*2.2+f.get("p"))*.45
if fx>=W-85: fx,d = W-85,-1
elif fx<=85: fx,d = 85,1
if bt<=0: bubs.append({"x":fx+(hw-2)*d,"y":fy-4,"s":random.uniform(.9,1.5),"c":random.choice(("o",".","°")),"p":random.uniform(0,6.28)}); bt=random.randint(90,220)
f.update({"x":fx,"y":fy,"d":d,"b":bt}); lbl=f_f.render(f.get("r") if d==1 else f.get("l"),True,f.get("c")); scr.blit(lbl,lbl.get_rect(center=(int(fx),int(fy))))
MODS.update({1: ch1})
b_mod, b_slp, b_smsg, b_ex, b_ey, b_tx, b_ty, b_idl, b_hap, b_msg, b_emo = 0, True, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, 90, 0
def _sb_eye(surf, cx, cy, side, px_o, py_o, emo, blink, asleep):
if asleep or blink:
pygame.draw.arc(surf, (248, 250, 255), (cx - 48, cy - 8, 96, 44), 3.3, 6.1, 10)
return
if emo == 2:
pygame.draw.arc(surf, (248, 250, 255), (cx - 50, cy - 36, 100, 88), 0.15, 2.99, 14)
return
pygame.draw.ellipse(surf, (250, 252, 255), (cx - 64, cy - 78, 128, 156))
if emo == 3:
hx, hy = cx + int(px_o * 0.4), cy + int(py_o * 0.4)
pygame.draw.circle(surf, (255, 45, 95), (hx - 13, hy - 8), 15)
pygame.draw.circle(surf, (255, 45, 95), (hx + 13, hy - 8), 15)
pygame.draw.polygon(surf, (255, 45, 95), ((hx - 27, hy - 3), (hx + 27, hy - 3), (hx, hy + 28)))
return
px = cx + int(max(-26, min(26, px_o)))
py = cy + int(max(-34, min(34, py_o)))
p_col = (255, 52, 24) if side < 0 else (236, 42, 218)
pygame.draw.circle(surf, p_col, (px, py), 31)
if emo == 1:
lid = ((cx - 72, cy - 68), (cx + 72, cy - 22), (cx + 72, cy - 90), (cx - 72, cy - 90)) if side < 0 else ((cx - 72, cy - 22), (cx + 72, cy - 68), (cx + 72, cy - 90), (cx - 72, cy - 90))
pygame.draw.polygon(surf, (0, 0, 0), lid)
def ch2(act, pos):
global b_mod, b_slp, b_smsg, b_ex, b_ey, b_tx, b_ty, b_idl, b_hap, b_msg, b_emo
if act == "go":
if nth(pos, 1) == 40: b_mod = (b_mod + 1) % 2; b_idl = 0; b_hap = 0; b_msg = 90; b_emo = 0
else: b_hap = 85; b_idl = 0; b_emo = 3 if b_emo != 3 else 2
return
if act == "z": b_slp = not b_slp; b_smsg = 90; b_idl = 0; return
if act == "move": b_tx, b_ty, b_idl = (nth(pos,0) - W//2) * 0.16, (nth(pos,1) - H//2) * 0.16, 0; return
b_idl += 1; b_hap = max(0, b_hap - 1); asleep = b_slp and (b_idl > 420)
if b_hap == 0 and not asleep:
if b_idl > 90 and int(t * 30) % (55 if b_mod == 1 else 85) == 0:
b_tx, b_ty = random.uniform(-44, 44), random.uniform(-28, 28)
b_emo = random.choice((0, 0, 0, 1, 2))
lerp = 0.20 if b_mod == 1 else 0.12
b_ex += (b_tx - b_ex) * lerp; b_ey += (b_ty - b_ey) * lerp
cx = int(W // 2 + b_ex * 0.55)
cy = int(H // 2 - 4 + b_ey * 0.55 + math.sin(t * (3.4 if b_mod == 1 else 2.4)) * 6)
blink = (int(t * 25) % (85 if b_mod == 1 else 105) < 3)
if b_mod == 0:
ec, eg = (0, 232, 255), (0, 68, 105)
for side in (-122, 122):
ex = cx + side
if asleep: pygame.draw.rect(scr, ec, (ex - 56, cy - 6, 112, 14), border_radius=7)
elif blink: pygame.draw.rect(scr, ec, (ex - 58, cy - 4, 116, 10), border_radius=5)
elif b_hap > 0: pygame.draw.arc(scr, ec, (ex - 56, cy - 36, 112, 84), 0.15, 2.99, 14)
else:
pygame.draw.rect(scr, eg, (ex - 64, cy - 72, 128, 144), border_radius=38)
pygame.draw.rect(scr, ec, (ex - 58, cy - 66, 116, 132), border_radius=34)
pygame.draw.circle(scr, (255, 255, 255), (ex - 22, cy - 32), 12)
pygame.draw.circle(scr, (210, 250, 255), (ex + 18, cy + 24), 6)
else:
for side in (-65, 65):
_sb_eye(scr, cx + side, cy, side, b_ex * 0.65, b_ey * 0.85, b_emo, blink, asleep)
if asleep:
zz = int((t * 24) % 52); scr.blit(f_s.render("Zzz", True, (0, 175, 205) if b_mod == 0 else (236, 82, 218)), (cx + 145, cy - 105 - zz))
if b_msg > 0:
b_msg -= 1; scr.blit(f_c.render("[ " + ("EMO" if b_mod == 0 else "STARBOY") + " ]", True, (0, 210, 235) if b_mod == 0 else (236, 82, 218)), (20, 20))
if b_smsg > 0:
b_smsg -= 1; scr.blit(f_c.render("SLAAP [Z]: " + ("AAN" if b_slp else "UIT"), True, (0, 190, 210)), (20, 44))
MODS.update({2: ch2})
clk_c, clk_bl = 0, True
CLK_C = (((255, 26, 26), (195, 10, 10), (42, 4, 4)), ((0, 235, 255), (0, 165, 195), (4, 36, 44)), ((55, 255, 95), (25, 185, 55), (6, 40, 14)), ((248, 250, 255), (190, 198, 210), (34, 38, 44)))
SEG_M = ("1111110", "0110000", "1101101", "1111001", "0110011", "1011011", "1011111", "1110000", "1111111", "1111011")
def _seg_dig(surf, x, y, w, h, d, c_top, c_bot, c_off):
tk, hm, g = 21, y + h // 2, 2
y2 = y + h
s0 = ((x+g,y),(x+w-g,y),(x+w-tk-g,y+tk),(x+tk+g,y+tk))
s1 = ((x+w,y+g),(x+w,hm-g),(x+w-tk//2,hm+tk//2-g),(x+w-tk,hm-tk//2-g),(x+w-tk,y+tk+g))
s2 = ((x+w,hm+g),(x+w,y2-g),(x+w-tk,y2-tk-g),(x+w-tk,hm+tk//2+g),(x+w-tk//2,hm-tk//2+g))
s3 = ((x+tk+g,y2-tk),(x+w-tk-g,y2-tk),(x+w-g,y2),(x+g,y2))
s4 = ((x,hm+g),(x+tk//2,hm-tk//2+g),(x+tk,hm+tk//2+g),(x+tk,y2-tk-g),(x,y2-g))
s5 = ((x,y+g),(x+tk,y+tk+g),(x+tk,hm-tk//2-g),(x+tk//2,hm+tk//2-g),(x,hm-g))
s6 = ((x+tk//2+g,hm),(x+tk+g,hm-tk//2),(x+w-tk-g,hm-tk//2),(x+w-tk//2-g,hm),(x+w-tk-g,hm+tk//2),(x+tk+g,hm+tk//2))
segs = (s0, s1, s2, s3, s4, s5, s6)
mask = nth(SEG_M, d)
for i in range(7):
pts = nth(segs, i)
if nth(mask, i) == "1":
pygame.draw.polygon(surf, c_top, pts)
pygame.draw.polygon(surf, c_bot, pts, 3)
else:
pygame.draw.polygon(surf, c_off, pts)
def ch3(act, pos):
global clk_c, clk_bl
if act == "go": clk_c = (clk_c + 1) % 4; return
if act == "z": clk_bl = not clk_bl; return
if act != "draw": return
now = datetime.datetime.now(); hm_str = now.strftime("%H%M"); c_top, c_bot, c_off = nth(CLK_C, clk_c)
xs = (28, 158, 336, 466)
for idx in range(4): _seg_dig(scr, nth(xs, idx), 196, 106, 208, int(nth(hm_str, idx)), c_top, c_bot, c_off)
dot_on = (not clk_bl) or (now.microsecond < 500000)
for dy in (254, 346): pygame.draw.circle(scr, c_top if dot_on else c_off, (300, dy), 11)
MODS.update({3: ch3})
while True:
fn = MODS.get(ch)
for ev in pygame.event.get():
if ev.type == pygame.QUIT or (ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE): pygame.quit(); sys.exit()
if ev.type == pygame.KEYDOWN:
if ev.key == pygame.K_m: mir = not mir
elif ev.key == pygame.K_z and fn: fn("z", (0, 0))
elif ev.key == pygame.K_x and fn: fn("x", (0, 0))
elif pygame.K_1 <= ev.key <= pygame.K_9: ch = ev.key - 48
elif ev.key == pygame.K_0: ch = 10
elif ev.key == pygame.K_SPACE and fn: fn("go", (random.randint(120, 480), 40))
if ev.type == pygame.MOUSEMOTION and fn:
mx, my = ev.pos
fn("move", (mx, H - my if mir else my))
if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1 and fn:
mx, my = ev.pos
fn("go", (mx, H - my if mir else my))
scr.fill((0, 0, 0))
if fn: fn("draw", (0, 0))
else:
lbl = f_s.render("[ KANAAL " + str(ch) + " // LEEG ]", True, (0, 140, 160))
scr.blit(lbl, lbl.get_rect(center=(W // 2, H // 2)))
if mir: scr.blit(pygame.transform.flip(scr, False, True), (0, 0))
pygame.display.flip()
t += 0.03
clk.tick(FPS)
Open ghost display
Project images are for reference only. Actual production is based on the manufacturing files on the project page.
Please review the designer's notes (e.g., PCB thickness) and select the appropriate options.
PCBWay is not responsible
for issues caused by unsuitable parameter selections.
For more important ordering information, please refer to
Read More
Raspberry Pi 5 7 Inch Touch Screen IPS 1024x600 HD LCD HDMI-compatible Display for RPI 4B 3B+ OPI 5 AIDA64 PC Secondary Screen(Without Speaker)
BUY NOW- Comments(0)
- Likes(1)
-
Engineer
Nov 25,2026
- 1 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
-
10design
-
10usability
-
10creativity
-
10content
More by Engineer
-
-
Power Proto Board 100 x 50 mm (built-in 5 V + 3.3 V supply)
160 0 0 -
-
-
-
BorePilot - ESP32-S3 Smart Borewell Pump Controller
376 0 0 -
-
-
AudioLink – USB & Bluetooth LE Audio / Auracast Receiver with Balanced Line Outputs (nRF5340)
537 0 1 -
-
-







