-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.py
63 lines (50 loc) · 1.83 KB
/
bench.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from pyglet.gl import *
import constants
import numpy as np
class Bench:
def __init__(self):
glClearColor(*constants.BACKGROUND_COLOR)
self._axes = []
self.highlighted = None
self.selected = []
def add_axis(self, axis):
self._axes.append(axis)
def update(self):
for axis in self._axes:
axis.trace_rays()
def move_mouse(self, x, y):
coord = np.array((x,y))
nearest = None
dist = -1
for ax in self._axes:
current = ax.distance(coord)
if current >=0:
if dist == -1 or current < dist:
dist = current
nearest = ax
if nearest is not None:
highlight = nearest.select(coord)
else:
highlight = None
if self.highlighted is not None:
if self.highlighted != highlight and self.highlighted not in self.selected:
self.highlighted.color = self.highlighted.base_color
self.highlighted = highlight
if self.highlighted is not None and self.highlighted not in self.selected:
self.highlighted.color = constants.HIGHLIGHT_COLOR
def mouse_click(self, add_select):
if not add_select:
for elmt in self.selected:
elmt.color = elmt.base_color
self.selected.clear()
if self.highlighted is not None and self.highlighted not in self.selected:
self.highlighted.color = constants.SELECT_COLOR
self.selected.append(self.highlighted)
def mouse_drag(self, dx, dy):
for object in self.selected:
translate = object.axis.project(np.array((dx, dy)))
object.position += translate
def draw(self, window):
window.clear()
for axis in self._axes:
axis.draw()