Skip to content

Commit

Permalink
Merge pull request #97 from Schulich-Ignite/dev
Browse files Browse the repository at this point in the history
v0.1.2 release
  • Loading branch information
AlphaRLee authored Feb 18, 2021
2 parents 6f08c0b + b978f51 commit 0ee7b2a
Show file tree
Hide file tree
Showing 9 changed files with 1,658 additions and 8 deletions.
Binary file added docs/img/rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/rotation_explanation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 39 additions & 1 deletion docs/utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,42 @@ def setup():

Results in:

![random demo](img/randint.png)
![random demo](img/randint.png)



### Rotation

![rotation explanation](rotation_explanation.png)

Transformations are always done to the **canvas**, not the individual shapes themselves. Rotation is done around the origin, point (0, 0) and affects all shapes drawn afterwards. You can use our built-in `pi` variable to express radians, or convert from degrees to radians by multiplying your number of degrees by `pi / 180`.

Note that canvas transformations are not removed automatically. In other words, if you want to rotate just one shape in your `draw()` function, you should rotate the canvas by `r` radians, draw your shape, and then rotate by `-r` radians to undo the effect.

To rotate the canvas clockwise around the origin, use:

```python
rotate(r)
```

**Parameters**

- r: (float) The angle, in radians to rotate the canvas

**Example(s):**

*Rotating a rectangle by 30 degrees clockwise*

```python hl_lines="6"
%%ignite

def setup():
size(300, 300)

rotate(pi / 6) # Rotate pi/6 radians (30 degrees) clockwise
rect(100, 0, 80, 50)
```

Results in:

![rotate demo](img/rotate.png)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="schulich-ignite",
version="0.1.1",
version="0.1.2",
author="Schulich Ignite",
author_email="info@shulichignite.com",
description="Spark library for Shulich Ignite sessions",
Expand Down
3 changes: 3 additions & 0 deletions spark/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ def clear(self, *args): pass
@extern
def background(self, *args): pass

@extern
def rotate(self, *args): pass

# From util.helper_functions.rect_functions

@extern
Expand Down
5 changes: 5 additions & 0 deletions spark/util/helper_functions/canvas_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ def helper_background(self, *args):
self.canvas.fill_style = fill
self.canvas.fill_rect(0, 0, self.width, self.height)
self.canvas.fill_style = old_fill

@validate_args([Real])
@ignite_global
def helper_rotate(self, *args):
self.canvas.rotate(args[0])
9 changes: 8 additions & 1 deletion spark/util/helper_functions/misc_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def helper_color(self, *args):
def helper_arc_args(self, *args):
argc = len(args)
x, y, w, h = args[:4]
w, h = abs(w), abs(h)
defaults = [0, 2*pi, "default"]
start, stop, mode = [*args[4:argc], *defaults[argc-4:]]
while start < 0:
Expand All @@ -72,9 +73,15 @@ def helper_arc_args(self, *args):
stop += 2*pi
while stop > 2*pi:
stop += 2*pi

d = max(w, h)/2
if d == 0:
return x, y, d, 0, 0, start, stop, mode
else:
w_ratio = w / d
h_ratio = h / d

return x, y, d/2, w/d, h/d, start, stop, mode
return x, y, d/2, w_ratio, h_ratio, start, stop, mode


@validate_args([])
Expand Down
466 changes: 461 additions & 5 deletions test/EllipseAndArcTest.ipynb

Large diffs are not rendered by default.

1,141 changes: 1,141 additions & 0 deletions test/RotateTest.ipynb

Large diffs are not rendered by default.

0 comments on commit 0ee7b2a

Please sign in to comment.