aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AutopyExtended/Curve/Bezier.py (renamed from AutopyExtended/Curve/CurveBezier.py)15
-rw-r--r--AutopyExtended/Curve/Linear.py (renamed from AutopyExtended/Curve/CurveLinear.py)2
-rw-r--r--AutopyExtended/Curve/__init__.py0
-rw-r--r--AutopyExtended/Curve/test.py55
-rw-r--r--AutopyExtended/__init__.py0
-rw-r--r--AutopyExtended/mouse.py10
-rw-r--r--README.md0
-rwxr-xr-xsetup.py9
-rw-r--r--test_bezier.py (renamed from AutopyExtended/Curve/test1.py)4
-rw-r--r--test_move.py5
10 files changed, 29 insertions, 71 deletions
diff --git a/AutopyExtended/Curve/CurveBezier.py b/AutopyExtended/Curve/Bezier.py
index 4aedb9d..ab79ec0 100644
--- a/AutopyExtended/Curve/CurveBezier.py
+++ b/AutopyExtended/Curve/Bezier.py
@@ -1,6 +1,6 @@
import numpy as np
-from Curve import Curve
+from AutopyExtended.Curve.Curve import Curve
from scipy.special import comb
class CurveBezier(Curve):
@@ -13,14 +13,11 @@ class CurveBezier(Curve):
self.__x = np.flip(np.dot(x, poly))
self.__y = np.flip(np.dot(y, poly))
- def point(self, t, t_target=None):
- if(t_target == None):
- t_target = self.__tn
- if(t_target != self.__tn):
- raise ValueError("t_target must be equal to tn.")
- return np.add((self.__x[int(np.floor(t))], self.__y[int(np.floor(t))]),
- np.subtract((self.__x[int(np.ceil(t))], self.__y[int(np.ceil(t))]),
- (self.__x[int(np.floor(t))], self.__y[int(np.floor(t))])) * (t - np.floor(t)))
+ def point(self, t, t_target):
+ t_scaled = min([t * self.__tn / t_target, self.__tn - 1])
+ return np.add((self.__x[int(np.floor(t_scaled))], self.__y[int(np.floor(t_scaled))]),
+ np.subtract((self.__x[int(np.ceil(t_scaled))], self.__y[int(np.ceil(t_scaled))]),
+ (self.__x[int(np.floor(t_scaled))], self.__y[int(np.floor(t_scaled))])) * (t_scaled - np.floor(t_scaled)))
@staticmethod
def bernstein(i, n, t):
diff --git a/AutopyExtended/Curve/CurveLinear.py b/AutopyExtended/Curve/Linear.py
index bee70cc..f35c095 100644
--- a/AutopyExtended/Curve/CurveLinear.py
+++ b/AutopyExtended/Curve/Linear.py
@@ -1,5 +1,5 @@
import numpy as np
-import Curve
+from AutopyExtended.Curve.Curve import Curve
class CurveLinear(Curve):
def __init__(self, start, end):
diff --git a/AutopyExtended/Curve/__init__.py b/AutopyExtended/Curve/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/AutopyExtended/Curve/__init__.py
diff --git a/AutopyExtended/Curve/test.py b/AutopyExtended/Curve/test.py
deleted file mode 100644
index ab9ee6c..0000000
--- a/AutopyExtended/Curve/test.py
+++ /dev/null
@@ -1,55 +0,0 @@
-import numpy as np
-from scipy.special import comb
-
-def bernstein_poly(i, n, t):
- """
- The Bernstein polynomial of n, i as a function of t
- """
-
- return comb(n, i) * ( t**(n-i) ) * (1 - t)**i
-
-
-
-def bezier_curve(points, nTimes=1000):
- """
- Given a set of control points, return the
- bezier curve defined by the control points.
- points should be a list of lists, or list of tuples
- such as [ [1,1],
- [2,3],
- [4,5], ..[Xn, Yn] ]
- nTimes is the number of time steps, defaults to 1000
- See http://processingjs.nihongoresources.com/bezierinfo/
- """
-
- nPoints = len(points)
- xPoints = np.array([p[0] for p in points])
- yPoints = np.array([p[1] for p in points])
-
- t = np.linspace(0.0, 1.0, nTimes)
-
- polynomial_array = np.array([ bernstein_poly(i, nPoints-1, t) for i in range(0, nPoints) ])
-
- xvals = np.dot(xPoints, polynomial_array)
- yvals = np.dot(yPoints, polynomial_array)
-
- return xvals, yvals
-
-
-
-if __name__ == "__main__":
- from matplotlib import pyplot as plt
-
- nPoints = 4
- points = np.random.rand(nPoints,2)*200
- xpoints = [p[0] for p in points]
- ypoints = [p[1] for p in points]
-
- xvals, yvals = bezier_curve(points, nTimes=1000)
- plt.plot(xvals, yvals)
- plt.plot(xpoints, ypoints, "ro")
- for nr in range(len(points)):
- plt.text(points[nr][0], points[nr][1], nr)
-
-
- plt.show()
diff --git a/AutopyExtended/__init__.py b/AutopyExtended/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/AutopyExtended/__init__.py
diff --git a/AutopyExtended/mouse.py b/AutopyExtended/mouse.py
index 0b06c11..f79255f 100644
--- a/AutopyExtended/mouse.py
+++ b/AutopyExtended/mouse.py
@@ -1,4 +1,10 @@
import autopy
+import time
-def move(target, time, curve, time_scale=(lambda x : 1 * x)):
-
+def move(curve, time_target, time_scale=(lambda x : 1 * x)):
+ start = time.time()
+ delta = 0
+ while(delta < time_target):
+ point = curve.point(time_scale(delta), time_target)
+ autopy.mouse.move(point[0], point[1])
+ delta = time.time() - start
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README.md
diff --git a/setup.py b/setup.py
index e942c1f..6158a2d 100755
--- a/setup.py
+++ b/setup.py
@@ -20,10 +20,15 @@ setuptools.setup(
],
python_requires = '>=3.6',
install_requires = [
- "autopy"
+ "autopy",
+ "numpy",
+ "scipy"
],
py_modules = [
- "AutopyExtended/"
+ "AutopyExtended/Curve/Curve",
+ "AutopyExtended/Curve/Linear",
+ "AutopyExtended/Curve/Bezier"
+ "AutopyExtended/mouse"
],
scripts = []
)
diff --git a/AutopyExtended/Curve/test1.py b/test_bezier.py
index 05f56d8..83694be 100644
--- a/AutopyExtended/Curve/test1.py
+++ b/test_bezier.py
@@ -1,8 +1,8 @@
import matplotlib.pyplot as plot
from CurveBezier import CurveBezier
-curve = CurveBezier([(0,0),(53,178),(5,87),(140,75),(48,647),(37,49)],1000)
-points = [curve.point(t) for t in range(0,1000)]
+curve = CurveBezier([(0,0),(53,178),(5,87),(140,75),(48,647),(37,49)],10)
+points = [curve.point(t, 1000) for t in range(0,1000)]
x = [p[0] for p in points]
y = [p[1] for p in points]
plot.scatter(x,y)
diff --git a/test_move.py b/test_move.py
new file mode 100644
index 0000000..ea24e93
--- /dev/null
+++ b/test_move.py
@@ -0,0 +1,5 @@
+from AutopyExtended.Curve.Bezier import CurveBezier
+import AutopyExtended.mouse as mouse
+
+curve = CurveBezier([(0,0),(53,178),(5,87),(140,75),(48,647),(37,49)],1000)
+mouse.move(curve, 1)