class Level: def __init__(self, file, screen): self.__tile_map = TileMap(file, screen) self.done = False def keydown(self, key): self.__tile_map.mario.keydown(key) def keyup(self, key): self.__tile_map.mario.keyup(key) def update(self): self.__tile_map.update() def render(self): self.__tile_map.render()
import datashader as ds from datashader.utils import export_image import datashader.transfer_functions as tf import pandas as pd from colorcet import fire from PIL import Image from tilemap import TileMap point_df = pd.read_parquet("point_data.gzip") bounds = [1.288423e+07, 1.291500e+07, -3.772000e+06, -3.750000e+06] filter_point_df = point_df[(point_df["x"] >= bounds[0]) & (point_df["x"] <= bounds[1]) & (point_df["y"] >= bounds[2]) & (point_df["y"] <= bounds[3])] filter_point_desc_df = filter_point_df.describe() aspect_ratio = (filter_point_desc_df.loc["max", "y"] - filter_point_desc_df.loc["min", "y"])/(filter_point_desc_df.loc["max", "x"] - filter_point_desc_df.loc["min", "x"]) dim = 2000 cvs = ds.Canvas(plot_width=dim, plot_height=int(dim * aspect_ratio)) agg = cvs.points(filter_point_df, 'x', 'y') img = tf.shade(agg, cmap=fire) figname = 'perth_wires' export_image(img, figname, background="black") render_map = TileMap(extents=(115.7410072222, -32.0661730556, 116.0174188889, -31.8985416667)) map_image = render_map.render(zoom=14) map_image_resized = map_image.resize((2000, 1430), resample=Image.LANCZOS) map_image_resized.putalpha(255) map_image_resized.save("perth_street_map.png")
elif event.key == pygame.K_RIGHT: direction = 3 elif event.key == pygame.K_DOWN: direction = 4 elif event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: direction = 0 elif event.key == pygame.K_UP: direction = 0 elif event.key == pygame.K_RIGHT: direction = 0 elif event.key == pygame.K_DOWN: direction = 0 if direction is 1: x -= 1 elif direction is 2: y -= 1 elif direction is 3: x += 1 elif direction is 4: y += 1 if x < 0: x = 0 if y < 0: y = 0 tile_map.update(x, y) tile_map.render(x, y) pygame.display.flip()