basilisk-engine 0.1.15__py3-none-any.whl → 0.1.17__py3-none-any.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.

Potentially problematic release.


This version of basilisk-engine might be problematic. Click here for more details.

Files changed (87) hide show
  1. basilisk/__init__.py +15 -14
  2. basilisk/audio/sound.py +27 -27
  3. basilisk/bsk_assets/cube.obj +48 -48
  4. basilisk/collisions/broad/broad_aabb.py +102 -102
  5. basilisk/collisions/broad/broad_bvh.py +137 -137
  6. basilisk/collisions/collider.py +95 -95
  7. basilisk/collisions/collider_handler.py +224 -224
  8. basilisk/collisions/narrow/contact_manifold.py +95 -95
  9. basilisk/collisions/narrow/dataclasses.py +34 -34
  10. basilisk/collisions/narrow/deprecated.py +46 -46
  11. basilisk/collisions/narrow/epa.py +91 -91
  12. basilisk/collisions/narrow/gjk.py +66 -66
  13. basilisk/collisions/narrow/graham_scan.py +24 -24
  14. basilisk/collisions/narrow/helper.py +29 -29
  15. basilisk/collisions/narrow/line_intersections.py +106 -106
  16. basilisk/collisions/narrow/sutherland_hodgman.py +75 -75
  17. basilisk/config.py +2 -2
  18. basilisk/draw/draw.py +100 -100
  19. basilisk/draw/draw_handler.py +179 -179
  20. basilisk/draw/font_renderer.py +28 -28
  21. basilisk/engine.py +206 -206
  22. basilisk/generic/abstract_bvh.py +15 -15
  23. basilisk/generic/abstract_custom.py +133 -133
  24. basilisk/generic/collisions.py +72 -72
  25. basilisk/generic/input_validation.py +66 -66
  26. basilisk/generic/math.py +6 -6
  27. basilisk/generic/matrices.py +35 -35
  28. basilisk/generic/meshes.py +72 -72
  29. basilisk/generic/quat.py +142 -142
  30. basilisk/generic/quat_methods.py +7 -7
  31. basilisk/generic/raycast_result.py +26 -26
  32. basilisk/generic/vec3.py +143 -143
  33. basilisk/input/mouse.py +61 -61
  34. basilisk/input/path.py +14 -14
  35. basilisk/mesh/cube.py +33 -33
  36. basilisk/mesh/mesh.py +230 -230
  37. basilisk/mesh/mesh_from_data.py +130 -130
  38. basilisk/mesh/model.py +271 -271
  39. basilisk/mesh/narrow_aabb.py +89 -89
  40. basilisk/mesh/narrow_bvh.py +91 -91
  41. basilisk/mesh/narrow_primative.py +23 -23
  42. basilisk/nodes/helper.py +28 -28
  43. basilisk/nodes/node.py +684 -684
  44. basilisk/nodes/node_handler.py +95 -95
  45. basilisk/particles/particle_handler.py +64 -63
  46. basilisk/particles/particle_renderer.py +93 -87
  47. basilisk/physics/impulse.py +112 -112
  48. basilisk/physics/physics_body.py +43 -43
  49. basilisk/physics/physics_engine.py +35 -35
  50. basilisk/render/batch.py +105 -105
  51. basilisk/render/camera.py +211 -211
  52. basilisk/render/chunk.py +106 -106
  53. basilisk/render/chunk_handler.py +165 -165
  54. basilisk/render/frame.py +101 -101
  55. basilisk/render/framebuffer.py +130 -130
  56. basilisk/render/image.py +87 -87
  57. basilisk/render/image_handler.py +122 -122
  58. basilisk/render/light.py +96 -96
  59. basilisk/render/light_handler.py +58 -58
  60. basilisk/render/material.py +219 -219
  61. basilisk/render/material_handler.py +135 -135
  62. basilisk/render/post_process.py +132 -132
  63. basilisk/render/shader.py +110 -110
  64. basilisk/render/shader_handler.py +80 -79
  65. basilisk/render/sky.py +120 -120
  66. basilisk/scene.py +276 -276
  67. basilisk/shaders/batch.frag +276 -276
  68. basilisk/shaders/batch.vert +115 -115
  69. basilisk/shaders/crt.frag +31 -31
  70. basilisk/shaders/draw.frag +21 -21
  71. basilisk/shaders/draw.vert +21 -21
  72. basilisk/shaders/filter.frag +22 -22
  73. basilisk/shaders/frame.frag +12 -12
  74. basilisk/shaders/frame.vert +13 -13
  75. basilisk/shaders/geometry.frag +8 -8
  76. basilisk/shaders/geometry.vert +41 -41
  77. basilisk/shaders/normal.frag +59 -59
  78. basilisk/shaders/normal.vert +96 -96
  79. basilisk/shaders/particle.frag +71 -71
  80. basilisk/shaders/particle.vert +84 -84
  81. basilisk/shaders/sky.frag +9 -9
  82. basilisk/shaders/sky.vert +13 -13
  83. {basilisk_engine-0.1.15.dist-info → basilisk_engine-0.1.17.dist-info}/METADATA +38 -45
  84. basilisk_engine-0.1.17.dist-info/RECORD +103 -0
  85. {basilisk_engine-0.1.15.dist-info → basilisk_engine-0.1.17.dist-info}/WHEEL +1 -1
  86. basilisk_engine-0.1.15.dist-info/RECORD +0 -103
  87. {basilisk_engine-0.1.15.dist-info → basilisk_engine-0.1.17.dist-info}/top_level.txt +0 -0
basilisk/draw/draw.py CHANGED
@@ -1,101 +1,101 @@
1
- from ..engine import Engine
2
- from ..render.image import Image
3
-
4
- def rect(engine: Engine, color: tuple, rect: tuple) -> None:
5
- """
6
- Draws a rectagle to the screen
7
- Args:
8
- engine: bsk.Engine
9
- The destination engine for the rectangle
10
- color: tuple(r, g, b) | tuple(r, g, b, a)
11
- The color value of the rectangle, with int components in range [0, 255]
12
- rect: tuple(x, y, w, h)
13
- The screen position and size of the rectangle given in pixels
14
- """
15
-
16
- # Get the draw handler from the engine
17
- draw_handler = engine.scene.draw_handler
18
- if not draw_handler: return
19
-
20
- # Draw the rect
21
- draw_handler.draw_rect(color, rect)
22
-
23
-
24
- def circle(engine: Engine, color: tuple, center: tuple, radius: int, resolution: int=20, outer_color: tuple=None) -> None:
25
- """
26
- Draws a rect between centered on x, y with width and height
27
- Args:
28
- color: tuple(r, g, b) | tuple(r, g, b, a)
29
- The color value of the circle, with int components in range [0, 255]
30
- center: tuple (x: float, y: float)
31
- Center of the circle, given in pixels
32
- radius: float
33
- Radius of the circle, given in pixels
34
- resolution: float
35
- The number of triangles used to approximate the circle
36
- """
37
-
38
- # Get the draw handler from the engine
39
- draw_handler = engine.scene.draw_handler
40
- if not draw_handler: return
41
-
42
- # Draw the circle
43
- draw_handler.draw_circle(color, center, radius, resolution, outer_color)
44
-
45
- def line(engine: Engine, color: tuple, p1: tuple, p2: tuple, thickness: int=1) -> None:
46
- """
47
- Draws a line between two points
48
- Args:
49
- color: tuple=(r, g, b) | tuple=(r, g, b, a)
50
- Color of the line
51
- p1: tuple=((x1, y1), (x2, y2))
52
- Starting point of the line. Given in pixels
53
- p1: tuple=((x1, y1), (x2, y2))
54
- Starting point of the line. Given in pixels
55
- thickness: int
56
- Size of the line on either side. pixels
57
- """
58
-
59
- # Get the draw handler from the engine
60
- draw_handler = engine.scene.draw_handler
61
- if not draw_handler: return
62
-
63
- # Draw the line
64
- draw_handler.draw_line(color, p1, p2, thickness)
65
-
66
- def blit(engine: Engine, image: Image, rect: tuple):
67
- """
68
- Blits a basilisk image to the engine screen.
69
- Args:
70
- image: bsk.Image
71
- The image to display on the screen
72
- rect: tuple(x, y, w, h)
73
- The screen position and size of the image given in pixels
74
- """
75
-
76
- # Get the draw handler from the engine
77
- draw_handler = engine.scene.draw_handler
78
- if not draw_handler: return
79
-
80
- engine.scene.material_handler.image_handler.add(image)
81
-
82
- # Blit the image
83
- draw_handler.blit(image, rect)
84
-
85
- def text(engine: Engine, text: str, position: tuple, scale: float=1.0):
86
- """
87
- Renders text do the screen
88
- USE SPARINGLY, INEFFICIENT IMPLAMENTATION
89
- """
90
-
91
- font_renderer = engine.scene.draw_handler.font_renderer
92
-
93
- # Render the text if it has not been cached
94
- if text not in font_renderer.text_renders:
95
- surf = font_renderer.render(text).convert_alpha()
96
- text_image = Image(surf)
97
- font_renderer.text_renders[text] = (text_image, surf.get_rect())
98
-
99
- # Blit the text image
100
- img, rect = font_renderer.text_renders[text]
1
+ from ..engine import Engine
2
+ from ..render.image import Image
3
+
4
+ def rect(engine: Engine, color: tuple, rect: tuple) -> None:
5
+ """
6
+ Draws a rectagle to the screen
7
+ Args:
8
+ engine: bsk.Engine
9
+ The destination engine for the rectangle
10
+ color: tuple(r, g, b) | tuple(r, g, b, a)
11
+ The color value of the rectangle, with int components in range [0, 255]
12
+ rect: tuple(x, y, w, h)
13
+ The screen position and size of the rectangle given in pixels
14
+ """
15
+
16
+ # Get the draw handler from the engine
17
+ draw_handler = engine.scene.draw_handler
18
+ if not draw_handler: return
19
+
20
+ # Draw the rect
21
+ draw_handler.draw_rect(color, rect)
22
+
23
+
24
+ def circle(engine: Engine, color: tuple, center: tuple, radius: int, resolution: int=20, outer_color: tuple=None) -> None:
25
+ """
26
+ Draws a rect between centered on x, y with width and height
27
+ Args:
28
+ color: tuple(r, g, b) | tuple(r, g, b, a)
29
+ The color value of the circle, with int components in range [0, 255]
30
+ center: tuple (x: float, y: float)
31
+ Center of the circle, given in pixels
32
+ radius: float
33
+ Radius of the circle, given in pixels
34
+ resolution: float
35
+ The number of triangles used to approximate the circle
36
+ """
37
+
38
+ # Get the draw handler from the engine
39
+ draw_handler = engine.scene.draw_handler
40
+ if not draw_handler: return
41
+
42
+ # Draw the circle
43
+ draw_handler.draw_circle(color, center, radius, resolution, outer_color)
44
+
45
+ def line(engine: Engine, color: tuple, p1: tuple, p2: tuple, thickness: int=1) -> None:
46
+ """
47
+ Draws a line between two points
48
+ Args:
49
+ color: tuple=(r, g, b) | tuple=(r, g, b, a)
50
+ Color of the line
51
+ p1: tuple=((x1, y1), (x2, y2))
52
+ Starting point of the line. Given in pixels
53
+ p1: tuple=((x1, y1), (x2, y2))
54
+ Starting point of the line. Given in pixels
55
+ thickness: int
56
+ Size of the line on either side. pixels
57
+ """
58
+
59
+ # Get the draw handler from the engine
60
+ draw_handler = engine.scene.draw_handler
61
+ if not draw_handler: return
62
+
63
+ # Draw the line
64
+ draw_handler.draw_line(color, p1, p2, thickness)
65
+
66
+ def blit(engine: Engine, image: Image, rect: tuple):
67
+ """
68
+ Blits a basilisk image to the engine screen.
69
+ Args:
70
+ image: bsk.Image
71
+ The image to display on the screen
72
+ rect: tuple(x, y, w, h)
73
+ The screen position and size of the image given in pixels
74
+ """
75
+
76
+ # Get the draw handler from the engine
77
+ draw_handler = engine.scene.draw_handler
78
+ if not draw_handler: return
79
+
80
+ engine.scene.material_handler.image_handler.add(image)
81
+
82
+ # Blit the image
83
+ draw_handler.blit(image, rect)
84
+
85
+ def text(engine: Engine, text: str, position: tuple, scale: float=1.0):
86
+ """
87
+ Renders text do the screen
88
+ USE SPARINGLY, INEFFICIENT IMPLAMENTATION
89
+ """
90
+
91
+ font_renderer = engine.scene.draw_handler.font_renderer
92
+
93
+ # Render the text if it has not been cached
94
+ if text not in font_renderer.text_renders:
95
+ surf = font_renderer.render(text).convert_alpha()
96
+ text_image = Image(surf)
97
+ font_renderer.text_renders[text] = (text_image, surf.get_rect())
98
+
99
+ # Blit the text image
100
+ img, rect = font_renderer.text_renders[text]
101
101
  blit(engine, img, (position[0] - rect[2] * scale / 2, position[1] - rect[3] * scale / 2, rect[2] * scale, rect[3] * scale))
@@ -1,180 +1,180 @@
1
- import moderngl as mgl
2
- import numpy as np
3
- import glm
4
- from math import cos, sin, atan2
5
- from ..render.image import Image
6
- from .font_renderer import FontRenderer
7
- from ..render.shader import Shader
8
- from ..generic.input_validation import validate_color, validate_rect, validate_point
9
-
10
- class DrawHandler():
11
- engine: ...
12
- """Back reference to the parent engine"""
13
- scene: ...
14
- """Back reference to the parent scene"""
15
- ctx: mgl.Context
16
- """Back reference to the parent context"""
17
- program: mgl.Program
18
- """2D draw program"""
19
- draw_data: list[float]
20
- """Temporary buffer for user draw calls"""
21
- vbo: mgl.Buffer=None
22
- """Buffer for all 2D draws"""
23
- vao: mgl.VertexArray=None
24
- """VAO for rendering all 2D draw calls"""
25
-
26
- def __init__(self, scene) -> None:
27
- # Back references
28
- self.scene = scene
29
- self.engine = scene.engine
30
- self.ctx = scene.engine.ctx
31
-
32
- # Get the shader
33
- root = self.engine.root
34
- self.shader = self.scene.shader_handler.add(Shader(self.engine, root + '/shaders/draw.vert', root + '/shaders/draw.frag'))
35
-
36
- # Initialize draw data as blank
37
- self.draw_data = []
38
- self.vbo = None
39
- self.vao = None
40
-
41
- self.font_renderer = FontRenderer(self.engine.root)
42
-
43
- def render(self) -> None:
44
- """
45
- Renders all draw calls from the user since the last frame
46
- """
47
-
48
- if not self.draw_data: return
49
-
50
- # Reverse the draw order, and convert to C-like array
51
- self.draw_data.reverse()
52
- data = np.array(self.draw_data, dtype='f4')
53
- ratio = np.array([2 / self.engine.win_size[0], 2 / self.engine.win_size[1]])
54
- data[:,:2] = data[:,:2] * ratio - 1
55
-
56
- # Create buffer and VAO
57
- self.vbo = self.ctx.buffer(data)
58
- self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '2f 4f 1i', *['in_position', 'in_color', 'in_uses_image'])], skip_errors=True)
59
-
60
- # Render the VAO
61
- self.ctx.enable(mgl.BLEND)
62
- self.ctx.blend_equation = mgl.ADDITIVE_BLENDING
63
- self.vao.render()
64
-
65
- # Clera the draw data
66
- self.vbo.release()
67
- self.vao.release()
68
- self.vbo = None
69
- self.vao = None
70
- self.draw_data.clear()
71
-
72
- def draw_rect(self, color: tuple, rect: tuple) -> None:
73
- """
74
- Draws a rect to the screen
75
- """
76
-
77
- color = validate_color('draw', 'color', color)
78
- rect = validate_rect(rect)
79
-
80
- p1 = (rect[0] , rect[1] )
81
- p2 = (rect[0] , rect[1] + rect[3])
82
- p3 = (rect[0] + rect[2], rect[1] )
83
- p4 = (rect[0] + rect[2], rect[1] + rect[3])
84
-
85
- v1 = (*p1, *color, 0)
86
- v2 = (*p2, *color, 0)
87
- v3 = (*p3, *color, 0)
88
- v4 = (*p4, *color, 0)
89
-
90
- self.draw_data.extend([
91
- v1, v3, v2,
92
- v2, v3, v4
93
- ])
94
-
95
- def draw_circle(self, color: tuple, center: tuple, radius: int, resolution: int=20, outer_color: tuple=None) -> None:
96
- """
97
- Draws a rect between centered on x, y with width and height
98
- Args:
99
- color: tuple(r, g, b) | tuple(r, g, b, a)
100
- The color value of the circle, with int components in range [0, 255]
101
- center: tuple (x: float, y: float)
102
- Center of the circle, given in pixels
103
- radius: float
104
- Radius of the circle, given in pixels
105
- resolution: float
106
- The number of triangles used to approximate the circle
107
- """
108
-
109
- if not outer_color: outer_color = color
110
- color = validate_color('draw', 'color', color)
111
- outer_color = validate_color('draw', 'color', outer_color)
112
- p1 = validate_point(center)
113
-
114
- v1 = (*p1, *color, 0)
115
- theta = 0
116
- delta_theta = (2 * 3.1415) / resolution
117
-
118
- for triangle in range(resolution):
119
- v2 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0)
120
- theta += delta_theta
121
- v3 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0)
122
- self.draw_data.extend([v1, v2, v3])
123
-
124
- def draw_line(self, color: tuple, p1: tuple, p2: tuple, thickness: int=1):
125
- """
126
- Draws a line between two points
127
- Args:
128
- color: tuple=(r, g, b) | tuple=(r, g, b, a)
129
- Color of the line
130
- p1: tuple=((x1, y1), (x2, y2))
131
- Starting point of the line. Given in pixels
132
- p1: tuple=((x1, y1), (x2, y2))
133
- Starting point of the line. Given in pixels
134
- thickness: int
135
- Size of the line on either side. pixels
136
- """
137
-
138
- color = validate_color('draw', 'color', color)
139
-
140
- p1 = glm.vec2(validate_point(p1))
141
- p2 = glm.vec2(validate_point(p2))
142
-
143
- thickness /= 2
144
-
145
- unit = glm.normalize(p1 - p2) * thickness
146
- theta = atan2(*unit)
147
- perp_vector = glm.vec2(cos(-theta), sin(-theta)) * thickness
148
-
149
- v1 = (*(p1 - perp_vector), *color, 0)
150
- v2 = (*(p1 + perp_vector), *color, 0)
151
- v3 = (*(p2 - perp_vector), *color, 0)
152
- v4 = (*(p2 + perp_vector), *color, 0)
153
-
154
- self.draw_data.extend([v1, v3, v4, v2, v1, v4])
155
-
156
- def blit(self, image: Image, rect: tuple):
157
- rect = validate_rect(rect)
158
-
159
- p1 = (rect[0] , rect[1] )
160
- p2 = (rect[0] , rect[1] + rect[3])
161
- p3 = (rect[0] + rect[2], rect[1] )
162
- p4 = (rect[0] + rect[2], rect[1] + rect[3])
163
-
164
- v1 = (*p1, *image.index, 0, 0, 1)
165
- v2 = (*p2, *image.index, 0, 1, 1)
166
- v3 = (*p3, *image.index, 1, 0, 1)
167
- v4 = (*p4, *image.index, 1, 1, 1)
168
-
169
- self.draw_data.extend([
170
- v1, v3, v2,
171
- v2, v3, v4
172
- ])
173
-
174
- def __del__(self) -> None:
175
- """
176
- Releases any allocated data
177
- """
178
-
179
- if self.vbo: self.vbo.release()
1
+ import moderngl as mgl
2
+ import numpy as np
3
+ import glm
4
+ from math import cos, sin, atan2
5
+ from ..render.image import Image
6
+ from .font_renderer import FontRenderer
7
+ from ..render.shader import Shader
8
+ from ..generic.input_validation import validate_color, validate_rect, validate_point
9
+
10
+ class DrawHandler():
11
+ engine: ...
12
+ """Back reference to the parent engine"""
13
+ scene: ...
14
+ """Back reference to the parent scene"""
15
+ ctx: mgl.Context
16
+ """Back reference to the parent context"""
17
+ program: mgl.Program
18
+ """2D draw program"""
19
+ draw_data: list[float]
20
+ """Temporary buffer for user draw calls"""
21
+ vbo: mgl.Buffer=None
22
+ """Buffer for all 2D draws"""
23
+ vao: mgl.VertexArray=None
24
+ """VAO for rendering all 2D draw calls"""
25
+
26
+ def __init__(self, scene) -> None:
27
+ # Back references
28
+ self.scene = scene
29
+ self.engine = scene.engine
30
+ self.ctx = scene.engine.ctx
31
+
32
+ # Get the shader
33
+ root = self.engine.root
34
+ self.shader = self.scene.shader_handler.add(Shader(self.engine, root + '/shaders/draw.vert', root + '/shaders/draw.frag'))
35
+
36
+ # Initialize draw data as blank
37
+ self.draw_data = []
38
+ self.vbo = None
39
+ self.vao = None
40
+
41
+ self.font_renderer = FontRenderer(self.engine.root)
42
+
43
+ def render(self) -> None:
44
+ """
45
+ Renders all draw calls from the user since the last frame
46
+ """
47
+
48
+ if not self.draw_data: return
49
+
50
+ # Reverse the draw order, and convert to C-like array
51
+ self.draw_data.reverse()
52
+ data = np.array(self.draw_data, dtype='f4')
53
+ ratio = np.array([2 / self.engine.win_size[0], 2 / self.engine.win_size[1]])
54
+ data[:,:2] = data[:,:2] * ratio - 1
55
+
56
+ # Create buffer and VAO
57
+ self.vbo = self.ctx.buffer(data)
58
+ self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '2f 4f 1i', *['in_position', 'in_color', 'in_uses_image'])], skip_errors=True)
59
+
60
+ # Render the VAO
61
+ self.ctx.enable(mgl.BLEND)
62
+ self.ctx.blend_equation = mgl.ADDITIVE_BLENDING
63
+ self.vao.render()
64
+
65
+ # Clera the draw data
66
+ self.vbo.release()
67
+ self.vao.release()
68
+ self.vbo = None
69
+ self.vao = None
70
+ self.draw_data.clear()
71
+
72
+ def draw_rect(self, color: tuple, rect: tuple) -> None:
73
+ """
74
+ Draws a rect to the screen
75
+ """
76
+
77
+ color = validate_color('draw', 'color', color)
78
+ rect = validate_rect(rect)
79
+
80
+ p1 = (rect[0] , rect[1] )
81
+ p2 = (rect[0] , rect[1] + rect[3])
82
+ p3 = (rect[0] + rect[2], rect[1] )
83
+ p4 = (rect[0] + rect[2], rect[1] + rect[3])
84
+
85
+ v1 = (*p1, *color, 0)
86
+ v2 = (*p2, *color, 0)
87
+ v3 = (*p3, *color, 0)
88
+ v4 = (*p4, *color, 0)
89
+
90
+ self.draw_data.extend([
91
+ v1, v3, v2,
92
+ v2, v3, v4
93
+ ])
94
+
95
+ def draw_circle(self, color: tuple, center: tuple, radius: int, resolution: int=20, outer_color: tuple=None) -> None:
96
+ """
97
+ Draws a rect between centered on x, y with width and height
98
+ Args:
99
+ color: tuple(r, g, b) | tuple(r, g, b, a)
100
+ The color value of the circle, with int components in range [0, 255]
101
+ center: tuple (x: float, y: float)
102
+ Center of the circle, given in pixels
103
+ radius: float
104
+ Radius of the circle, given in pixels
105
+ resolution: float
106
+ The number of triangles used to approximate the circle
107
+ """
108
+
109
+ if not outer_color: outer_color = color
110
+ color = validate_color('draw', 'color', color)
111
+ outer_color = validate_color('draw', 'color', outer_color)
112
+ p1 = validate_point(center)
113
+
114
+ v1 = (*p1, *color, 0)
115
+ theta = 0
116
+ delta_theta = (2 * 3.1415) / resolution
117
+
118
+ for triangle in range(resolution):
119
+ v2 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0)
120
+ theta += delta_theta
121
+ v3 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0)
122
+ self.draw_data.extend([v1, v2, v3])
123
+
124
+ def draw_line(self, color: tuple, p1: tuple, p2: tuple, thickness: int=1):
125
+ """
126
+ Draws a line between two points
127
+ Args:
128
+ color: tuple=(r, g, b) | tuple=(r, g, b, a)
129
+ Color of the line
130
+ p1: tuple=((x1, y1), (x2, y2))
131
+ Starting point of the line. Given in pixels
132
+ p1: tuple=((x1, y1), (x2, y2))
133
+ Starting point of the line. Given in pixels
134
+ thickness: int
135
+ Size of the line on either side. pixels
136
+ """
137
+
138
+ color = validate_color('draw', 'color', color)
139
+
140
+ p1 = glm.vec2(validate_point(p1))
141
+ p2 = glm.vec2(validate_point(p2))
142
+
143
+ thickness /= 2
144
+
145
+ unit = glm.normalize(p1 - p2) * thickness
146
+ theta = atan2(*unit)
147
+ perp_vector = glm.vec2(cos(-theta), sin(-theta)) * thickness
148
+
149
+ v1 = (*(p1 - perp_vector), *color, 0)
150
+ v2 = (*(p1 + perp_vector), *color, 0)
151
+ v3 = (*(p2 - perp_vector), *color, 0)
152
+ v4 = (*(p2 + perp_vector), *color, 0)
153
+
154
+ self.draw_data.extend([v1, v3, v4, v2, v1, v4])
155
+
156
+ def blit(self, image: Image, rect: tuple):
157
+ rect = validate_rect(rect)
158
+
159
+ p1 = (rect[0] , rect[1] )
160
+ p2 = (rect[0] , rect[1] + rect[3])
161
+ p3 = (rect[0] + rect[2], rect[1] )
162
+ p4 = (rect[0] + rect[2], rect[1] + rect[3])
163
+
164
+ v1 = (*p1, *image.index, 0, 0, 1)
165
+ v2 = (*p2, *image.index, 0, 1, 1)
166
+ v3 = (*p3, *image.index, 1, 0, 1)
167
+ v4 = (*p4, *image.index, 1, 1, 1)
168
+
169
+ self.draw_data.extend([
170
+ v1, v3, v2,
171
+ v2, v3, v4
172
+ ])
173
+
174
+ def __del__(self) -> None:
175
+ """
176
+ Releases any allocated data
177
+ """
178
+
179
+ if self.vbo: self.vbo.release()
180
180
  if self.vao: self.vao.release()
@@ -1,28 +1,28 @@
1
- import pygame as pg
2
-
3
- class FontRenderer():
4
- def __init__(self, root):
5
- pg.font.init()
6
- self.font = pg.font.Font(root + '/bsk_assets/Roboto-Regular.ttf', 48)
7
- self.text_renders = {}
8
-
9
- def render(self, text, color=(255, 255, 255), bold=False, underline=False, italic=False):
10
- '''
11
- Renders any font which has been loaded to the class instance.
12
- Args:
13
- text::str
14
- Text to be rendered
15
- color::(int, int, int) =(255, 255, 255)
16
- The RGB value of the text
17
- bold::bool (=False)
18
- Specifies if the text should be rendered in bolded font
19
- underline::bool (=False)
20
- Specifies if the text should be underlined in bolded font
21
- italic::bool (=False)
22
- Specifies if the text should be rendered in italicized font
23
- '''
24
- self.font.set_bold(bold)
25
- self.font.set_underline(underline)
26
- self.font.set_italic(italic)
27
-
28
- return self.font.render(text, True, color, (0, 0, 0, 0))
1
+ import pygame as pg
2
+
3
+ class FontRenderer():
4
+ def __init__(self, root):
5
+ pg.font.init()
6
+ self.font = pg.font.Font(root + '/bsk_assets/Roboto-Regular.ttf', 48)
7
+ self.text_renders = {}
8
+
9
+ def render(self, text, color=(255, 255, 255), bold=False, underline=False, italic=False):
10
+ '''
11
+ Renders any font which has been loaded to the class instance.
12
+ Args:
13
+ text::str
14
+ Text to be rendered
15
+ color::(int, int, int) =(255, 255, 255)
16
+ The RGB value of the text
17
+ bold::bool (=False)
18
+ Specifies if the text should be rendered in bolded font
19
+ underline::bool (=False)
20
+ Specifies if the text should be underlined in bolded font
21
+ italic::bool (=False)
22
+ Specifies if the text should be rendered in italicized font
23
+ '''
24
+ self.font.set_bold(bold)
25
+ self.font.set_underline(underline)
26
+ self.font.set_italic(italic)
27
+
28
+ return self.font.render(text, True, color, (0, 0, 0, 0))