forked from phrack/ShootOFF-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshot.py
64 lines (52 loc) · 2.09 KB
/
shot.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
# Copyright (c) 2013 phrack. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import cv2
class Shot:
# Use the default color and radius for the
# shot marker. Create a new shoot at coord
# (a tuple representing the coordinate of
# laser on the webcam feed). The timestamp
# is the shot timer's time stamp when the
# shot was detected.
def __init__(self, coord, canvas, marker_radius=2, marker_color="green2", timestamp=0):
self._marker_color = marker_color
self._marker_radius = marker_radius
self._coord = coord
self._canvas = canvas
self._timestamp = timestamp
self._canvas_id = None
self._is_selected = False
def set_marker_color(self, marker_color):
self._marker_color = marker_color
self._canvas.itemconfig(self._canvas_id, fill=marker_color)
def set_marker_radius(self, marker_radius):
self._marker_radius = marker_radius
# Redraw the marker with the new radius
self._canvas.delete(self._canvas_id)
self.draw_marker()
def get_color(self):
return self._marker_color
def get_coords(self):
return self._coord
def get_timestamp(self):
return self._timestamp
def draw_marker(self):
x = self._coord[0]
y = self._coord[1]
self._canvas_id = self._canvas.create_oval(
x - self._marker_radius,
y - self._marker_radius,
x + self._marker_radius,
y + self._marker_radius,
fill=self._marker_color, outline=self._marker_color,
tags=("shot_marker"))
def toggle_selected(self):
self._is_selected = not self._is_selected
if self._is_selected:
# Selected shots have cyan outlines
self._canvas.itemconfig(self._canvas_id, fill="gold", outline="gold")
self._canvas.tag_raise(self._canvas_id)
else:
self._canvas.itemconfig(self._canvas_id, fill=self._marker_color,
outline=self._marker_color)