From 4d4d78039e5c18fa55b16545f456dfd70fe388a4 Mon Sep 17 00:00:00 2001 From: Noe Ruiz Date: Wed, 6 Nov 2019 10:00:05 -0500 Subject: [PATCH] Updated Flying Clouds Updated Flying Clouds --- CircuitPython_Flying_Toasters/code.py | 54 ++++++++---------- .../spritesheet-2x.bmp | Bin 0 -> 36984 bytes CircuitPython_Flying_Toasters/spritesheet.bmp | Bin 9334 -> 0 bytes 3 files changed, 23 insertions(+), 31 deletions(-) create mode 100644 CircuitPython_Flying_Toasters/spritesheet-2x.bmp delete mode 100644 CircuitPython_Flying_Toasters/spritesheet.bmp diff --git a/CircuitPython_Flying_Toasters/code.py b/CircuitPython_Flying_Toasters/code.py index 761565e69..26c0615f1 100644 --- a/CircuitPython_Flying_Toasters/code.py +++ b/CircuitPython_Flying_Toasters/code.py @@ -44,12 +44,11 @@ NUMBER_OF_CELLS = (LAST_CELL - FIRST_CELL) + 1 ANIMATED = [_sprite >= FIRST_CELL and _sprite <= LAST_CELL for _sprite in range(NUMBER_OF_SPRITES)] -# The chance (out of 10) that a new toaster, or toast will enter -CHANCE_OF_NEW_TOASTER = 5 +# The chance (out of 10) that toast will enter CHANCE_OF_NEW_TOAST = 2 # How many sprites to styart with -INITIAL_NUMBER_OF_SPRITES= 5 +INITIAL_NUMBER_OF_SPRITES = 4 # Global variables display = None @@ -66,11 +65,8 @@ def make_display(): pass spi.configure(baudrate=24000000) # Configure SPI for 24MHz spi.unlock() - tft_cs = board.D10 - tft_dc = board.D7 - displayio.release_displays() - display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) + display_bus = displayio.FourWire(spi, command=board.D7, chip_select=board.D10, reset=board.D9) return ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True) @@ -78,13 +74,13 @@ def make_tilegrid(): """Construct and return the tilegrid.""" group = displayio.Group(max_size=10) - sprite_sheet, palette = adafruit_imageload.load("/spritesheet.bmp", + sprite_sheet, palette = adafruit_imageload.load("/spritesheet-2x.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) grid = displayio.TileGrid(sprite_sheet, pixel_shader=palette, - width=9, height=9, - tile_height=32, tile_width=32, - x=0, y=-32, + width=5, height=5, + tile_height=64, tile_width=64, + x=0, y=-64, default_tile=EMPTY) group.append(grid) display.show(group) @@ -104,8 +100,8 @@ def seed_toasters(number_of_toasters): """Create the initial toasters so it doesn't start empty""" for _ in range(number_of_toasters): while True: - row = randint(0, 8) - col = randint(0, 8) + row = randint(0, 4) + col = randint(0, 4) if evaluate_position(row, col): break tilegrid[col, row] = random_cell() @@ -117,7 +113,7 @@ def next_sprite(sprite): def advance_animation(): """Cycle through animation cells each time.""" - for tile_number in range(81): + for tile_number in range(25): tilegrid[tile_number] = next_sprite(tilegrid[tile_number]) def slide_tiles(): @@ -127,24 +123,24 @@ def slide_tiles(): def shift_tiles(): """Move tiles one spot to the left, and reset the tilegrid's position""" - for row in range(8, 0, -1): - for col in range(8): + for row in range(4, 0, -1): + for col in range(4): tilegrid[col, row] = tilegrid[col + 1, row - 1] - tilegrid[8, row] = EMPTY - for col in range(9): + tilegrid[4, row] = EMPTY + for col in range(5): tilegrid[col, 0] = EMPTY tilegrid.x = 0 - tilegrid.y = -32 + tilegrid.y = -64 def get_entry_row(): while True: - row = randint(0, 8) - if tilegrid[8, row] == EMPTY and tilegrid[7, row] == EMPTY: + row = randint(0, 4) + if tilegrid[4, row] == EMPTY and tilegrid[3, row] == EMPTY: return row def get_entry_column(): while True: - col = randint(0, 8) + col = randint(0, 3) if tilegrid[col, 0] == EMPTY and tilegrid[col, 1] == EMPTY: return col @@ -152,18 +148,14 @@ def add_toaster_or_toast(): """Maybe add a new toaster or toast on the right and/or top at a randon open location""" if randint(1, 10) <= CHANCE_OF_NEW_TOAST: tile = TOAST - elif randint(1, 10) <= CHANCE_OF_NEW_TOASTER: - tile = random_cell() else: - tile = EMPTY - tilegrid[8, get_entry_row()] = tile + tile = random_cell() + tilegrid[4, get_entry_row()] = tile if randint(1, 10) <= CHANCE_OF_NEW_TOAST: tile = TOAST - elif randint(1, 8) <= CHANCE_OF_NEW_TOASTER: - tile = random_cell() else: - tile = EMPTY + tile = random_cell() tilegrid[get_entry_column(), 0] = tile display = make_display() @@ -172,10 +164,10 @@ seed_toasters(INITIAL_NUMBER_OF_SPRITES) display.refresh() while True: - for _ in range(32): + for _ in range(64): display.refresh(target_frames_per_second=80) advance_animation() slide_tiles() shift_tiles() add_toaster_or_toast() - display.refresh(target_frames_per_second=120) + display.refresh(target_frames_per_second=120) \ No newline at end of file diff --git a/CircuitPython_Flying_Toasters/spritesheet-2x.bmp b/CircuitPython_Flying_Toasters/spritesheet-2x.bmp new file mode 100644 index 0000000000000000000000000000000000000000..fbd062153e0819682afe745dba5b8502d77c999e GIT binary patch literal 36984 zcmeHMTXN$z5aepDa#VJea|l-@xkYOK{IR)-e^dF)5mNrjNqiX}#>;kZYX%RBpeRw6 zG^ipm05KS_(P)jNZ{Pp(5nx_4SwTm;T;$tN!_KeU0napI2Y?<-O~k z{_U&xZuR_s_vMejVD{I0_xASIy}rJ7FE20M^Ye4}^z_s{K0fw7Z~gV!UxzGr+p^!R zTlc&3^q;=!yFK4jkxuQebsVNX_x+!{{^=;5djIFfpZ>-}9>9Lp7v0ew8e8i>cmML8 zfCfwXEP8ST&VB#qu0O}4&o{QEd=@<(0bvios6T`b{VghlQ3Bg6%!T43)oqMArGL39 zt;W~osOTXAr{2F)$1i!{c_X_V6+J+}&OVSzTkP4bA*n~&ItTxf1z2^xlw+eO-SM;q z6rm2gP)a@0);ai>?^fpyddsob-jnZl-X@mA9LmS%?Zf)t_9fl1JYL=&i=WQsvu1kM z?zzu3w{yJn_89*8_`H2s|KQK(;%d3uWsgo^O@qqOWzS*!yAIr8F$~LSWzVkoHWMt3 zWWC;&v>&b1?|NG$+GUT>3;qa+;Ezs>*s|FO8}+E2);WhX`q=(neV{>yTEFJWwP&?j zuWz=6LX;vA90GPr?Z2?!mw&+@WBO;Z#2@Xi|NRGhtz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