drawzero 0.5.1__tar.gz → 0.5.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {drawzero-0.5.1/src/drawzero.egg-info → drawzero-0.5.4}/PKG-INFO +1 -1
- drawzero-0.5.4/docs/imgs/ex_00.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_01.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_02.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_03.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_04.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_05.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_06.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_11.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_12.png +0 -0
- drawzero-0.5.4/docs/imgs/ex_13.png +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/pyproject.toml +1 -1
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/__about__.py +1 -1
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/06_turtle_style.py +1 -1
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/19_game_colors.py +10 -10
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/draw.py +8 -2
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/renderer.py +28 -7
- drawzero-0.5.4/src/drawzero/utils/renderer_ejudge.py +66 -0
- {drawzero-0.5.1 → drawzero-0.5.4/src/drawzero.egg-info}/PKG-INFO +1 -1
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero.egg-info/SOURCES.txt +12 -10
- {drawzero-0.5.1 → drawzero-0.5.4}/tests/test_errors.py +2 -2
- drawzero-0.5.4/tests/test_renderer_ejudge.py +80 -0
- drawzero-0.5.1/docs/ex_00.png +0 -0
- drawzero-0.5.1/docs/ex_01.png +0 -0
- drawzero-0.5.1/docs/ex_02.png +0 -0
- drawzero-0.5.1/docs/ex_03.png +0 -0
- drawzero-0.5.1/docs/ex_04.png +0 -0
- drawzero-0.5.1/docs/ex_05.png +0 -0
- drawzero-0.5.1/docs/ex_06.png +0 -0
- drawzero-0.5.1/docs/ex_10.png +0 -0
- drawzero-0.5.1/docs/ex_13.png +0 -0
- drawzero-0.5.1/src/drawzero/utils/renderer_ejudge.py +0 -110
- {drawzero-0.5.1 → drawzero-0.5.4}/LICENSE +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/MANIFEST.in +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/README.md +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/docs/hello_world.png +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/docs/keyboard_and_mouse_events.gif +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/docs/planet_animation.gif +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/docs/transparent.png +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/setup.cfg +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/__init__.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/__main__.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/00_hello_world.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/01_grid_and_coordinates.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/02_loops_and_rgb_colors.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/03_simple_objects.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/04_loops_sin_plot.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/05_points.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/07_animation_circles.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/08_animation_traffic_light.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/09_animation_rectangles.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/10_animation_planets.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/11_transparency_and_line_width.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/12_images.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/13_gradients.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/14_animation_close_vertex.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/15_animation_firework.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/16_keyboard_and_mouse.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/17_mouse_tube.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/18_game_stars.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/20_game_racing.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/99_errors.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/__init__.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/examples/cat.png +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/__init__.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/colors.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/converters.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/copy_examples.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/errors.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/gradient.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/i18n.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/key_flags.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/pt.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero/utils/screen_size.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero.egg-info/dependency_links.txt +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero.egg-info/requires.txt +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/src/drawzero.egg-info/top_level.txt +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/tests/test_converters.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/tests/test_copy_examples.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/tests/test_examples_gui_mode.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/tests/test_examples_text_mode.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/tests/test_gradient.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/tests/test_i18n.py +0 -0
- {drawzero-0.5.1 → drawzero-0.5.4}/tests/test_pt.py +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -6,7 +6,7 @@ colors = [C.darkslategrey, C.dimgrey, C.slateblue, C.darkblue, C.yellowgreen, C.
|
|
|
6
6
|
# Drawing regular polygons for n from 3 to 10
|
|
7
7
|
# Рисуем правильные треугольник (n=3), четырёхугольник и т.д. до десятиугольник
|
|
8
8
|
for n in range(3, 11):
|
|
9
|
-
cur = Pt(600,
|
|
9
|
+
cur = Pt(600, 800)
|
|
10
10
|
# Drawing n lines for regular polygon
|
|
11
11
|
# Каждую сторону рисуем отдельно
|
|
12
12
|
for i in range(n):
|
|
@@ -2,8 +2,8 @@ from drawzero import *
|
|
|
2
2
|
import random
|
|
3
3
|
from time import time
|
|
4
4
|
|
|
5
|
-
COLORS = [('
|
|
6
|
-
('
|
|
5
|
+
COLORS = [('yellow', 'yellow'), ('green', 'green'), ('cyan', '#42aaff'), ('blue', '#0000ff'), ('purple', 'purple'),
|
|
6
|
+
('red', 'red'), ('orange', 'orange'), ('brown', 'brown'), ('gray', 'gray'), ('white', 'white'), ]
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def gen_new():
|
|
@@ -33,20 +33,20 @@ while True:
|
|
|
33
33
|
cur_status = None
|
|
34
34
|
time_left = cur_timelimit
|
|
35
35
|
clear()
|
|
36
|
-
text('white', f'
|
|
37
|
-
text('white', f'
|
|
38
|
-
text('white', f'
|
|
39
|
-
text('white', f'{time_left:0.2f}
|
|
36
|
+
text('white', f'Scores: {score}', (500, 50), 48)
|
|
37
|
+
text('white', f'Double-click the left mouse button,', (500, 100), 32)
|
|
38
|
+
text('white', f'if the word and color match, otherwise right-click', (500, 142), 32)
|
|
39
|
+
text('white', f'{time_left:0.2f}s...', (500, 600), 48)
|
|
40
40
|
text(color, cur_word, (500, 500), 120)
|
|
41
41
|
if cur_status == 1:
|
|
42
|
-
text('green', '
|
|
42
|
+
text('green', 'Match?', (500, 700), 48)
|
|
43
43
|
elif cur_status == 3:
|
|
44
|
-
text('red', '
|
|
45
|
-
#
|
|
44
|
+
text('red', 'Mismatch?', (500, 800), 48)
|
|
45
|
+
# Ignore clicks for half a second after color change
|
|
46
46
|
for ev in mousebuttonsdown:
|
|
47
47
|
if cur_ts - last_status_ts > 0.3:
|
|
48
48
|
if ev.button == cur_status:
|
|
49
|
-
#
|
|
49
|
+
# User confirmed
|
|
50
50
|
if (corr and cur_status == 1) or (not corr and cur_status == 3):
|
|
51
51
|
score += 1
|
|
52
52
|
cur_timelimit *= 0.95
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
|
+
from typing import Type, Literal
|
|
3
|
+
|
|
2
4
|
from math import sin, cos, pi
|
|
3
5
|
from time import time
|
|
4
6
|
|
|
@@ -260,10 +262,11 @@ def filled_polygon(color='red', *points, alpha=255):
|
|
|
260
262
|
|
|
261
263
|
|
|
262
264
|
|
|
263
|
-
_VALID_ALIGN = {
|
|
265
|
+
_VALID_ALIGN = {'<.', '.<', '>.', '^>', 'v>', '.^', 'v.', '>^', 'v<', '<v', '..', '.v', '>v', '.>', '^<', '^.', '<^'}
|
|
266
|
+
TAlign: Type = Literal['<.', '.<', '>.', '^>', 'v>', '.^', 'v.', '>^', 'v<', '<v', '..', '.v', '>v', '.>', '^<', '^.', '<^']
|
|
264
267
|
|
|
265
268
|
|
|
266
|
-
def text(color='red', text='Hello!', pos=(100, 100), fontsize=24, align='..'):
|
|
269
|
+
def text(color='red', text='Hello!', pos=(100, 100), fontsize=24, align: TAlign = '..'):
|
|
267
270
|
"""Draw text to the screen."""
|
|
268
271
|
error = BadDrawParmsError()
|
|
269
272
|
use_color = _to_color(color, error)
|
|
@@ -272,6 +275,9 @@ def text(color='red', text='Hello!', pos=(100, 100), fontsize=24, align='..'):
|
|
|
272
275
|
if align not in _VALID_ALIGN:
|
|
273
276
|
error.errors.append(I18N.bad_text_align.format(align))
|
|
274
277
|
error.errors.append(I18N.use_text_align)
|
|
278
|
+
if isinstance(align, str) and len(align) == 2:
|
|
279
|
+
if align[0] in '^v':
|
|
280
|
+
align = align[::-1]
|
|
275
281
|
if error.errors:
|
|
276
282
|
error.call_string = f'text({color!r}, {text!r}, {pos!r}, {fontsize!r}, {align!r})'
|
|
277
283
|
error.example = f"text({color if use_color else 'red'!r}, {text!r}, {use_pos or (100, 100)!r}, {use_fontsize or 24!r}, {align if align in _VALID_ALIGN else '..'!r})"
|
|
@@ -5,6 +5,7 @@ import os
|
|
|
5
5
|
from typing import Tuple, List, Union, Optional
|
|
6
6
|
|
|
7
7
|
import warnings
|
|
8
|
+
|
|
8
9
|
warnings.filterwarnings(
|
|
9
10
|
"ignore",
|
|
10
11
|
message=r"pkg_resources is deprecated.*",
|
|
@@ -13,6 +14,7 @@ warnings.filterwarnings(
|
|
|
13
14
|
)
|
|
14
15
|
|
|
15
16
|
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
|
|
17
|
+
from drawzero.utils.key_flags import KEY
|
|
16
18
|
import pygame
|
|
17
19
|
import pygame.locals
|
|
18
20
|
|
|
@@ -240,12 +242,7 @@ def draw_image(path: str, pos: Pt, width: int = None, alpha: int = 255):
|
|
|
240
242
|
height = int(h * width / w + 0.5)
|
|
241
243
|
image = pygame.transform.smoothscale(image, (width, height))
|
|
242
244
|
if alpha != 255:
|
|
243
|
-
|
|
244
|
-
temp.blit(_surface, (-pos[0], -pos[1])) # Blit the OPAQUE BACKGROUND onto this temporary image.
|
|
245
|
-
temp.blit(image, (0, 0)) # Blit the per-pixel transparency image onto the temporary image.
|
|
246
|
-
# The temporary image is completely opaque and has the transparent image on it above the background.
|
|
247
|
-
temp.set_alpha(alpha)
|
|
248
|
-
image = temp
|
|
245
|
+
image.set_alpha(alpha)
|
|
249
246
|
_surface.blit(image, pos)
|
|
250
247
|
_display_update_if_no_animation()
|
|
251
248
|
|
|
@@ -365,8 +362,32 @@ def get_mouse_pressed():
|
|
|
365
362
|
return pygame.mouse.get_pressed(3)
|
|
366
363
|
|
|
367
364
|
|
|
365
|
+
class KeysPressed:
|
|
366
|
+
def __init__(self, raw_pressed):
|
|
367
|
+
self._raw = raw_pressed
|
|
368
|
+
self._pressed_names = None
|
|
369
|
+
|
|
370
|
+
def __getitem__(self, key):
|
|
371
|
+
if isinstance(key, int):
|
|
372
|
+
return self._raw[key]
|
|
373
|
+
|
|
374
|
+
if isinstance(key, str):
|
|
375
|
+
return self._raw[KEY.__getattribute__(key)]
|
|
376
|
+
|
|
377
|
+
return False
|
|
378
|
+
|
|
379
|
+
def __contains__(self, key):
|
|
380
|
+
if isinstance(key, int):
|
|
381
|
+
return self._raw[key]
|
|
382
|
+
|
|
383
|
+
if isinstance(key, str):
|
|
384
|
+
return self._raw[KEY.__getattribute__(key)]
|
|
385
|
+
|
|
386
|
+
return False
|
|
387
|
+
|
|
388
|
+
|
|
368
389
|
def get_keys_pressed():
|
|
369
|
-
return pygame.key.get_pressed()
|
|
390
|
+
return KeysPressed(pygame.key.get_pressed())
|
|
370
391
|
|
|
371
392
|
|
|
372
393
|
def keys_mods_pressed():
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from drawzero.utils.screen_size import set_real_size
|
|
5
|
+
|
|
6
|
+
set_real_size(1000, 1000)
|
|
7
|
+
|
|
8
|
+
class PathEncoder(json.JSONEncoder):
|
|
9
|
+
def default(self, obj):
|
|
10
|
+
if isinstance(obj, Path):
|
|
11
|
+
return str(obj)
|
|
12
|
+
return super().default(obj)
|
|
13
|
+
|
|
14
|
+
def draw_line(color, start, end, alpha, line_width):
|
|
15
|
+
print(json.dumps({"figure": "line", "color": color, "start": start, "end": end, "alpha": alpha, "line_width": line_width}, cls=PathEncoder))
|
|
16
|
+
|
|
17
|
+
def draw_circle(color, pos, radius, alpha, line_width):
|
|
18
|
+
print(json.dumps({"figure": "circle", "color": color, "pos": pos, "radius": radius, "alpha": alpha, "line_width": line_width}, cls=PathEncoder))
|
|
19
|
+
|
|
20
|
+
def draw_rect(color, rect, alpha, line_width):
|
|
21
|
+
print(json.dumps({"figure": "rect", "color": color, "rect": rect, "alpha": alpha, "line_width": line_width}, cls=PathEncoder))
|
|
22
|
+
|
|
23
|
+
def draw_ellipse(color, rect, alpha, line_width):
|
|
24
|
+
print(json.dumps({"figure": "ellipse", "color": color, "rect": rect, "alpha": alpha, "line_width": line_width}, cls=PathEncoder))
|
|
25
|
+
|
|
26
|
+
def draw_arc(color, rect, start_angle, stop_angle, alpha, line_width):
|
|
27
|
+
print(json.dumps({"figure": "arc", "color": color, "rect": rect, "start_angle": start_angle, "stop_angle": stop_angle, "alpha": alpha, "line_width": line_width}, cls=PathEncoder))
|
|
28
|
+
|
|
29
|
+
def draw_polygon(color, points, alpha, line_width):
|
|
30
|
+
print(json.dumps({"figure": "polygon", "color": color, "points": points, "alpha": alpha, "line_width": line_width}, cls=PathEncoder))
|
|
31
|
+
|
|
32
|
+
def draw_text(color, text, pos, fontsize, align):
|
|
33
|
+
print(json.dumps({"figure": "text", "color": color, "text": text, "pos": pos, "fontsize": fontsize, "align": align}, cls=PathEncoder))
|
|
34
|
+
|
|
35
|
+
def draw_fill(color, alpha):
|
|
36
|
+
print(json.dumps({"figure": "fill", "color": color, "alpha": alpha}, cls=PathEncoder))
|
|
37
|
+
|
|
38
|
+
def draw_clear():
|
|
39
|
+
print(json.dumps({"figure": "clear"}))
|
|
40
|
+
|
|
41
|
+
def draw_image(path, pos, width, alpha):
|
|
42
|
+
print(json.dumps({"figure": "image", "path": path, "pos": pos, "width": width, "alpha": alpha}, cls=PathEncoder))
|
|
43
|
+
|
|
44
|
+
def draw_tick(r=1):
|
|
45
|
+
print(json.dumps({"cmd": "tick", "r": r}))
|
|
46
|
+
|
|
47
|
+
def draw_sleep(t=1):
|
|
48
|
+
print(json.dumps({"cmd": "sleep", "t": t}))
|
|
49
|
+
|
|
50
|
+
def draw_set_line_width(w):
|
|
51
|
+
print(json.dumps({"cmd": "set_line_width", "w": w}))
|
|
52
|
+
|
|
53
|
+
def draw_quit():
|
|
54
|
+
print(json.dumps({"cmd": "quit"}))
|
|
55
|
+
|
|
56
|
+
surface_size = 1000
|
|
57
|
+
key_flags = None
|
|
58
|
+
|
|
59
|
+
get_keys_pressed = lambda: []
|
|
60
|
+
keys_mods_pressed = lambda: []
|
|
61
|
+
get_mouse_pressed = lambda: []
|
|
62
|
+
keysdown = []
|
|
63
|
+
keysup = []
|
|
64
|
+
mousemotions = []
|
|
65
|
+
mousebuttonsdown = []
|
|
66
|
+
mousebuttonsup = []
|
|
@@ -2,19 +2,20 @@ LICENSE
|
|
|
2
2
|
MANIFEST.in
|
|
3
3
|
README.md
|
|
4
4
|
pyproject.toml
|
|
5
|
-
docs/ex_00.png
|
|
6
|
-
docs/ex_01.png
|
|
7
|
-
docs/ex_02.png
|
|
8
|
-
docs/ex_03.png
|
|
9
|
-
docs/ex_04.png
|
|
10
|
-
docs/ex_05.png
|
|
11
|
-
docs/ex_06.png
|
|
12
|
-
docs/ex_10.png
|
|
13
|
-
docs/ex_13.png
|
|
14
5
|
docs/hello_world.png
|
|
15
6
|
docs/keyboard_and_mouse_events.gif
|
|
16
7
|
docs/planet_animation.gif
|
|
17
8
|
docs/transparent.png
|
|
9
|
+
docs/imgs/ex_00.png
|
|
10
|
+
docs/imgs/ex_01.png
|
|
11
|
+
docs/imgs/ex_02.png
|
|
12
|
+
docs/imgs/ex_03.png
|
|
13
|
+
docs/imgs/ex_04.png
|
|
14
|
+
docs/imgs/ex_05.png
|
|
15
|
+
docs/imgs/ex_06.png
|
|
16
|
+
docs/imgs/ex_11.png
|
|
17
|
+
docs/imgs/ex_12.png
|
|
18
|
+
docs/imgs/ex_13.png
|
|
18
19
|
src/drawzero/__about__.py
|
|
19
20
|
src/drawzero/__init__.py
|
|
20
21
|
src/drawzero/__main__.py
|
|
@@ -67,4 +68,5 @@ tests/test_examples_gui_mode.py
|
|
|
67
68
|
tests/test_examples_text_mode.py
|
|
68
69
|
tests/test_gradient.py
|
|
69
70
|
tests/test_i18n.py
|
|
70
|
-
tests/test_pt.py
|
|
71
|
+
tests/test_pt.py
|
|
72
|
+
tests/test_renderer_ejudge.py
|
|
@@ -46,7 +46,7 @@ class RunExamples(unittest.TestCase):
|
|
|
46
46
|
self.assertTrue(exception_printer.last_raised, msg=msg)
|
|
47
47
|
max_deep = MAX_TRACEBACK_DEEP
|
|
48
48
|
if func.__name__.startswith('filled'):
|
|
49
|
-
max_deep +=
|
|
49
|
+
max_deep += 2
|
|
50
50
|
self.assertLessEqual(exception_printer.last_deep, max_deep, msg=msg)
|
|
51
51
|
|
|
52
52
|
def test_bad_pos(self):
|
|
@@ -63,7 +63,7 @@ class RunExamples(unittest.TestCase):
|
|
|
63
63
|
self.assertTrue(exception_printer.last_raised, msg=msg)
|
|
64
64
|
max_deep = MAX_TRACEBACK_DEEP
|
|
65
65
|
if func.__name__.startswith('filled'):
|
|
66
|
-
max_deep +=
|
|
66
|
+
max_deep += 2
|
|
67
67
|
self.assertLessEqual(exception_printer.last_deep, max_deep, msg=msg)
|
|
68
68
|
|
|
69
69
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
import json
|
|
4
|
+
from io import StringIO
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
os.environ['EJUDGE_MODE'] = 'true'
|
|
8
|
+
# We need to reload drawzero to apply EJUDGE_MODE
|
|
9
|
+
if 'drawzero' in sys.modules:
|
|
10
|
+
import importlib
|
|
11
|
+
importlib.reload(sys.modules['drawzero.utils.draw'])
|
|
12
|
+
importlib.reload(sys.modules['drawzero'])
|
|
13
|
+
from drawzero import *
|
|
14
|
+
|
|
15
|
+
class EjudgeRendererTest(unittest.TestCase):
|
|
16
|
+
def setUp(self):
|
|
17
|
+
self.held, sys.stdout = sys.stdout, StringIO()
|
|
18
|
+
|
|
19
|
+
def tearDown(self):
|
|
20
|
+
sys.stdout = self.held
|
|
21
|
+
|
|
22
|
+
def test_line(self):
|
|
23
|
+
line('red', (10, 20), (30, 40), alpha=128, line_width=2)
|
|
24
|
+
output = sys.stdout.getvalue().strip()
|
|
25
|
+
data = json.loads(output)
|
|
26
|
+
self.assertEqual(data['figure'], 'line')
|
|
27
|
+
self.assertEqual(data['color'], [255, 0, 0])
|
|
28
|
+
self.assertEqual(data['start'], [10, 20])
|
|
29
|
+
self.assertEqual(data['end'], [30, 40])
|
|
30
|
+
self.assertEqual(data['alpha'], 128)
|
|
31
|
+
self.assertEqual(data['line_width'], 2)
|
|
32
|
+
|
|
33
|
+
def test_circle(self):
|
|
34
|
+
circle('blue', (50, 60), 10, alpha=200, line_width=4)
|
|
35
|
+
output = sys.stdout.getvalue().strip()
|
|
36
|
+
data = json.loads(output)
|
|
37
|
+
self.assertEqual(data['figure'], 'circle')
|
|
38
|
+
self.assertEqual(data['color'], [0, 0, 255])
|
|
39
|
+
self.assertEqual(data['pos'], [50, 60])
|
|
40
|
+
self.assertEqual(data['radius'], 10)
|
|
41
|
+
self.assertEqual(data['alpha'], 200)
|
|
42
|
+
self.assertEqual(data['line_width'], 4)
|
|
43
|
+
|
|
44
|
+
def test_rect(self):
|
|
45
|
+
rect('green', (10, 20, 30, 40), alpha=100, line_width=1)
|
|
46
|
+
output = sys.stdout.getvalue().strip()
|
|
47
|
+
data = json.loads(output)
|
|
48
|
+
self.assertEqual(data['figure'], 'rect')
|
|
49
|
+
self.assertEqual(data['color'], [0, 255, 0])
|
|
50
|
+
self.assertEqual(data['rect'], [10, 20, 30, 40])
|
|
51
|
+
self.assertEqual(data['alpha'], 100)
|
|
52
|
+
self.assertEqual(data['line_width'], 1)
|
|
53
|
+
|
|
54
|
+
def test_text(self):
|
|
55
|
+
text('yellow', 'Hello', (10, 20), fontsize=12, align='..')
|
|
56
|
+
output = sys.stdout.getvalue().strip()
|
|
57
|
+
data = json.loads(output)
|
|
58
|
+
self.assertEqual(data['figure'], 'text')
|
|
59
|
+
self.assertEqual(data['color'], [255, 255, 0])
|
|
60
|
+
self.assertEqual(data['text'], 'Hello')
|
|
61
|
+
self.assertEqual(data['pos'], [10, 20])
|
|
62
|
+
self.assertEqual(data['fontsize'], 12)
|
|
63
|
+
self.assertEqual(data['align'], '..')
|
|
64
|
+
|
|
65
|
+
def test_fill(self):
|
|
66
|
+
fill('black', alpha=50)
|
|
67
|
+
output = sys.stdout.getvalue().strip()
|
|
68
|
+
data = json.loads(output)
|
|
69
|
+
self.assertEqual(data['figure'], 'fill')
|
|
70
|
+
self.assertEqual(data['color'], [0, 0, 0])
|
|
71
|
+
self.assertEqual(data['alpha'], 50)
|
|
72
|
+
|
|
73
|
+
def test_clear(self):
|
|
74
|
+
clear()
|
|
75
|
+
output = sys.stdout.getvalue().strip()
|
|
76
|
+
data = json.loads(output)
|
|
77
|
+
self.assertEqual(data['figure'], 'clear')
|
|
78
|
+
|
|
79
|
+
if __name__ == "__main__":
|
|
80
|
+
unittest.main()
|
drawzero-0.5.1/docs/ex_00.png
DELETED
|
Binary file
|
drawzero-0.5.1/docs/ex_01.png
DELETED
|
Binary file
|
drawzero-0.5.1/docs/ex_02.png
DELETED
|
Binary file
|
drawzero-0.5.1/docs/ex_03.png
DELETED
|
Binary file
|
drawzero-0.5.1/docs/ex_04.png
DELETED
|
Binary file
|
drawzero-0.5.1/docs/ex_05.png
DELETED
|
Binary file
|
drawzero-0.5.1/docs/ex_06.png
DELETED
|
Binary file
|
drawzero-0.5.1/docs/ex_10.png
DELETED
|
Binary file
|
drawzero-0.5.1/docs/ex_13.png
DELETED
|
Binary file
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
from drawzero.utils.screen_size import set_real_size
|
|
3
|
-
|
|
4
|
-
# TODO
|
|
5
|
-
set_real_size(1000, 1000)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def jsonize(parms, sep=','):
|
|
9
|
-
if type(parms) == int or type(parms) == float:
|
|
10
|
-
return str(parms)
|
|
11
|
-
elif type(parms) == str:
|
|
12
|
-
return '"' + parms.replace('"', '\\"') + '"'
|
|
13
|
-
elif isinstance(parms, Path):
|
|
14
|
-
return '"' + str(parms).replace('"', '\\"') + '"'
|
|
15
|
-
elif type(parms) == list or type(parms) == tuple:
|
|
16
|
-
return '[' + sep.join(map(jsonize, parms)) + ']'
|
|
17
|
-
elif parms is None:
|
|
18
|
-
return 'null'
|
|
19
|
-
else:
|
|
20
|
-
raise ValueError('Тип не поддерживается')
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def draw_resize(*parms):
|
|
24
|
-
print('resize', format(jsonize(parms, sep=', ')))
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def draw_line(*parms):
|
|
28
|
-
print('line', format(jsonize(parms, sep=', ')))
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def draw_circle(*parms):
|
|
32
|
-
print('circle', format(jsonize(parms, sep=', ')))
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def draw_filled_circle(*parms):
|
|
36
|
-
print('filled_circle', format(jsonize(parms, sep=', ')))
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def draw_rect(*parms):
|
|
40
|
-
print('rect', format(jsonize(parms, sep=', ')))
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def draw_filled_rect(*parms):
|
|
44
|
-
print('filled_rect', format(jsonize(parms, sep=', ')))
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def draw_ellipse(*parms):
|
|
48
|
-
print('ellipse', format(jsonize(parms, sep=', ')))
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def draw_filled_ellipse(*parms):
|
|
52
|
-
print('filled_ellipse', format(jsonize(parms, sep=', ')))
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def draw_arc(*parms):
|
|
56
|
-
print('arc', format(jsonize(parms, sep=', ')))
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def draw_polygon(*parms):
|
|
60
|
-
print('polygon', format(jsonize(parms, sep=', ')))
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def draw_filled_polygon(*parms):
|
|
64
|
-
print('filled_polygon', format(jsonize(parms, sep=', ')))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def draw_text(*parms):
|
|
68
|
-
print('text', format(jsonize(parms, sep=', ')))
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def draw_fill(*parms):
|
|
72
|
-
print('fill', format(jsonize(parms, sep=', ')))
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def draw_clear(*parms):
|
|
76
|
-
print('clear', format(jsonize(parms, sep=', ')))
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def draw_image(*parms):
|
|
80
|
-
print('image', format(jsonize(parms, sep=', ')))
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def draw_tick(r=1):
|
|
84
|
-
print('tick({})'.format(r))
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def draw_sleep(t=1):
|
|
88
|
-
print('sleep({})'.format(t))
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def draw_set_line_width(w):
|
|
92
|
-
print('set_line_width({})'.format(w))
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def draw_quit():
|
|
96
|
-
print('quit')
|
|
97
|
-
pass
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
surface_size = 1000
|
|
101
|
-
key_flags = None
|
|
102
|
-
|
|
103
|
-
get_keys_pressed = lambda: []
|
|
104
|
-
keys_mods_pressed = lambda: []
|
|
105
|
-
get_mouse_pressed = lambda: []
|
|
106
|
-
keysdown = []
|
|
107
|
-
keysup = []
|
|
108
|
-
mousemotions = []
|
|
109
|
-
mousebuttonsdown = []
|
|
110
|
-
mousebuttonsup = []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|