added useful functions for tile selection and more

This commit is contained in:
MarRac 2024-05-26 19:54:46 +02:00
parent 9e978d6032
commit fb0ec5057c
4 changed files with 16 additions and 2 deletions

View File

@ -53,3 +53,10 @@ def get_tile_coordinates(index):
return tile.x, tile.y
else:
return None
def get_tile_index():
valid_indices = []
for index, tile in enumerate(tiles):
if tile.image=="resources/images/sampling.png":
valid_indices.append(index)
return random.choice(valid_indices)

View File

@ -1,5 +1,7 @@
import random
import os
import numpy as np
import matplotlib.pyplot as plt
# path to plant images folder (used in randomize_photo function)
folder_path = "resources/images/plant_photos"
@ -48,4 +50,9 @@ class Tile:
self.image = "resources/images/rock_dirt.png"
# DISCLAMER check column and choose plant type ("potato","wheat" etc.)
def displayPhoto(self):
img = self.photo
img = img / 2 + 0.5 # unnormalize
npimg = img.numpy()
plt.imshow(np.transpose(npimg, (1, 2, 0)))
plt.show()