diff --git a/README.md b/README.md
index 5b54b1c..1fa4057 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,71 @@ while True:
```
+# Point class which acts like 2-d vector and Turtle both
+
+
+
+```python
+from drawzero import *
+
+# just coordinates
+A = Pt(100, 100)
+B = Pt(300, 150)
+line(C.red, A, B)
+
+# A point which acts as 2-d vector and as a Turtle
+# Pt(x=0.0, y=0.0, *, heading=0.0)
+#
+# Provides (for a, b — points, k number):
+# * arithmetic
+# a+b — vector addition
+# a-b — vector subtraction
+# k*a and a*k — multiplication with scalar
+# abs — absolute value of a
+# +a, -a
+
+# arithmetic
+A = Pt(100, 200)
+dx = Pt(50, 5)
+for i in range(10):
+ filled_circle(C.blue, A + dx * i, radius=10)
+
+# * turtle-style movement
+# forward — Move the point forward by the specified distance.
+# backward — Move the point backward by distance.
+# right — Turn point right by angle degrees.
+# left — Turn point left by angle degrees.
+# goto — Move point to an absolute position.
+# rotate_around — Rotate around given point by angle degrees.
+# move_towards — Move towards the given point by the specified distance.
+# reset, home — Move point to the origin - coordinates (0,0), set heading=0
+# setx — Set the point's first coordinate to x
+# sety — Set the point's second coordinate to y
+# setheading — Set the point's heading
+
+A = Pt(100, 300)
+B = Pt(1000, 400)
+for i in range(10):
+ filled_circle(C.green2, A, radius=10)
+ A.move_towards(50, B)
+
+A = Pt(100, 400)
+for i in range(10):
+ filled_circle(C.magenta, A, radius=10)
+ A.left(10).forward(30)
+
+# * information
+# position — Return the point's current location (x,y), as a tuple.
+# x, xcor — Return the point's x coordinate.
+# y, ycor — Return the point's y coordinate
+# heading — Return the point's heading
+# distance — Return the distance between points
+# towards — Return the angle towards point
+# * deep copy
+# copy — a clone of point
+```
+
+
# Transparency
@@ -124,6 +189,31 @@ circle((0, 255, 0, 50), (100, 110), 50, line_width=10) # <-- RGBA
+# Color gradients
+
+
+
+```python
+from drawzero import *
+
+
+scale1 = Gradient([C.black, C.white], 0, 1000)
+for x in range(0, 1000, 10):
+ filled_rect(scale1(x), (x, 0), 10, 100)
+text(C.white, 'scale1 = Gradient([C.black, C.white], 0, 1000)', (50, 100), 48, '<^')
+
+scale2 = Gradient([C.green, C.yellow, C.magenta, C.red], 0, 1000)
+for x in range(0, 1000, 10):
+ filled_rect(scale2(x), (x, 200), 10, 100)
+text(C.white, 'scale2 = Gradient([C.green, C.yellow, C.magenta, C.red], 0, 1000)', (50, 300), 32, '<^')
+
+scale3 = Gradient([C.white, C.black, C.red, C.black, C.white], 200, 800)
+for x in range(0, 1000, 10):
+ filled_rect(scale3(x), (x, 400), 10, 100)
+text(C.white, 'scale3 = Gradient([C.white, C.black, C.red, C.black, C.white], 200, 800)', (50, 500), 32, '<^')
+```
+
+
# Keyboard and mouse events
@@ -180,10 +270,10 @@ Or run the following program:
```python
import os, sys
python = sys.executable
-user = '--user' if 'venv' not in python else ''
+user = '--user' if 'venv' not in python and 'virtualenvs' not in python else ''
cmd = f'"{python}" -m pip install drawzero --upgrade {user}'
-print(cmd)
os.system(cmd)
+from drawzero import *
```
# [Contributing](CONTRIBUTING.md)
diff --git a/docs/ex_00.png b/docs/ex_00.png
new file mode 100644
index 0000000..72ab171
Binary files /dev/null and b/docs/ex_00.png differ
diff --git a/docs/ex_01.png b/docs/ex_01.png
new file mode 100644
index 0000000..ac65a21
Binary files /dev/null and b/docs/ex_01.png differ
diff --git a/docs/ex_02.png b/docs/ex_02.png
new file mode 100644
index 0000000..e0fdf04
Binary files /dev/null and b/docs/ex_02.png differ
diff --git a/docs/ex_03.png b/docs/ex_03.png
new file mode 100644
index 0000000..8634151
Binary files /dev/null and b/docs/ex_03.png differ
diff --git a/docs/ex_04.png b/docs/ex_04.png
new file mode 100644
index 0000000..b78fe42
Binary files /dev/null and b/docs/ex_04.png differ
diff --git a/docs/ex_05.png b/docs/ex_05.png
new file mode 100644
index 0000000..0182934
Binary files /dev/null and b/docs/ex_05.png differ
diff --git a/docs/ex_06.png b/docs/ex_06.png
new file mode 100644
index 0000000..1028bb7
Binary files /dev/null and b/docs/ex_06.png differ
diff --git a/docs/ex_10.png b/docs/ex_10.png
new file mode 100644
index 0000000..f356c76
Binary files /dev/null and b/docs/ex_10.png differ
diff --git a/docs/ex_13.png b/docs/ex_13.png
new file mode 100644
index 0000000..9b87abe
Binary files /dev/null and b/docs/ex_13.png differ
diff --git a/requirements.txt b/requirements.txt
index 5d2caa2..0d61ebd 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +1 @@
-pygame>=2.0.0
+pygame>=2.0.1
diff --git a/src/drawzero/__about__.py b/src/drawzero/__about__.py
index 3df4cf4..5991b3e 100644
--- a/src/drawzero/__about__.py
+++ b/src/drawzero/__about__.py
@@ -5,7 +5,7 @@
"__copyright__",
]
-__version__ = '0.4.3'
+__version__ = '0.4.4'
__author__ = "Sergey Shashkov"
__license__ = "MIT"
__copyright__ = "Copyright 2020- Sergey Shashkov"
diff --git a/src/drawzero/__init__.py b/src/drawzero/__init__.py
index 9cc1a6b..7448bb0 100644
--- a/src/drawzero/__init__.py
+++ b/src/drawzero/__init__.py
@@ -17,6 +17,8 @@
__all__ = [
# spec
'__author__', '__copyright__', '__version__',
+ #
+ 'run',
# simple shapes
'line', 'arc', 'circle', 'rect', 'ellipse', 'rect_rotated', 'polygon',
# filled shapes
diff --git a/src/drawzero/examples/00_hello_world.py b/src/drawzero/examples/00_hello_world.py
index e79c019..3041951 100644
--- a/src/drawzero/examples/00_hello_world.py
+++ b/src/drawzero/examples/00_hello_world.py
@@ -1,22 +1,20 @@
# Just import everything
# Импортируем всё
from drawzero import *
-#
-# # Red rectangle with upper left corner at (50, 150) and width = 900, height = 700
-# # Красный прямоугольник с левым верхнем углом в точке(50, 150), шириной 900 и высотой 700
-# rect('red', (50, 150), 900, 700)
-#
-# # Straight orange line from (100, 500) to (900, 500)
-# # Оранжевая прямая линия из точки (100, 500) в точку (900, 500)
-# line('orange', (100, 500), (900, 500))
-#
-# # Centered text
-# # Центрированный текст
-# text('green', 'Hello world!', (500, 250), fontsize=72)
-# text('blue', 'Привет, мир!', (500, 750), fontsize=72)
-from drawzero import *
+# Red rectangle with upper left corner at (50, 150) and width = 900, height = 700
+# Красный прямоугольник с левым верхнем углом в точке(50, 150), шириной 900 и высотой 700
+rect('red', (50, 150), 900, 700)
+
+# Straight orange line from (100, 500) to (900, 500)
+# Оранжевая прямая линия из точки (100, 500) в точку (900, 500)
+line('orange', (100, 500), (900, 500))
+
+# Centered text
+# Центрированный текст
+text('green', 'Hello world!', (500, 250), fontsize=72)
+text('blue', 'Привет, мир!', (500, 750), fontsize=72)
-# help(line)
-set_lang('en')
-line('red', 300, 400, 1, 2, )
+# Run loop
+# Запуск
+run()
diff --git a/src/drawzero/examples/05_points.py b/src/drawzero/examples/05_points.py
new file mode 100644
index 0000000..8ebcbe3
--- /dev/null
+++ b/src/drawzero/examples/05_points.py
@@ -0,0 +1,57 @@
+from drawzero import *
+
+# just coordinates
+A = Pt(100, 100)
+B = Pt(300, 150)
+line(C.red, A, B)
+
+# A point which acts as 2-d vector and as a Turtle
+# Pt(x=0.0, y=0.0, *, heading=0.0)
+#
+# Provides (for a, b — points, k number):
+# * arithmetic
+# a+b — vector addition
+# a-b — vector subtraction
+# k*a and a*k — multiplication with scalar
+# abs — absolute value of a
+# +a, -a
+
+# arithmetic
+A = Pt(100, 200)
+dx = Pt(50, 5)
+for i in range(10):
+ filled_circle(C.blue, A + dx * i, radius=10)
+
+# * turtle-style movement
+# forward — Move the point forward by the specified distance.
+# backward — Move the point backward by distance.
+# right — Turn point right by angle degrees.
+# left — Turn point left by angle degrees.
+# goto — Move point to an absolute position.
+# rotate_around — Rotate around given point by angle degrees.
+# move_towards — Move towards the given point by the specified distance.
+# reset, home — Move point to the origin - coordinates (0,0), set heading=0
+# setx — Set the point's first coordinate to x
+# sety — Set the point's second coordinate to y
+# setheading — Set the point's heading
+
+A = Pt(100, 300)
+B = Pt(1000, 400)
+for i in range(10):
+ filled_circle(C.green2, A, radius=10)
+ A.move_towards(50, B)
+
+A = Pt(100, 400)
+for i in range(10):
+ filled_circle(C.magenta, A, radius=10)
+ A.left(10).forward(30)
+
+# * information
+# position — Return the point's current location (x,y), as a tuple.
+# x, xcor — Return the point's x coordinate.
+# y, ycor — Return the point's y coordinate
+# heading — Return the point's heading
+# distance — Return the distance between points
+# towards — Return the angle towards point
+# * deep copy
+# copy — a clone of point
diff --git a/src/drawzero/examples/05_turtle_style.py b/src/drawzero/examples/06_turtle_style.py
similarity index 100%
rename from src/drawzero/examples/05_turtle_style.py
rename to src/drawzero/examples/06_turtle_style.py
diff --git a/src/drawzero/examples/06_animation_circles.py b/src/drawzero/examples/07_animation_circles.py
similarity index 100%
rename from src/drawzero/examples/06_animation_circles.py
rename to src/drawzero/examples/07_animation_circles.py
diff --git a/src/drawzero/examples/07_animation_traffic_light.py b/src/drawzero/examples/08_animation_traffic_light.py
similarity index 100%
rename from src/drawzero/examples/07_animation_traffic_light.py
rename to src/drawzero/examples/08_animation_traffic_light.py
diff --git a/src/drawzero/examples/08_animation_rectangles.py b/src/drawzero/examples/09_animation_rectangles.py
similarity index 100%
rename from src/drawzero/examples/08_animation_rectangles.py
rename to src/drawzero/examples/09_animation_rectangles.py
diff --git a/src/drawzero/examples/09_animation_planets.py b/src/drawzero/examples/10_animation_planets.py
similarity index 100%
rename from src/drawzero/examples/09_animation_planets.py
rename to src/drawzero/examples/10_animation_planets.py
diff --git a/src/drawzero/examples/10_transparency_and_line_width.py b/src/drawzero/examples/11_transparency_and_line_width.py
similarity index 100%
rename from src/drawzero/examples/10_transparency_and_line_width.py
rename to src/drawzero/examples/11_transparency_and_line_width.py
diff --git a/src/drawzero/examples/11_images.py b/src/drawzero/examples/12_images.py
similarity index 100%
rename from src/drawzero/examples/11_images.py
rename to src/drawzero/examples/12_images.py
diff --git a/src/drawzero/examples/13_gradients.py b/src/drawzero/examples/13_gradients.py
new file mode 100644
index 0000000..4ea005b
--- /dev/null
+++ b/src/drawzero/examples/13_gradients.py
@@ -0,0 +1,17 @@
+from drawzero import *
+
+
+scale1 = Gradient([C.black, C.white], 0, 1000)
+for x in range(0, 1000, 10):
+ filled_rect(scale1(x), (x, 0), 10, 100)
+text(C.white, 'scale1 = Gradient([C.black, C.white], 0, 1000)', (50, 100), 48, '<^')
+
+scale2 = Gradient([C.green, C.yellow, C.magenta, C.red], 0, 1000)
+for x in range(0, 1000, 10):
+ filled_rect(scale2(x), (x, 200), 10, 100)
+text(C.white, 'scale2 = Gradient([C.green, C.yellow, C.magenta, C.red], 0, 1000)', (50, 300), 32, '<^')
+
+scale3 = Gradient([C.white, C.black, C.red, C.black, C.white], 200, 800)
+for x in range(0, 1000, 10):
+ filled_rect(scale3(x), (x, 400), 10, 100)
+text(C.white, 'scale3 = Gradient([C.white, C.black, C.red, C.black, C.white], 200, 800)', (50, 500), 32, '<^')
diff --git a/src/drawzero/examples/12_animation_close_vertex.py b/src/drawzero/examples/14_animation_close_vertex.py
similarity index 100%
rename from src/drawzero/examples/12_animation_close_vertex.py
rename to src/drawzero/examples/14_animation_close_vertex.py
diff --git a/src/drawzero/examples/13_animation_firework.py b/src/drawzero/examples/15_animation_firework.py
similarity index 100%
rename from src/drawzero/examples/13_animation_firework.py
rename to src/drawzero/examples/15_animation_firework.py
diff --git a/src/drawzero/examples/14_keyboard_and_mouse.py b/src/drawzero/examples/16_keyboard_and_mouse.py
similarity index 100%
rename from src/drawzero/examples/14_keyboard_and_mouse.py
rename to src/drawzero/examples/16_keyboard_and_mouse.py
diff --git a/src/drawzero/examples/15_mouse_tube.py b/src/drawzero/examples/17_mouse_tube.py
similarity index 73%
rename from src/drawzero/examples/15_mouse_tube.py
rename to src/drawzero/examples/17_mouse_tube.py
index 3291f28..b099381 100644
--- a/src/drawzero/examples/15_mouse_tube.py
+++ b/src/drawzero/examples/17_mouse_tube.py
@@ -2,7 +2,7 @@
circles = []
tick()
-scale = Gradient([C.gray10, C.white], 100, 500)
+scale = Gradient([C.gray10, C.blue, C.orange], 100, 500)
while True:
x, y = mouse_pos()
circles.append([x, y, 100])
@@ -12,7 +12,7 @@
if r > 1000:
circles.pop(i)
else:
- circle(scale(r), (x, y), r, line_width=1)
+ circle(scale(r), (x, y), r, line_width=3)
circles[i][2] += 10
fps()
tick()
diff --git a/src/drawzero/examples/16_game_stars.py b/src/drawzero/examples/18_game_stars.py
similarity index 99%
rename from src/drawzero/examples/16_game_stars.py
rename to src/drawzero/examples/18_game_stars.py
index fb75453..230dd2c 100644
--- a/src/drawzero/examples/16_game_stars.py
+++ b/src/drawzero/examples/18_game_stars.py
@@ -59,7 +59,7 @@ def draw_stars(stars):
screen_x = 500 + star.x / y
screen_y = 500 + star.z / y
screen_r = star.r / y
- filled_circle(star.color, (screen_x, screen_y), screen_r)
+ filled_circle(star.color, (screen_x, screen_y), screen_r*2)
text('white', 'Press WASD or QE to move', (500, 5), 48, '.^')
diff --git a/src/drawzero/examples/17_game_colors.py b/src/drawzero/examples/19_game_colors.py
similarity index 100%
rename from src/drawzero/examples/17_game_colors.py
rename to src/drawzero/examples/19_game_colors.py
diff --git a/src/drawzero/examples/18_game_racing.py b/src/drawzero/examples/20_game_racing.py
similarity index 100%
rename from src/drawzero/examples/18_game_racing.py
rename to src/drawzero/examples/20_game_racing.py
diff --git a/src/drawzero/examples/99_errors.py b/src/drawzero/examples/99_errors.py
new file mode 100644
index 0000000..9d78071
--- /dev/null
+++ b/src/drawzero/examples/99_errors.py
@@ -0,0 +1,40 @@
+import os
+import traceback
+import sys
+
+os.environ['EJUDGE_MODE'] = 'true'
+
+from drawzero import *
+
+filled_circle('boo')
+# line('nocolor', (100, 100), ('asdf',))
+circle('red', (100, 100), 'asd', line_width=0)
+
+
+class ExceptionPrinter:
+ def __enter__(self):
+ pass
+
+ def __exit__(self, exc_type, exc_value, exc_traceback):
+ if exc_traceback:
+ traceback_len = 0
+ cur = exc_traceback
+ while cur:
+ traceback_len += 1
+ cur = cur.tb_next
+ print(f'Traceback is {traceback_len} deep')
+ print(''.join(traceback.format_tb(exc_traceback)), end='')
+ print(exc_value)
+ return True
+
+
+# import drawzero
+# print(help(drawzero))
+# exit()
+#
+#
+s = ExceptionPrinter()
+
+with s: line('nocolor', (100, 100), (200, 200))
+with s: line(C.red, (100, 200), (200, 'baz'))
+with s: rect('violet', (100, 200, 300, 'baz'))