kraken-engine 1.2.1__cp313-cp313-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kraken_engine-1.2.1.dist-info/METADATA +53 -0
- kraken_engine-1.2.1.dist-info/RECORD +27 -0
- kraken_engine-1.2.1.dist-info/WHEEL +6 -0
- kraken_engine-1.2.1.dist-info/licenses/LICENSE +21 -0
- pykraken/__init__.py +2 -0
- pykraken/__init__.pyi +513 -0
- pykraken/__pyinstaller/hook-pykraken.py +8 -0
- pykraken/_core/__init__.pyi +4137 -0
- pykraken/_core/collision.pyi +283 -0
- pykraken/_core/color.pyi +113 -0
- pykraken/_core/draw.pyi +95 -0
- pykraken/_core/ease.pyi +285 -0
- pykraken/_core/event.pyi +15 -0
- pykraken/_core/gamepad.pyi +105 -0
- pykraken/_core/input.pyi +78 -0
- pykraken/_core/key.pyi +73 -0
- pykraken/_core/line.pyi +10 -0
- pykraken/_core/math.pyi +184 -0
- pykraken/_core/mouse.pyi +85 -0
- pykraken/_core/rect.pyi +93 -0
- pykraken/_core/renderer.pyi +74 -0
- pykraken/_core/time.pyi +75 -0
- pykraken/_core/transform.pyi +141 -0
- pykraken/_core/window.pyi +113 -0
- pykraken/_core.cpython-313-darwin.so +0 -0
- pykraken/shader_uniform.py +55 -0
- pykraken/shader_uniform.pyi +59 -0
pykraken/_core/math.pyi
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Math related functions
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
import pykraken._core
|
|
6
|
+
import typing
|
|
7
|
+
__all__: list[str] = ['angle_between', 'clamp', 'cross', 'dot', 'from_polar', 'lerp', 'normalize', 'remap', 'rotate', 'scale_to_length', 'to_deg', 'to_rad']
|
|
8
|
+
def angle_between(a: pykraken._core.Vec2, b: pykraken._core.Vec2) -> float:
|
|
9
|
+
"""
|
|
10
|
+
Calculate the angle between two vectors.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
a (Vec2): The first vector.
|
|
14
|
+
b (Vec2): The second vector.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
float: The angle between the vectors in radians [0, π].
|
|
18
|
+
"""
|
|
19
|
+
@typing.overload
|
|
20
|
+
def clamp(vec: pykraken._core.Vec2, min_vec: pykraken._core.Vec2, max_vec: pykraken._core.Vec2) -> pykraken._core.Vec2:
|
|
21
|
+
"""
|
|
22
|
+
Clamp a vector between two boundary vectors.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
vector (Vec2): The vector to clamp.
|
|
26
|
+
min_vec (Vec2): The minimum boundary vector.
|
|
27
|
+
max_vec (Vec2): The maximum boundary vector.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
Vec2: A new vector with components clamped between min and max.
|
|
31
|
+
"""
|
|
32
|
+
@typing.overload
|
|
33
|
+
def clamp(value: typing.SupportsFloat, min_val: typing.SupportsFloat, max_val: typing.SupportsFloat) -> float:
|
|
34
|
+
"""
|
|
35
|
+
Clamp a value between two boundaries.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
value (float): The value to clamp.
|
|
39
|
+
min_val (float): The minimum boundary.
|
|
40
|
+
max_val (float): The maximum boundary.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
float: The clamped value.
|
|
44
|
+
"""
|
|
45
|
+
def cross(a: pykraken._core.Vec2, b: pykraken._core.Vec2) -> float:
|
|
46
|
+
"""
|
|
47
|
+
Calculate the 2D cross product of two vectors.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
a (Vec2): The first vector.
|
|
51
|
+
b (Vec2): The second vector.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
float: The 2D cross product (a.x * b.y - a.y * b.x).
|
|
55
|
+
"""
|
|
56
|
+
def dot(a: pykraken._core.Vec2, b: pykraken._core.Vec2) -> float:
|
|
57
|
+
"""
|
|
58
|
+
Calculate the dot product of two vectors.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
a (Vec2): The first vector.
|
|
62
|
+
b (Vec2): The second vector.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
float: The dot product (a.x * b.x + a.y * b.y).
|
|
66
|
+
"""
|
|
67
|
+
@typing.overload
|
|
68
|
+
def from_polar(angle: typing.SupportsFloat, radius: typing.SupportsFloat) -> pykraken._core.Vec2:
|
|
69
|
+
"""
|
|
70
|
+
Convert polar coordinates to a Cartesian vector.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
angle (float): The angle in radians.
|
|
74
|
+
radius (float): The radius/distance from origin.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
Vec2: The equivalent Cartesian vector.
|
|
78
|
+
"""
|
|
79
|
+
@typing.overload
|
|
80
|
+
def from_polar(polar: pykraken._core.PolarCoordinate) -> pykraken._core.Vec2:
|
|
81
|
+
"""
|
|
82
|
+
Convert a PolarCoordinate object to a Cartesian vector.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
polar (PolarCoordinate): The polar coordinate to convert.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
Vec2: The equivalent Cartesian vector.
|
|
89
|
+
"""
|
|
90
|
+
@typing.overload
|
|
91
|
+
def lerp(a: pykraken._core.Vec2, b: pykraken._core.Vec2, t: typing.SupportsFloat) -> pykraken._core.Vec2:
|
|
92
|
+
"""
|
|
93
|
+
Linearly interpolate between two Vec2s.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
a (Vec2): The start vector.
|
|
97
|
+
b (Vec2): The end vector.
|
|
98
|
+
t (float): The interpolation factor [0.0, 1.0].
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
Vec2: The interpolated vector.
|
|
102
|
+
"""
|
|
103
|
+
@typing.overload
|
|
104
|
+
def lerp(a: typing.SupportsFloat, b: typing.SupportsFloat, t: typing.SupportsFloat) -> float:
|
|
105
|
+
"""
|
|
106
|
+
Linearly interpolate between two values.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
a (float): The start value.
|
|
110
|
+
b (float): The end value.
|
|
111
|
+
t (float): The interpolation factor [0.0, 1.0].
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
float: The interpolated value.
|
|
115
|
+
"""
|
|
116
|
+
def normalize(vec: pykraken._core.Vec2) -> pykraken._core.Vec2:
|
|
117
|
+
"""
|
|
118
|
+
Normalize a vector to unit length.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
vector (Vec2): The input vector.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
Vec2: A new normalized vector.
|
|
125
|
+
"""
|
|
126
|
+
def remap(in_min: typing.SupportsFloat, in_max: typing.SupportsFloat, out_min: typing.SupportsFloat, out_max: typing.SupportsFloat, value: typing.SupportsFloat) -> float:
|
|
127
|
+
"""
|
|
128
|
+
Remap a value from one range to another.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
in_min (float): Input range minimum.
|
|
132
|
+
in_max (float): Input range maximum.
|
|
133
|
+
out_min (float): Output range minimum.
|
|
134
|
+
out_max (float): Output range maximum.
|
|
135
|
+
value (float): The value to remap.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
float: The remapped value in the output range.
|
|
139
|
+
|
|
140
|
+
Raises:
|
|
141
|
+
ValueError: If in_min equals in_max.
|
|
142
|
+
"""
|
|
143
|
+
def rotate(vec: pykraken._core.Vec2, radians: typing.SupportsFloat) -> pykraken._core.Vec2:
|
|
144
|
+
"""
|
|
145
|
+
Rotate a vector by the given angle (non-mutating).
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
vec (Vec2): The vector to rotate.
|
|
149
|
+
radians (float): Angle in radians.
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
Vec2: A new rotated vector.
|
|
153
|
+
"""
|
|
154
|
+
def scale_to_length(vector: pykraken._core.Vec2, length: typing.SupportsFloat) -> pykraken._core.Vec2:
|
|
155
|
+
"""
|
|
156
|
+
Scale a vector to a given length.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
vector (Vec2): The input vector.
|
|
160
|
+
length (float): The target length.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
Vec2: A new vector scaled to the specified length.
|
|
164
|
+
"""
|
|
165
|
+
def to_deg(radians: typing.SupportsFloat) -> float:
|
|
166
|
+
"""
|
|
167
|
+
Convert radians to degrees.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
radians (float): The angle in radians.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
float: The angle in degrees.
|
|
174
|
+
"""
|
|
175
|
+
def to_rad(degrees: typing.SupportsFloat) -> float:
|
|
176
|
+
"""
|
|
177
|
+
Convert degrees to radians.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
degrees (float): The angle in degrees.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
float: The angle in radians.
|
|
184
|
+
"""
|
pykraken/_core/mouse.pyi
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Mouse related functions
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
import pykraken._core
|
|
6
|
+
__all__: list[str] = ['get_pos', 'get_rel', 'hide', 'is_hidden', 'is_just_pressed', 'is_just_released', 'is_locked', 'is_pressed', 'lock', 'show', 'unlock']
|
|
7
|
+
def get_pos() -> pykraken._core.Vec2:
|
|
8
|
+
"""
|
|
9
|
+
Get the current position of the mouse cursor.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
tuple[float, float]: The current mouse position as (x, y) coordinates.
|
|
13
|
+
"""
|
|
14
|
+
def get_rel() -> pykraken._core.Vec2:
|
|
15
|
+
"""
|
|
16
|
+
Get the relative mouse movement since the last frame.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
tuple[float, float]: The relative movement of the mouse as (dx, dy).
|
|
20
|
+
"""
|
|
21
|
+
def hide() -> None:
|
|
22
|
+
"""
|
|
23
|
+
Hide the mouse cursor from view.
|
|
24
|
+
|
|
25
|
+
The cursor will be invisible but mouse input will still be tracked.
|
|
26
|
+
"""
|
|
27
|
+
def is_hidden() -> bool:
|
|
28
|
+
"""
|
|
29
|
+
Check if the mouse cursor is currently hidden.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
bool: True if the cursor is hidden.
|
|
33
|
+
"""
|
|
34
|
+
def is_just_pressed(button: pykraken._core.MouseButton) -> bool:
|
|
35
|
+
"""
|
|
36
|
+
Check if a mouse button was pressed this frame.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
button (MouseButton): The mouse button to check.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
bool: True if the button was just pressed.
|
|
43
|
+
"""
|
|
44
|
+
def is_just_released(button: pykraken._core.MouseButton) -> bool:
|
|
45
|
+
"""
|
|
46
|
+
Check if a mouse button was released this frame.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
button (MouseButton): The mouse button to check.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
bool: True if the button was just released.
|
|
53
|
+
"""
|
|
54
|
+
def is_locked() -> bool:
|
|
55
|
+
"""
|
|
56
|
+
Check if the mouse is currently locked to the window.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
bool: True if the mouse is locked.
|
|
60
|
+
"""
|
|
61
|
+
def is_pressed(button: pykraken._core.MouseButton) -> bool:
|
|
62
|
+
"""
|
|
63
|
+
Check if a mouse button is currently pressed.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
button (MouseButton): The mouse button to check (e.g., kn.MOUSE_LEFT).
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
bool: True if the button is currently pressed.
|
|
70
|
+
"""
|
|
71
|
+
def lock() -> None:
|
|
72
|
+
"""
|
|
73
|
+
Lock the mouse to the center of the window.
|
|
74
|
+
|
|
75
|
+
Useful for first-person controls where you want to capture mouse movement
|
|
76
|
+
without letting the cursor leave the window area.
|
|
77
|
+
"""
|
|
78
|
+
def show() -> None:
|
|
79
|
+
"""
|
|
80
|
+
Show the mouse cursor if it was hidden.
|
|
81
|
+
"""
|
|
82
|
+
def unlock() -> None:
|
|
83
|
+
"""
|
|
84
|
+
Unlock the mouse from the window, allowing it to move freely.
|
|
85
|
+
"""
|
pykraken/_core/rect.pyi
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Rectangle related functions
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
import pykraken._core
|
|
6
|
+
import typing
|
|
7
|
+
__all__: list[str] = ['clamp', 'move', 'scale_by', 'scale_to']
|
|
8
|
+
@typing.overload
|
|
9
|
+
def clamp(rect: pykraken._core.Rect, min: pykraken._core.Vec2, max: pykraken._core.Vec2) -> pykraken._core.Rect:
|
|
10
|
+
"""
|
|
11
|
+
Clamp a rectangle to be within the specified bounds.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
rect (Rect): The rectangle to clamp.
|
|
15
|
+
min (Vec2): The minimum bounds as (min_x, min_y).
|
|
16
|
+
max (Vec2): The maximum bounds as (max_x, max_y).
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
Rect: A new rectangle clamped within the bounds.
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
ValueError: If min >= max or rectangle is larger than the clamp area.
|
|
23
|
+
"""
|
|
24
|
+
@typing.overload
|
|
25
|
+
def clamp(rect: pykraken._core.Rect, other: pykraken._core.Rect) -> pykraken._core.Rect:
|
|
26
|
+
"""
|
|
27
|
+
Clamp a rectangle to be within another rectangle.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
rect (Rect): The rectangle to clamp.
|
|
31
|
+
other (Rect): The rectangle to clamp within.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Rect: A new rectangle clamped within the other rectangle.
|
|
35
|
+
|
|
36
|
+
Raises:
|
|
37
|
+
ValueError: If rect is larger than the clamp area.
|
|
38
|
+
"""
|
|
39
|
+
def move(rect: pykraken._core.Rect, offset: pykraken._core.Vec2) -> pykraken._core.Rect:
|
|
40
|
+
"""
|
|
41
|
+
Move a rectangle by the given offset.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
rect (Rect): The rectangle to move.
|
|
45
|
+
offset (Vec2): The offset to move by as (dx, dy).
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Rect: A new rectangle moved by the offset.
|
|
49
|
+
"""
|
|
50
|
+
@typing.overload
|
|
51
|
+
def scale_by(rect: pykraken._core.Rect, factor: typing.SupportsFloat) -> pykraken._core.Rect:
|
|
52
|
+
"""
|
|
53
|
+
Scale a rectangle by a uniform factor.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
rect (Rect): The rectangle to scale.
|
|
57
|
+
factor (float): The scaling factor (must be > 0).
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
Rect: A new rectangle scaled by the factor.
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
ValueError: If factor is <= 0.
|
|
64
|
+
"""
|
|
65
|
+
@typing.overload
|
|
66
|
+
def scale_by(rect: pykraken._core.Rect, factor: pykraken._core.Vec2) -> pykraken._core.Rect:
|
|
67
|
+
"""
|
|
68
|
+
Scale a rectangle by different factors for width and height.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
rect (Rect): The rectangle to scale.
|
|
72
|
+
factor (Vec2): The scaling factors as (scale_x, scale_y).
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Rect: A new rectangle scaled by the factors.
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
ValueError: If any factor is <= 0.
|
|
79
|
+
"""
|
|
80
|
+
def scale_to(rect: pykraken._core.Rect, size: pykraken._core.Vec2) -> pykraken._core.Rect:
|
|
81
|
+
"""
|
|
82
|
+
Scale a rectangle to the specified size.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
rect (Rect): The rectangle to scale.
|
|
86
|
+
size (Vec2): The new size as (width, height).
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
Rect: A new rectangle scaled to the specified size.
|
|
90
|
+
|
|
91
|
+
Raises:
|
|
92
|
+
ValueError: If width or height is <= 0.
|
|
93
|
+
"""
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions for rendering graphics
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
import pykraken._core
|
|
6
|
+
import typing
|
|
7
|
+
__all__: list[str] = ['clear', 'draw', 'get_res', 'present', 'read_pixels']
|
|
8
|
+
@typing.overload
|
|
9
|
+
def clear(color: typing.Any = None) -> None:
|
|
10
|
+
"""
|
|
11
|
+
Clear the renderer with the specified color.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
color (Color, optional): The color to clear with. Defaults to black (0, 0, 0, 255).
|
|
15
|
+
|
|
16
|
+
Raises:
|
|
17
|
+
ValueError: If color values are not between 0 and 255.
|
|
18
|
+
"""
|
|
19
|
+
@typing.overload
|
|
20
|
+
def clear(r: typing.SupportsInt, g: typing.SupportsInt, b: typing.SupportsInt, a: typing.SupportsInt = 255) -> None:
|
|
21
|
+
"""
|
|
22
|
+
Clear the renderer with the specified color.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
r (int): Red component (0-255).
|
|
26
|
+
g (int): Green component (0-255).
|
|
27
|
+
b (int): Blue component (0-255).
|
|
28
|
+
a (int, optional): Alpha component (0-255). Defaults to 255.
|
|
29
|
+
"""
|
|
30
|
+
@typing.overload
|
|
31
|
+
def draw(texture: pykraken._core.Texture, dst: pykraken._core.Rect, src: typing.Any = None) -> None:
|
|
32
|
+
"""
|
|
33
|
+
Render a texture with specified destination and source rectangles.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
texture (Texture): The texture to render.
|
|
37
|
+
dst (Rect): The destination rectangle on the renderer.
|
|
38
|
+
src (Rect, optional): The source rectangle from the texture. Defaults to entire texture if not specified.
|
|
39
|
+
"""
|
|
40
|
+
@typing.overload
|
|
41
|
+
def draw(texture: pykraken._core.Texture, pos: typing.Any = None, anchor: pykraken._core.Anchor = pykraken._core.Anchor.CENTER) -> None:
|
|
42
|
+
"""
|
|
43
|
+
Render a texture at the specified position with anchor alignment.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
texture (Texture): The texture to render.
|
|
47
|
+
pos (Vec2, optional): The position to draw at. Defaults to (0, 0).
|
|
48
|
+
anchor (Anchor, optional): The anchor point for positioning. Defaults to CENTER.
|
|
49
|
+
"""
|
|
50
|
+
def get_res() -> pykraken._core.Vec2:
|
|
51
|
+
"""
|
|
52
|
+
Get the resolution of the renderer.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
Vec2: The current rendering resolution as (width, height).
|
|
56
|
+
"""
|
|
57
|
+
def present() -> None:
|
|
58
|
+
"""
|
|
59
|
+
Present the rendered content to the screen.
|
|
60
|
+
|
|
61
|
+
This finalizes the current frame and displays it. Should be called after
|
|
62
|
+
all drawing operations for the frame are complete.
|
|
63
|
+
"""
|
|
64
|
+
def read_pixels(src: typing.Any = None) -> pykraken._core.PixelArray:
|
|
65
|
+
"""
|
|
66
|
+
Read pixel data from the renderer within the specified rectangle.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
src (Rect, optional): The rectangle area to read pixels from. Defaults to entire renderer if None.
|
|
70
|
+
Returns:
|
|
71
|
+
PixelArray: An array containing the pixel data.
|
|
72
|
+
Raises:
|
|
73
|
+
RuntimeError: If reading pixels fails.
|
|
74
|
+
"""
|
pykraken/_core/time.pyi
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Time related functions
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
import typing
|
|
6
|
+
__all__: list[str] = ['delay', 'get_delta', 'get_elapsed', 'get_fps', 'get_scale', 'set_max_delta', 'set_scale', 'set_target']
|
|
7
|
+
def delay(milliseconds: typing.SupportsInt) -> None:
|
|
8
|
+
"""
|
|
9
|
+
Delay the program execution for the specified duration.
|
|
10
|
+
|
|
11
|
+
This function pauses execution for the given number of milliseconds.
|
|
12
|
+
Useful for simple timing control, though using time.set_cap() is generally
|
|
13
|
+
preferred for precise frame rate control with nanosecond accuracy.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
milliseconds (int): The number of milliseconds to delay.
|
|
17
|
+
"""
|
|
18
|
+
def get_delta() -> float:
|
|
19
|
+
"""
|
|
20
|
+
Get the time elapsed since the last frame in seconds.
|
|
21
|
+
|
|
22
|
+
For stability, the returned delta is clamped so it will not be
|
|
23
|
+
smaller than 1/12 seconds (equivalent to capping at 12 FPS). This prevents
|
|
24
|
+
unstable calculations that rely on delta when very small frame times are
|
|
25
|
+
measured.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
float: The time elapsed since the last frame, in seconds.
|
|
29
|
+
"""
|
|
30
|
+
def get_elapsed() -> float:
|
|
31
|
+
"""
|
|
32
|
+
Get the elapsed time since the program started.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
float: The total elapsed time since program start, in seconds.
|
|
36
|
+
"""
|
|
37
|
+
def get_fps() -> float:
|
|
38
|
+
"""
|
|
39
|
+
Get the current frames per second of the program.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
float: The current FPS based on the last frame time.
|
|
43
|
+
"""
|
|
44
|
+
def get_scale() -> float:
|
|
45
|
+
"""
|
|
46
|
+
Get the current global time scale factor.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
float: The current time scale factor.
|
|
50
|
+
"""
|
|
51
|
+
def set_max_delta(max_delta: typing.SupportsFloat) -> None:
|
|
52
|
+
"""
|
|
53
|
+
Set the maximum allowed delta time between frames.
|
|
54
|
+
|
|
55
|
+
Parameters:
|
|
56
|
+
max_delta (float): The maximum delta time in seconds, greater than 0.0.
|
|
57
|
+
This is useful to prevent large delta values during
|
|
58
|
+
frame drops or pauses that could destabilize physics or animations.
|
|
59
|
+
"""
|
|
60
|
+
def set_scale(scale: typing.SupportsFloat) -> None:
|
|
61
|
+
"""
|
|
62
|
+
Set the global time scale factor.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
scale (float): The time scale factor. Values < 0.0 are clamped to 0.0.
|
|
66
|
+
A scale of 1.0 represents normal time, 0.5 is half speed,
|
|
67
|
+
and 2.0 is double speed.
|
|
68
|
+
"""
|
|
69
|
+
def set_target(frame_rate: typing.SupportsInt) -> None:
|
|
70
|
+
"""
|
|
71
|
+
Set the target framerate for the application.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
frame_rate (int): Target framerate to enforce. Values <= 0 disable frame rate limiting.
|
|
75
|
+
"""
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions for transforming pixel arrays
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
import pykraken._core
|
|
6
|
+
import typing
|
|
7
|
+
__all__: list[str] = ['box_blur', 'flip', 'gaussian_blur', 'grayscale', 'invert', 'rotate', 'scale_by', 'scale_to']
|
|
8
|
+
def box_blur(pixel_array: pykraken._core.PixelArray, radius: typing.SupportsInt, repeat_edge_pixels: bool = True) -> pykraken._core.PixelArray:
|
|
9
|
+
"""
|
|
10
|
+
Apply a box blur effect to a pixel array.
|
|
11
|
+
|
|
12
|
+
Box blur creates a uniform blur effect by averaging pixels within a square kernel.
|
|
13
|
+
It's faster than Gaussian blur but produces a more uniform, less natural look.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
pixel_array (PixelArray): The pixel array to blur.
|
|
17
|
+
radius (int): The blur radius in pixels. Larger values create stronger blur.
|
|
18
|
+
repeat_edge_pixels (bool, optional): Whether to repeat edge pixels when sampling
|
|
19
|
+
outside the pixel array bounds. Defaults to True.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
PixelArray: A new pixel array with the box blur effect applied.
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
RuntimeError: If pixel array creation fails during the blur process.
|
|
26
|
+
"""
|
|
27
|
+
def flip(pixel_array: pykraken._core.PixelArray, flip_x: bool, flip_y: bool) -> pykraken._core.PixelArray:
|
|
28
|
+
"""
|
|
29
|
+
Flip a pixel array horizontally, vertically, or both.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
pixel_array (PixelArray): The pixel array to flip.
|
|
33
|
+
flip_x (bool): Whether to flip horizontally (mirror left-right).
|
|
34
|
+
flip_y (bool): Whether to flip vertically (mirror top-bottom).
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
PixelArray: A new pixel array with the flipped image.
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
RuntimeError: If pixel array creation fails.
|
|
41
|
+
"""
|
|
42
|
+
def gaussian_blur(pixel_array: pykraken._core.PixelArray, radius: typing.SupportsInt, repeat_edge_pixels: bool = True) -> pykraken._core.PixelArray:
|
|
43
|
+
"""
|
|
44
|
+
Apply a Gaussian blur effect to a pixel array.
|
|
45
|
+
|
|
46
|
+
Gaussian blur creates a natural, smooth blur effect using a Gaussian distribution
|
|
47
|
+
for pixel weighting. It produces higher quality results than box blur but is
|
|
48
|
+
computationally more expensive.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
pixel_array (PixelArray): The pixel array to blur.
|
|
52
|
+
radius (int): The blur radius in pixels. Larger values create stronger blur.
|
|
53
|
+
repeat_edge_pixels (bool, optional): Whether to repeat edge pixels when sampling
|
|
54
|
+
outside the pixel array bounds. Defaults to True.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
PixelArray: A new pixel array with the Gaussian blur effect applied.
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
RuntimeError: If pixel array creation fails during the blur process.
|
|
61
|
+
"""
|
|
62
|
+
def grayscale(pixel_array: pykraken._core.PixelArray) -> pykraken._core.PixelArray:
|
|
63
|
+
"""
|
|
64
|
+
Convert a pixel array to grayscale.
|
|
65
|
+
|
|
66
|
+
Converts the pixel array to grayscale using the standard luminance formula:
|
|
67
|
+
gray = 0.299 * red + 0.587 * green + 0.114 * blue
|
|
68
|
+
|
|
69
|
+
This formula accounts for human perception of brightness across different colors.
|
|
70
|
+
The alpha channel is preserved unchanged.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
pixel_array (PixelArray): The pixel array to convert to grayscale.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
PixelArray: A new pixel array converted to grayscale.
|
|
77
|
+
|
|
78
|
+
Raises:
|
|
79
|
+
RuntimeError: If pixel array creation fails.
|
|
80
|
+
"""
|
|
81
|
+
def invert(pixel_array: pykraken._core.PixelArray) -> pykraken._core.PixelArray:
|
|
82
|
+
"""
|
|
83
|
+
Invert the colors of a pixel array.
|
|
84
|
+
|
|
85
|
+
Creates a negative image effect by inverting each color channel (RGB).
|
|
86
|
+
The alpha channel is preserved unchanged.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
pixel_array (PixelArray): The pixel array to invert.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
PixelArray: A new pixel array with inverted colors.
|
|
93
|
+
|
|
94
|
+
Raises:
|
|
95
|
+
RuntimeError: If pixel array creation fails.
|
|
96
|
+
"""
|
|
97
|
+
def rotate(pixel_array: pykraken._core.PixelArray, angle: typing.SupportsFloat) -> pykraken._core.PixelArray:
|
|
98
|
+
"""
|
|
99
|
+
Rotate a pixel array by a given angle.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
pixel_array (PixelArray): The pixel array to rotate.
|
|
103
|
+
angle (float): The rotation angle in degrees. Positive values rotate clockwise.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
PixelArray: A new pixel array containing the rotated image. The output pixel array may be
|
|
107
|
+
larger than the input to accommodate the rotated image.
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
RuntimeError: If pixel array rotation fails.
|
|
111
|
+
"""
|
|
112
|
+
def scale_by(pixel_array: pykraken._core.PixelArray, factor: typing.SupportsFloat) -> pykraken._core.PixelArray:
|
|
113
|
+
"""
|
|
114
|
+
Scale a pixel array by a given factor.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
pixel_array (PixelArray): The pixel array to scale.
|
|
118
|
+
factor (float): The scaling factor (must be > 0). Values > 1.0 enlarge,
|
|
119
|
+
values < 1.0 shrink the pixel array.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
PixelArray: A new pixel array scaled by the specified factor.
|
|
123
|
+
|
|
124
|
+
Raises:
|
|
125
|
+
ValueError: If factor is <= 0.
|
|
126
|
+
RuntimeError: If pixel array creation or scaling fails.
|
|
127
|
+
"""
|
|
128
|
+
def scale_to(pixel_array: pykraken._core.PixelArray, size: pykraken._core.Vec2) -> pykraken._core.PixelArray:
|
|
129
|
+
"""
|
|
130
|
+
Scale a pixel array to a new exact size.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
pixel_array (PixelArray): The pixel array to scale.
|
|
134
|
+
size (Vec2): The target size as (width, height).
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
PixelArray: A new pixel array scaled to the specified size.
|
|
138
|
+
|
|
139
|
+
Raises:
|
|
140
|
+
RuntimeError: If pixel array creation or scaling fails.
|
|
141
|
+
"""
|