Skip to content

Commit 6538379

Browse files
committed
Various updates and additions
1 parent fc50259 commit 6538379

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+59664
-58
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*.pyc
77
build/
88
dist/
9+
_unused
10+
test.py
11+
templates/
12+
libraylib_shared_no9patch.dll
13+
libraylib_shared_pre9patch.dll
914
*.egg-info/
1015
*.egg
1116
*.py[cod]

LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018 Jorge A. Gomes
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

MANIFEST.in

Whitespace-only changes.

README.md

Lines changed: 153 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ More about raylib can be found at its [repository](https://github.com/raisan5/ra
88
and/or [website](https://www.raylib.com).
99

1010

11-
##features
11+
## features
1212
* **NO external dependencies**, all required libraries included with raylib.
1313
* Multiple platforms supported: **Window, MacOS, Android... and many more!**
1414
* Hardware accelerated with OpenGL (**1.1, 2.1, 3.3 or ES 2.0**)
@@ -48,18 +48,156 @@ More information on how to build raylib can be found in the [raylib wiki pages](
4848

4949
## raylib vs raylibpy
5050

51-
Except for the naming conventions and data types (names and convertions), theres no
52-
significative differences between raylib and raylibpy. At the moment, only bytes
53-
are accepted as string arguments, no implicit convertion is made between integers and
54-
floats. Some of the refinements to be done are exposed below:
55-
56-
| Expects or returns | Accepts/returns only | Will accept/return |
57-
| ------- | ------- | ------- |
58-
| `const char *` | `bytes` (ASCII) | `str` (unicode) |
59-
| `const char **` | `CharPtrPtr` | `List[str]` |
60-
| `int` | `int` | `float` |
61-
| `float` | `float` | `int` |
62-
| `int*` as argument | `IntPtr` as argument | `int` as return, if omitted as argument |
63-
| `Vector3` | `Vector3` | `Tuple[float, float, float]` or `List[float]` |
64-
| `Vector3 *` | `Vector3Ptr` as `byref(instance)` | array, sequence or `bytes` |
51+
### Constant values
52+
53+
All C `#define`s and `enum`s got translated to Python 'constants'. Enums may, in the future,
54+
be converted to Python [enums](https://docs.python.org/3/library/enum.html), if
55+
`ctypes` allows it.
56+
57+
### Structures
58+
59+
#### In general
60+
61+
All structures inherit from `ctypes.Structure` class. Unlike functions, constructors require
62+
the exact argument types, so `int`s can't be passed where `float`s are expected (although the
63+
argument can be omitted):
64+
65+
```python
66+
# ways of creating a Vector3 instance:
67+
vec_a = Vector3()
68+
vec_b = Vector3(0., 1., 0.)
69+
vec_c = Vector3.one()
70+
71+
# the following will raise an exception:
72+
vec_d = Vector3(10, 0, 100)
73+
```
74+
75+
All structures have `__str__()` implemented, so they have a very basic textual representation:
76+
```python
77+
# Define the camera to look into our 3d world
78+
>>> camera = Camera()
79+
>>> camera.position = Vector3(5., 4., 5.)
80+
>>> camera.target = Vector3(0., 2., 0.)
81+
>>> camera.up = Vector3(0., 1., 0.)
82+
>>> camera.fovy = 45.0
83+
>>> camera.type = CAMERA_PERSPECTIVE
84+
>>> camera
85+
"(CAMERA3D: position: (5.0, 4.0, 5.0), target: (0.0, 2.0, 0.0), up: (0.0, 1.0, 0.0), fovy: 45.0°, type: PERSPECTIVE)"
86+
```
87+
Not all information is exposed, though. Mesh objects, for example, exposes only the
88+
vertex and triangle count attributes.
89+
90+
91+
#### Vectors
92+
93+
Vector2, Vector3 and Vector4 support basic aritmetic operations: addiction, subtraction,
94+
multiplication (incluiding scalar multiplication), division and modulo. Augmented
95+
assignment is also supported; the right hand side operand can be any sequence of same
96+
number of components:
97+
98+
```python
99+
>>> vec_a = Vector3(3., 5., 7.)
100+
>>> vec_b = Vector3(4., 2., 0.)
101+
>>> vec_a * vec_b
102+
"(12.0, 10.0, 0.0)"
103+
>>> vec_a + (8, 100, -1)
104+
"(11.0, 105.0, 6.0)"
105+
>>> vec_a %= 2
106+
>>> vec_a
107+
"(1.0, 1.0, 1.0)"
108+
```
109+
110+
Vectors have also a feature that tries to emulate the GLSL vector swizzling, but
111+
its done through subscription:
112+
```python
113+
>>> vec_a = Vector4(10.0, 20.0, 50.0, 1.0)
114+
>>> # create a Vector2 from it:
115+
...
116+
>>> vec_b = vec_a['xy']
117+
>>> vec_b
118+
"(10.0, 20.0)"
119+
>>> # create a Vector3 from it, setting 1.0 to the z axis:
120+
...
121+
>>> vec_c = vec_b['xy1']
122+
>>> vec_c
123+
"(10.0, 20.0, 0.0)"
124+
>>> # another Vector2, perpendicular to vec_b:
125+
...
126+
>>> vec_d = vec_b['Yx']
127+
>>> vec_d
128+
"(-20.0, 10.0)"
129+
>>> # a Vector4 from the y axis:
130+
...
131+
>>> vec_e = vec_b['yyyy']
132+
>>> # vec_d with signs flipped:
133+
...
134+
>>> vec_d['XY']
135+
"(20.0, -10.0)"
136+
>>> # moving vec_a in the y axis by one:
137+
...
138+
>>> vec_a += vec_a['0010']
139+
```
140+
That's not all! Other component-wise operations (or tricks) can be made this way (note,
141+
though that these operators apply in positional fashion):
142+
```python
143+
>>> vec_a = Vector3(-10.0, 20.5, 15.840)
144+
>>> # divide all components by 2:
145+
...
146+
>>> vec_a['///']
147+
"(-5.0, 10.25, 7.920)"
148+
>>>
149+
>>>
150+
>>> # multiply all components by 2:
151+
...
152+
>>> vec_a['***']
153+
"(-20.0, 41.0, 31.680)"
154+
>>>
155+
>>>
156+
>>> # all components raised to the power of 2:
157+
...
158+
>>> vec_a['^^^']
159+
"(-1e-10, 7.779544182561597e+26, 1.0095364584490473e+19)"
160+
>>>
161+
>>>
162+
>>> # inverse of all components (1/x):
163+
...
164+
>>> vec_a['...']
165+
"(-0.1, 0.04878048780487805, 0.06313131313131314)"
166+
>>>
167+
>>>
168+
>>> # sign of components (-1 if < 0, 1 if > 0, 0 otherwise):
169+
...
170+
>>> vec_a['+++']
171+
"(-1.0, 1.0, 1.0)"
172+
>>>
173+
>>>
174+
>>> # nonzero components (1 if != 0, 0 otherwise):
175+
...
176+
>>> vec_a['???']
177+
"(1.0, 1.0, 1.0)"
178+
>>>
179+
>>>
180+
>>> # the component of vec_a with largest value:
181+
...
182+
>>> vec_a['>>>']
183+
"(15.840, 15.840, 15.840)"
184+
>>>
185+
>>>
186+
>>> # the component of vec_a with smallest value:
187+
...
188+
>>> vec_a['<<<']
189+
"(-10.0, -10.0, -10.0)"
190+
>>>
191+
>>>
192+
>>> # component values rounded:
193+
...
194+
>>> vec_a['###']
195+
"(-10.0, 20.0, 15.0)"
196+
>>>
197+
>>>
198+
>>> # fractional part of component values:
199+
...
200+
>>> vec_a['%%%']
201+
"(0.0, 0.5, 0.840)"
202+
```
65203

examples/__init__.py

Whitespace-only changes.

examples/core/__init__.py

Whitespace-only changes.

examples/core/core_basic_window.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# core_basic_window.py
2-
import raylibpy as rl
2+
3+
from raylibpy import *
34

45

56
def main():
67

7-
rl.init_window(800, 450, "raylib [core] example - basic window")
8+
init_window(800, 450, "raylib [core] example - basic window")
89

9-
rl.set_target_fps(60)
10+
set_target_fps(60)
1011

11-
while not rl.window_should_close():
12+
while not window_should_close():
1213

13-
rl.begin_drawing()
14-
rl.clear_background(rl.RAYWHITE)
15-
rl.draw_text("Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY)
16-
rl.end_drawing()
14+
begin_drawing()
15+
clear_background(RAYWHITE)
16+
draw_text("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY)
17+
end_drawing()
1718

18-
rl.close_window()
19+
close_window()
1920

2021

2122
if __name__ == '__main__':

examples/core/core_color_select.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ def main():
1717
color_rects: List[Rectangle] = []
1818

1919
for i in range(21):
20+
y, x = divmod(i, 7)
2021
rect = Rectangle(
21-
20 + 100 * (i % 7) + 10 * (i % 7),
22-
60 + 100 * (i / 7) + 10 * (i / 7),
22+
20 + 110 * x,
23+
60 + 110 * y,
2324
100,
2425
100
2526
)
27+
print(rect)
2628
color_rects.append(rect)
2729

2830
selected: List[bool] = [False for i in range(21)]
29-
mouse_point: Vector2.zero()
31+
mouse_point: Vector2
3032

3133
set_target_fps(60)
3234

examples/core/core_input_keys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def main():
1818
if is_key_down(KEY_RIGHT):
1919
ball_position.x += 2.0
2020
if is_key_down(KEY_LEFT):
21-
ball_position.x += 2.0
21+
ball_position.x -= 2.0
2222
if is_key_down(KEY_UP):
23-
ball_position.y += 2.0
23+
ball_position.y -= 2.0
2424
if is_key_down(KEY_DOWN):
2525
ball_position.y += 2.0
2626

examples/core/resources/ps3.png

18.9 KB
Loading

0 commit comments

Comments
 (0)