Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tim/frame rate #100

Merged
merged 21 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9a2d396
Added mouse_down(), mouse_is_pressed and mouse_up docs
Descent098 Nov 21, 2020
19fd246
Added info about mouse_down() and mouse_up() only firing once in draw…
Descent098 Nov 21, 2020
ccf5e61
Changes mousebutton to mouse button in docs
Descent098 Nov 21, 2020
eb0e2c8
Merge pull request #83 from Schulich-Ignite/mouse_docs
Descent098 Nov 24, 2020
3b1f6df
Merge pull request #91 from Schulich-Ignite/dev
AlphaRLee Nov 25, 2020
d36c23e
Bumped test run
AlphaRLee Feb 7, 2021
6f08c0b
Merge pull request #93 from Schulich-Ignite/bump_main
AlphaRLee Feb 7, 2021
0ee7b2a
Merge pull request #97 from Schulich-Ignite/dev
AlphaRLee Feb 18, 2021
2705f8a
Fixed rotation_explanation.png link
AlphaRLee Feb 18, 2021
1ea80fd
Added a FRAME_RATE variable to global_constants{}
tim-macphail Feb 23, 2021
43b4432
Added documentation mentioning the frame rate
tim-macphail Feb 28, 2021
3631226
Unit test for for frame rate
tim-macphail Feb 28, 2021
626bad0
Added FRAME_RATE variable
tim-macphail Feb 28, 2021
205e8c8
Merge branch 'main' of https://github.com/Schulich-Ignite/spark into …
tim-macphail Feb 28, 2021
38e6183
Merge branch 'dev' into tim/frame_rate
tim-macphail Mar 1, 2021
8fa33fe
Moved FrameRateTest.ipynb to the correct folder (test)
tim-macphail Mar 1, 2021
00356c5
Removed non-functional code
tim-macphail Mar 2, 2021
1e896e9
Just adjusted a comment
tim-macphail Mar 2, 2021
36b6aec
Cleaned up unit test for FRAME_RATE
tim-macphail Mar 8, 2021
a1b9122
Added FRAME_RATE docs
tim-macphail Mar 8, 2021
7d2cc28
Merged dev changes into branch, kept both changes
tim-macphail Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/img/mouse_down.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/mouse_is_pressed.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/mouse_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setup():
size(200, 200) # You can change 200, 200 to any integers
```

You can also use the draw() function, which will execute the code constantly that is inside it. This makes it ideal for things like animation, and any code that will update itself over time. **Most of the time this will be the setup you want**:
You can also use the draw() function, which will execute the code constantly that is inside it. The draw function executes 30 times per second. This makes it ideal for things like animation, and any code that will update itself over time. **Most of the time this will be the setup you want**:

```python
%%ignite
Expand Down
113 changes: 113 additions & 0 deletions docs/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,115 @@ which results in:

![Ask circle diameter](img/circle_radius.png){: loading=lazy }


### Check for mouse presses

Spark features multiple ways to check for user mouse presses:

| Name | Type | Description |
|---------------------------------------|-----------------------|-------------------------------------------------------------------------|
| [mouse_is_pressed](#mouse_is_pressed) | Variable | A boolean variable that is True when a mouse button is pressed |
| [mouse_down()](#mouse_down) | User defined function | A definable function that activates when a mouse button is pressed down |
| [mouse_up()](#mouse_up) | User defined function | A definable function that activates when a mouse button is released |

**Notes**

- All of these variables fire on **any** mouse button press (left mouse click, right mouse click, or scroll wheel click)
- Mouse events are only captured when the mouse is **inside** the canvas boundary


#### mouse_is_pressed
A boolean that is True when **any** mouse button is pressed

**Example(s):**

*Draw a square at the (mouse_x, mouse_y) position when the mouse is pressed*


```python hl_lines="7"
%%ignite
def setup():
background(255)
size(500,500)

def draw():
if mouse_is_pressed:
square(mouse_x, mouse_y, 45)
```

Results in:

![mouse_is_pressed example](img/mouse_is_pressed.png){: loading=lazy }

#### mouse_down()

```python
def mouse_down():
# Your code goes here
```

This is a user definable function that activates when **any** mouse button is pressed down.

##### Notes

- This function is handy when you want to do something in a ```#!python draw()``` loop **one time** on mouse press. ```#!python mouse_is_pressed``` will constantly fire in a ```#!python draw()``` loop, whereas ```#!python mouse_down()``` will fire once per event

Example(s):

*Print "Mouse Button Pressed Down" if a mouse button is pressed down*

```python hl_lines="9 10"
%%ignite

def setup():
size(200, 200)

def draw():
... # Does nothing

def mouse_down():
print("Mouse Button Pressed Down")
```

Results in:

![mouse_down() example](img/mouse_down.png){: loading=lazy }


#### mouse_up()

```python
def mouse_up():
# Your code goes here
```

This is a user definable function that activates when **any** mouse button is released after being pressed down.

##### Notes

- This function is handy when you want to do something in a ```#!python draw()``` loop **one time** on mouse release. ```#!python mouse_is_pressed``` will constantly fire in a ```#!python draw()``` loop, whereas ```#!python mouse_up()``` will fire once per event

Example(s):

*Print "Mouse Button Released" if a mouse button is released after being pressed down*

```python hl_lines="9 10"
%%ignite

def setup():
size(200, 200)

def draw():
... # Does nothing

def mouse_up():
print("Mouse Button Released")
```

Results in:

![mouse_up() example](img/mouse_up.png){: loading=lazy }

### Check for key presses

Spark features multiple ways to check for user key presses:
Expand All @@ -120,6 +229,10 @@ Spark features multiple ways to check for user key presses:
| [key_released()](#key_released) | User defined function | A definable function that activates when any key is released |
| [key_repeated()](#key_repeated) | User defined function | A definable function that activates when any key is held |

**Notes**

- Key events **only** trigger when the mouse is **inside** the canvas

#### key

A string that is the last key event (a key being pressed, released, or held down). So for example if you press, hold or release ++shift++ then `#!python key == "Shift"`.
Expand Down
2 changes: 1 addition & 1 deletion docs/utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Results in:

### Rotation

![rotation explanation](rotation_explanation.png)
![rotation explanation](img/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`.

Expand Down
6 changes: 6 additions & 0 deletions spark/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ def height(self, val):
self._globals_dict["height"] = val
self.canvas.height = val

@property
@ignite_global
def FRAME_RATE(self):
return FRAME_RATE


### Library init ###

# Updates last activity time
Expand Down
Loading