Skip to content

Commit 9120171

Browse files
authored
Merge pull request #6 from dylannalex/1.0.1
1.0.1
2 parents 6396424 + b0f760d commit 9120171

20 files changed

+282
-133
lines changed

README.md

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ Curvipy is a great tool for learning and teaching math with animations. In this
2323

2424
A function has been translated when it has been moved in a way that does not change its shape or rotate it in any way. A function can be translated either *vertically*, *horizontally*, or both.
2525

26-
To visualize translations, we will use the function $f(x) = x^{2}$, where $x \in [-15, 15]$.
26+
To visualize translations, we will use the function $f(x) = x^{2}$.
2727

2828
```python
2929
import curvipy
30-
import turtle
3130

3231

3332
def f(x):
@@ -38,20 +37,20 @@ plotter = curvipy.Plotter(x_axis_scale=50, y_axis_scale=20)
3837
interval = curvipy.Interval(start=-15, end=15, samples=45)
3938
plotter.plot_curve(curvipy.Function(f), interval)
4039

41-
turtle.exitonclick()
40+
plotter.wait()
4241
```
4342

4443
<p align="center">
4544
<img width="500" height="500" src="docs/source/img/function_x_squared.png">
4645
</p>
4746

47+
4848
### Horizontal Translation
4949

5050
In a horizontal translation, the function is moved along the x-axis.
5151

5252
```python
5353
import curvipy
54-
import turtle
5554

5655

5756
def f(x):
@@ -68,18 +67,19 @@ def m(x):
6867
return f(x + 3)
6968

7069

71-
plotter = curvipy.Plotter(x_axis_scale=50, y_axis_scale=20)
72-
interval = curvipy.Interval(start=-15, end=15, samples=45)
70+
plotter = curvipy.Plotter(x_axis_scale=50, y_axis_scale=20, plotting_speed=3)
7371
plotter.curve_color = "#FF7B61" # Red
72+
interval = curvipy.Interval(start=-2, end=7.5, samples=45)
7473
plotter.plot_curve(curvipy.Function(g), interval)
7574
plotter.curve_color = "#F061FF" # Purple
75+
interval = curvipy.Interval(start=-7.5, end=2, samples=45)
7676
plotter.plot_curve(curvipy.Function(m), interval)
7777

78-
turtle.exitonclick()
78+
plotter.wait()
7979
```
8080

8181
<p align="center">
82-
<img width="500" height="500" src="docs/source/img/horizontal_translation.png">
82+
<img width="500" height="500" src="docs/source/img/horizontal_translation.gif">
8383
</p>
8484

8585
### Vertical Translation
@@ -88,7 +88,6 @@ In a horizontal translation, the function is moved along the y-axis.
8888

8989
```python
9090
import curvipy
91-
import turtle
9291

9392

9493
def f(x):
@@ -105,18 +104,18 @@ def m(x):
105104
return f(x) + 3
106105

107106

108-
plotter = curvipy.Plotter(x_axis_scale=50, y_axis_scale=20)
109-
interval = curvipy.Interval(start=-15, end=15, samples=45)
107+
plotter = curvipy.Plotter(x_axis_scale=50, y_axis_scale=20, plotting_speed=3)
108+
interval = curvipy.Interval(start=-5, end=5, samples=45)
110109
plotter.curve_color = "#FF7B61" # Red
111110
plotter.plot_curve(curvipy.Function(g), interval)
112111
plotter.curve_color = "#F061FF" # Purple
113112
plotter.plot_curve(curvipy.Function(m), interval)
114113

115-
turtle.exitonclick()
114+
plotter.wait()
116115
```
117116

118117
<p align="center">
119-
<img width="500" height="500" src="docs/source/img/vertical_translation.png">
118+
<img width="500" height="500" src="docs/source/img/vertical_translation.gif">
120119
</p>
121120

122121
## Linear transformations
@@ -143,34 +142,39 @@ A =
143142
\end{bmatrix}
144143
$$
145144

146-
transforms the function $f(x) = sin(x)$.
145+
transforms the function $f(x) =\frac{x}{2}sin(x)$.
147146

148147
```python
149148
import math
150149
import curvipy
151-
import turtle
152150

153151

154-
curve = curvipy.Function(math.sin)
155-
interval = curvipy.Interval(-10, 10, 50)
156-
A = ((0, -1), (1, 0))
152+
def f(x):
153+
return x / 2 * math.sin(x)
154+
155+
157156
plotter = curvipy.Plotter(x_axis_scale=25, y_axis_scale=25)
157+
interval = curvipy.Interval(-15, 15, 250)
158158

159-
# Plot curve:
159+
# Plot curve f(x) = x/2 * sin(x):
160160
plotter.curve_color = "#FF7B61" # Red
161+
curve = curvipy.Function(f)
161162
plotter.plot_curve(curve, interval)
163+
162164
# Plot transformed curve:
163165
plotter.curve_color = "#457B9D" # Blue
164-
plotter.plot_curve(curvipy.TransformedCurve(A, curve), interval)
166+
A = ((0, -1), (1, 0))
167+
transformed_curve = curvipy.TransformedCurve(A, curve)
168+
plotter.plot_curve(transformed_curve, interval)
165169

166-
turtle.exitonclick() # Exits plotter on click
170+
plotter.wait()
167171
```
168172

169173
<p align="center">
170-
<img width="500" height="500" src="docs/source/img/transformation_matrix.png">
174+
<img width="500" height="500" src="docs/source/img/transformation_matrix.gif">
171175
</p>
172176

173-
As you can see above, the matrix $A$ rotates the function $f(x)$ 90° anticlockwise.
177+
As you can see above, the matrix $A$ rotates the function $f(x)$ ninety degree anticlockwise.
174178

175179
**Note:** `curvipy.TransformedCurve`
176180
matrix parameter has the same format as numpy arrays. In fact, you can directly use a numpy array.
@@ -197,25 +201,28 @@ B =
197201
\end{bmatrix}
198202
$$
199203

200-
201204
and see how they transform the curve $f(x) = x^{3}$.
202205

203206
```python
204207
import curvipy
205-
import turtle
206208

207209

208210
def f(x):
209211
return x**3
210212

211213

212-
curve = curvipy.Function(f)
213-
interval = curvipy.Interval(-10, 10, 70)
214-
plotter = curvipy.Plotter(x_axis_scale=25, y_axis_scale=25, curve_width=6)
214+
plotter = curvipy.Plotter(
215+
x_axis_scale=25,
216+
y_axis_scale=25,
217+
curve_width=6,
218+
plotting_speed=3,
219+
)
220+
interval = curvipy.Interval(-2.7, 2.7, 70)
215221

222+
# Define curves
216223
A = ((0, -1), (1, 0))
217224
B = ((1, 1), (0, 1))
218-
225+
curve = curvipy.Function(f)
219226
AB_transformed_curve = curvipy.TransformedCurve(A, curvipy.TransformedCurve(B, curve))
220227
BA_transformed_curve = curvipy.TransformedCurve(B, curvipy.TransformedCurve(A, curve))
221228

@@ -231,11 +238,11 @@ plotter.plot_curve(AB_transformed_curve, interval)
231238
plotter.curve_color = "#457B9D" # Blue
232239
plotter.plot_curve(BA_transformed_curve, interval)
233240

234-
turtle.exitonclick() # Exits plotter on click
241+
plotter.wait()
235242
```
236243

237244
<p align="center">
238-
<img width="500" height="500" src="docs/source/img/mat_multiplication_commutative_property.png">
245+
<img width="500" height="500" src="docs/source/img/mat_multiplication_commutative_property.gif">
239246
</p>
240247

241248
As you can see above, transforming $f(x)$ with the matrix $AB$ gives a different result as transforming $f(x)$ with the matrix $BA$.
@@ -257,4 +264,4 @@ AB_transformed_curve = curvipy.TransformedCurve(AB, curve)
257264
BA_transformed_curve = curvipy.TransformedCurve(BA, curve)
258265
```
259266

260-
You can learn more about Curvipy by visiting the [Documentation Page](https://curvipy.readthedocs.io/en/latest/).
267+
You can learn more about Curvipy by going through the [Documentation](documentation.md) section or by directly visiting Curvipy on [Github](https://github.com/dylannalex/curvipy) in order to check out the source code itself.

curvipy/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .plotter import *
2-
from .curve import *
3-
from .interval import *
4-
from .vector import *
1+
from ._plotter import *
2+
from ._curve import *
3+
from ._interval import *
4+
from ._vector import *

curvipy/curve.py renamed to curvipy/_curve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from abc import ABC as _ABC
33
from abc import abstractmethod as _abstractmethod
44

5-
from .interval import Interval as _Interval
5+
from ._interval import Interval as _Interval
66

77

88
_number = int | float

0 commit comments

Comments
 (0)