Skip to content

Commit

Permalink
Improve arcade rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
aurbano committed May 11, 2022
1 parent ec7064e commit 3f99448
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
34 changes: 29 additions & 5 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
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):
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
Expand All @@ -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__":
Expand Down
8 changes: 8 additions & 0 deletions src/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 3f99448

Please sign in to comment.