-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.py
49 lines (25 loc) · 1.4 KB
/
Utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import math
app_width = 1800 # Width of the screen
app_height = 900 # Height of the screen
board_width = app_height # Width of the tile board
board_height = app_height # Height of the tile board
tiles_per_row = 100 # Amount of rows and columns of tiles
tile_num = tiles_per_row ** 2 # Amount of tiles on the board (must be a square number)
tile_width = board_width / tiles_per_row # Width and height of a tile
init_creature_num = 100 # Amount of creatures created when application starts
total_creature_num = init_creature_num # An integer for the total amount of creatures that have been created
creatures = [] # List of creatures currently alive
tiles = [] # List of tiles
tile_update = [] # A list of Creatures created when the application begins
birth_food = 100 # A number representing the amount of food a Creature is born with
birth_water = 100 # A number representing the amount of water a Creature is born with
mutation_rate = .1 # A float representing the chance of a mutation on a given weight at birth
def rgb_to_hex(r, g, b):
return "#%02x%02x%02x" % (r, g, b)
def get_tile(x, y):
x_tile = clamp(math.floor(x / tile_width), 0, tiles_per_row)
y_tile = clamp(math.floor(y / tile_width), 0, tiles_per_row - 1)
position = clamp(x_tile + y_tile * tiles_per_row, 0, tile_num - 1)
return tiles[position]
def clamp(n, min_n, max_n):
return max(min(max_n, n), min_n)