Skip to content
Snippets Groups Projects
Verified Commit 02aea1bd authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

add snippets for `src.ui.qtree`

parent 6d2e96d3
No related branches found
No related tags found
No related merge requests found
# `src.ui.maze`
Below are snippets that show how to define a maze and use the `src.ui.maze` module:
- import the library
......@@ -68,3 +69,50 @@ while True:
- _left click_ on two different maze cells to select them
- _right click_ to unselect all the cells
- _ENTER_ to run the path algorithm once the maze generation is done
# `src.ui.qtree`
Below are snippets that show how to define a maze and use the `src.ui.qtree` module:
- import the library
```python
from src.ui.qtree import Canva
```
- setup the canva
```python
canva = Canva(1600, 800, caption='', frame_rate=30)
canva.setup()
```
- create a bunch of points
```python
from random import random
canva.points = []
for _ in range(1000):
canva.points.append(Point(
randint(0, canva.width),
randint(0, canva.height),
3,
))
```
- run the animation
```python
# compute the new set of points, e.g. by moving them a bit randomly
def update(points: list) -> list:
return []
# gives back to the canva the things to show.
# it should be either
# - a list of booleans, one for each point, that indicates whether or not a
# point is colliding with others
# - a quad-tree and the query range
def f(points: list, mouse: (int, int)):
...
canva.loop(update, f)
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment