From 3f99448fdce31bc3899ba5f0e3d7fb4fca5f39ca Mon Sep 17 00:00:00 2001 From: "Alejandro U. Alvarez" Date: Wed, 11 May 2022 06:03:15 +0100 Subject: [PATCH] Improve arcade rendering --- Readme.md | 6 +++++- run.py | 34 +++++++++++++++++++++++++++++----- src/world.py | 8 ++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index df08ae4..4107dd6 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,10 @@ # Evolving Beings -## Conda environment +## Running locally + +Just run the `run.py` file at the root. It should open up a window titled "Evolving beings" where the world should start animating. + +## Development ### Create environment diff --git a/run.py b/run.py index 68c7f1e..acf3973 100644 --- a/run.py +++ b/run.py @@ -1,10 +1,13 @@ import arcade +from arcade.gui import UIManager +from arcade.gui.widgets import UITextArea from src.world import World -SCREEN_WIDTH = 500 +SCREEN_WIDTH = 800 SCREEN_HEIGHT = 500 SCREEN_TITLE = "Evolving Beings" +DEBUG_PADDING = 10 class EvolvingBeings(arcade.Window): @@ -12,11 +15,29 @@ def __init__(self): super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) self.world = World(250, 250) - self.world.spawn(10) + + self.manager = UIManager() + self.manager.enable() + + self.debug_text = UITextArea( + x=DEBUG_PADDING, + y=-DEBUG_PADDING, + width=SCREEN_WIDTH - SCREEN_HEIGHT - DEBUG_PADDING, + height=SCREEN_HEIGHT - DEBUG_PADDING, + text='Testing this', + text_color=(255, 255, 255, 255), + ) + + self.manager.add(self.debug_text) + + self.background_color = arcade.color.BLACK + + # cell rendering + self.grid_sprite_list = arcade.SpriteList() def setup(self): """Sets up the world for the current simulation""" - pass + self.world.spawn(10) def on_key_press(self, key: int, modifiers: int): """Processes key presses @@ -40,10 +61,13 @@ def on_update(self, delta_time: float): Arguments: delta_time {float} -- How much time since the last call """ - pass + self.debug_text.text = f'FPS: {int(1 / delta_time)}\n' \ + f'Beings alive: {self.world.beings()}\n' \ + def on_draw(self): - pass + self.clear() + self.manager.draw() if __name__ == "__main__": diff --git a/src/world.py b/src/world.py index d722f2e..15a429b 100644 --- a/src/world.py +++ b/src/world.py @@ -53,6 +53,14 @@ def spawn(self, number): being = Being() self.state[x, y].update('BEING', being) + def beings(self): + num = 0 + for row in self.state: + for cell in row: + if cell.type is 'BEING' and cell.content.energy > 0: + num += 1 + return num + def render(self): state = np.zeros((self.w, self.h)) for i, row in enumerate(self.state):