-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.py
51 lines (41 loc) · 1.42 KB
/
canvas.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
from threading import Lock
class Canvas:
displayObjects = []
canvasLock = Lock()
@classmethod
def get_display_objects(cls):
with cls.canvasLock:
return cls.displayObjects
@classmethod
def clear(cls):
with cls.canvasLock:
cls.displayObjects = []
@classmethod
def draw_line(cls, start, end, stroke_style=None):
with cls.canvasLock:
line = {
'type': 'line',
'description': {
'start': {'x': start[0], 'y': start[1]},
'end': {'x': end[0], 'y': end[1]}
}
}
if stroke_style is not None:
line['description']['strokeStyle'] = stroke_style
cls.displayObjects.append(line)
@classmethod
def draw_rect(cls, start, end, fill_style=None, stroke_style=None):
with cls.canvasLock:
rect = {
'type': 'rect',
'description': {
'start': {'x': start[0], 'y': start[1]},
'end': {'x': end[0], 'y': end[1]}
}
}
if stroke_style is not None:
rect['description']['strokeStyle'] = stroke_style
if fill_style is not None:
rect['description']['fill'] = True
rect['description']['fillStyle'] = fill_style
cls.displayObjects.append(rect)