Skip to content

Commit

Permalink
Cythonized ShadowCaster. Bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Feb 10, 2025
1 parent 5711167 commit 15f6a50
Show file tree
Hide file tree
Showing 5 changed files with 472 additions and 307 deletions.
27 changes: 14 additions & 13 deletions examples/advanced/shadow_casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from batgrl.gadgets.behaviors.grabbable import Grabbable
from batgrl.gadgets.gadget import Gadget, clamp
from batgrl.gadgets.grid_layout import GridLayout
from batgrl.gadgets.shadow_caster import LightSource, ShadowCaster, ShadowCasterCamera
from batgrl.gadgets.shadow_caster import ShadowCaster
from batgrl.gadgets.text import Text, new_cell
from batgrl.gadgets.toggle_button import ToggleButton

Expand Down Expand Up @@ -51,16 +51,17 @@ def grab_update(self, mouse_event):

class ShadowCasterApp(App):
async def on_start(self):
map_ = np.zeros((34, 34), int)
caster_map = np.zeros((34, 34), np.uint8)

caster = ShadowCaster(
size=(17, 34),
map=map_,
camera=ShadowCasterCamera((0, 0), (34, 34)),
caster_map=caster_map,
camera_pos=(0, 0),
camera_size=(34, 34),
tile_colors=[AWHITE, ACYAN, AMAGENTA],
light_sources=[LightSource(), LightSource()],
light_coords=[(0, 0), (0, 0)],
light_colors=[WHITE, WHITE],
radius=40,
restrictiveness="permissive",
)

label_kwargs = dict(
Expand Down Expand Up @@ -102,7 +103,7 @@ def callback(toggle_state):

def make_slider_callback(light_source, colors):
def callback(i):
caster.light_sources[light_source].color = colors[round(i)]
caster.light_colors[light_source] = colors[round(i)]

return callback

Expand Down Expand Up @@ -199,22 +200,22 @@ def callback(state):
while True:
for i in chain(range(21), range(21)[::-1]):
# Move boxes
map_[:] = 0
map_[8:12, 5 + i : 5 + i + 4] = 1
map_[22:26, 25 - i : 25 - i + 4] = 2
caster_map[:] = 0
caster_map[8:12, 5 + i : 5 + i + 4] = 1
caster_map[22:26, 25 - i : 25 - i + 4] = 2
# Move light sources
theta = (theta + 0.1) % math.tau
caster.light_sources[0].coords = (
caster.light_coords[0] = (
18 * math.sin(theta) + 17,
18 * math.cos(theta) + 17,
)
caster.light_sources[1].coords = (
caster.light_coords[1] = (
17 * math.cos(theta) + 17,
17 * math.sin(theta) + 17,
)
caster.cast_shadows()

await asyncio.sleep(0.01)
await asyncio.sleep(0.0166666)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def run(self):
"src/batgrl/_sixel.pyx",
"src/batgrl/char_width.pyx",
"src/batgrl/gadgets/_raycasting.pyx",
"src/batgrl/gadgets/_shadow_casting.pyx",
"src/batgrl/geometry/regions.pyx",
]
),
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""batgrl, the badass terminal graphics library."""

__version__ = "0.41.1"
__version__ = "0.42.0"
Loading

0 comments on commit 15f6a50

Please sign in to comment.