Skip to content

Commit 3769a44

Browse files
committed
Initial commit
0 parents  commit 3769a44

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.venv/*
2+
.idea/*
3+
dist/*
4+
build/*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"# Simple Input Display"

cfg.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pickle, os
2+
3+
def load_config():
4+
if os.path.exists('cfg.pkl'):
5+
with open('cfg.pkl', 'rb') as f:
6+
return pickle.load(f)
7+
else:
8+
cfg = {}
9+
cfg["SCREEN_WIDTH"] = 640
10+
cfg["SCREEN_HEIGHT"] = 480
11+
cfg["TITLE"] = "sinputd"
12+
13+
with open('cfg.pkl', 'wb') as f:
14+
pickle.dump(cfg, f)
15+
16+
return cfg
17+
18+
config = load_config()

fs_mouse.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import pg_main, pygame, time, math
2+
from pynput.mouse import Listener
3+
from cfg import *
4+
5+
prev_time = time.time()
6+
prev_pos = None
7+
8+
vx = 0
9+
vy = 0
10+
11+
px = 0
12+
py = 0
13+
14+
mx = 0
15+
my = 0
16+
17+
speed_level = 2
18+
19+
def event_func(event):
20+
global mx, my
21+
if event.type == pygame.KEYDOWN:
22+
if event.key == pygame.K_RETURN:
23+
print(mx,my)
24+
25+
last_dx = 0.0
26+
last_dy = 0.0
27+
28+
def on_move(x,y):
29+
global prev_time, prev_pos, vx, vy, px, py, mx, my, last_dx, last_dy
30+
31+
mouse_mult = 1 - math.exp(-speed_level)
32+
33+
current_time = time.time()
34+
if prev_pos is not None:
35+
dx = x - prev_pos[0]
36+
dy = y - prev_pos[1]
37+
38+
if dx != 0 and last_dx != 0 and ( dx/abs(dx) != last_dx/abs(last_dx) ):
39+
dx = 0
40+
if dy != 0 and last_dy != 0 and ( dy/abs(dy) != last_dy/abs(last_dy) ):
41+
dy = 0
42+
43+
last_dx = dx
44+
last_dy = dy
45+
46+
dt = current_time - prev_time
47+
if dt > 0:
48+
vx = dx / (dt * 1000)
49+
vy = dy / (dt * 1000)
50+
51+
px += vx
52+
py += vy
53+
mx += vx * 0.1 * mouse_mult
54+
my += vy * 0.1 * mouse_mult
55+
56+
prev_pos = (x, y)
57+
prev_time = current_time
58+
59+
surface1 = pygame.Surface((config["SCREEN_WIDTH"], config["SCREEN_HEIGHT"]))
60+
surface2 = pygame.Surface((config["SCREEN_WIDTH"], config["SCREEN_HEIGHT"]))
61+
62+
surface1.set_alpha(100)
63+
surface2.set_alpha(100)
64+
65+
def render_func(screen):
66+
67+
global vx, vy, px, py, mx, my, timey
68+
69+
mouse_mult = 1-math.exp(-speed_level)
70+
px *= mouse_mult
71+
py *= mouse_mult
72+
73+
sw = config["SCREEN_WIDTH"]
74+
sh = config["SCREEN_HEIGHT"]
75+
s = pygame.Surface((sw,sh))
76+
s.set_alpha(1)
77+
s.fill((0, 0, 0))
78+
surface2.blit(s, (0, 0))
79+
screen.fill((0, 0, 0))
80+
81+
shift_x = -vx * 0.1 * mouse_mult
82+
shift_y = -vy * 0.1 * mouse_mult
83+
84+
# Scroll the trail surface
85+
surface2.scroll(int(shift_x), int(shift_y))
86+
87+
pygame.draw.circle(surface2,(255,255,255),(sw*0.5,sh*0.5), 3)
88+
surface1.blit(surface2, (0, 0))
89+
90+
screen.blit(surface1, (0, 0))
91+
pygame.draw.line(screen, (255, 255, 255), (sw * 0.5, sh * 0.5),(sw*0.5 + px,sh*0.5 + py), 2)
92+
93+
94+
if __name__ == "__main__":
95+
listener = Listener(on_move=on_move)
96+
listener.start()
97+
pg_main.render(event_func, render_func)

offset_surface.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pg_main, pygame
2+
3+
def event_func(event):
4+
pass
5+
def render_func(screen):
6+
pass
7+
8+
if __name__ == "__main__":
9+
pg_main.render(event_func, render_func)

pg_main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from cfg import *
2+
import pygame, sys
3+
4+
def render(event_func,render_func):
5+
load_config()
6+
pygame.init()
7+
display = pygame.display.set_mode((config["SCREEN_WIDTH"], config["SCREEN_HEIGHT"]))
8+
pygame.display.set_caption(config["TITLE"])
9+
10+
while True:
11+
for event in pygame.event.get():
12+
if event.type == pygame.QUIT:
13+
pygame.quit()
14+
sys.exit()
15+
if event.type == pygame.KEYDOWN:
16+
if event.key == pygame.K_ESCAPE:
17+
pygame.quit()
18+
sys.exit()
19+
event_func(event)
20+
21+
render_func(display)
22+
23+
pygame.display.update()

0 commit comments

Comments
 (0)