Toggle Navigation
Hatchery
Eggs
SleepSheeps
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import display import leds import urandom import utime import buttons # constants X_MAX = 160 X_STEP = 2 dir_x=X_STEP Y_MAX = 80 Y_STEP = 0 SHEEP = [[17,1],[18,1],[19,1],[30,1],[31,1],[32,1],[34,1],[35,1],[37,1],[12,2],[13,2],[14,2],[17,2],[18,2],[19,2],[20,2],[22,2],[23,2],[27,2],[28,2],[29,2],[30,2],[31,2],[32,2],[33,2],[34,2],[35,2],[36,2],[37,2],[38,2],[39,2],[11,3],[12,3],[13,3],[14,3],[15,3],[16,3],[17,3],[18,3],[19,3],[20,3],[21,3],[22,3],[23,3],[24,3],[25,3],[26,3],[27,3],[28,3],[29,3],[30,3],[31,3],[32,3],[33,3],[34,3],[35,3],[36,3],[37,3],[38,3],[39,3],[40,3],[41,3],[9,4],[10,4],[11,4],[12,4],[13,4],[14,4],[15,4],[16,4],[17,4],[18,4],[19,4],[20,4],[21,4],[22,4],[23,4],[24,4],[25,4],[26,4],[27,4],[28,4],[29,4],[30,4],[31,4],[32,4],[33,4],[34,4],[35,4],[36,4],[37,4],[38,4],[39,4],[40,4],[41,4],[7,5],[8,5],[9,5],[10,5],[11,5],[12,5],[13,5],[14,5],[15,5],[16,5],[17,5],[18,5],[19,5],[20,5],[21,5],[22,5],[23,5],[24,5],[25,5],[26,5],[30,5],[31,5],[32,5],[33,5],[34,5],[35,5],[36,5],[37,5],[41,5],[42,5],[7,6],[8,6],[9,6],[10,6],[11,6],[12,6],[13,6],[14,6],[15,6],[16,6],[17,6],[18,6],[19,6],[20,6],[21,6],[22,6],[23,6],[24,6],[25,6],[26,6],[31,6],[32,6],[33,6],[34,6],[35,6],[36,6],[42,6],[7,7],[8,7],[9,7],[10,7],[11,7],[12,7],[13,7],[14,7],[15,7],[16,7],[17,7],[18,7],[19,7],[20,7],[21,7],[22,7],[23,7],[24,7],[25,7],[32,7],[33,7],[34,7],[35,7],[42,7],[6,8],[7,8],[8,8],[9,8],[10,8],[11,8],[12,8],[13,8],[14,8],[15,8],[16,8],[17,8],[18,8],[19,8],[20,8],[21,8],[22,8],[23,8],[24,8],[25,8],[39,8],[42,8],[5,9],[6,9],[7,9],[8,9],[9,9],[10,9],[11,9],[12,9],[13,9],[14,9],[15,9],[16,9],[17,9],[18,9],[19,9],[20,9],[21,9],[22,9],[23,9],[24,9],[25,9],[28,9],[30,9],[31,9],[32,9],[35,9],[36,9],[37,9],[39,9],[42,9],[4,10],[5,10],[6,10],[7,10],[8,10],[9,10],[10,10],[11,10],[12,10],[13,10],[14,10],[15,10],[16,10],[17,10],[18,10],[19,10],[20,10],[21,10],[22,10],[23,10],[24,10],[25,10],[28,10],[31,10],[32,10],[35,10],[36,10],[39,10],[41,10],[3,11],[4,11],[5,11],[7,11],[8,11],[9,11],[10,11],[11,11],[12,11],[13,11],[14,11],[15,11],[16,11],[17,11],[18,11],[19,11],[20,11],[21,11],[22,11],[23,11],[24,11],[25,11],[26,11],[28,11],[39,11],[40,11],[41,11],[2,12],[3,12],[4,12],[5,12],[7,12],[8,12],[9,12],[10,12],[11,12],[12,12],[13,12],[14,12],[15,12],[16,12],[17,12],[18,12],[19,12],[20,12],[21,12],[22,12],[23,12],[24,12],[25,12],[26,12],[27,12],[28,12],[39,12],[3,13],[7,13],[8,13],[9,13],[10,13],[11,13],[12,13],[13,13],[14,13],[15,13],[16,13],[17,13],[18,13],[19,13],[20,13],[21,13],[22,13],[23,13],[24,13],[25,13],[26,13],[27,13],[28,13],[33,13],[34,13],[35,13],[39,13],[7,14],[8,14],[9,14],[10,14],[11,14],[12,14],[13,14],[14,14],[15,14],[16,14],[17,14],[18,14],[19,14],[20,14],[21,14],[22,14],[23,14],[24,14],[25,14],[26,14],[27,14],[28,14],[29,14],[33,14],[34,14],[35,14],[39,14],[7,15],[8,15],[9,15],[10,15],[11,15],[12,15],[13,15],[14,15],[15,15],[16,15],[17,15],[18,15],[19,15],[20,15],[21,15],[22,15],[23,15],[24,15],[25,15],[26,15],[27,15],[28,15],[29,15],[31,15],[34,15],[38,15],[7,16],[8,16],[9,16],[10,16],[11,16],[12,16],[13,16],[14,16],[15,16],[16,16],[17,16],[18,16],[19,16],[20,16],[21,16],[22,16],[23,16],[24,16],[25,16],[26,16],[27,16],[28,16],[29,16],[32,16],[33,16],[34,16],[35,16],[38,16],[7,17],[8,17],[9,17],[10,17],[11,17],[12,17],[13,17],[14,17],[15,17],[16,17],[17,17],[18,17],[19,17],[20,17],[21,17],[22,17],[23,17],[24,17],[25,17],[26,17],[27,17],[28,17],[29,17],[37,17],[8,18],[9,18],[10,18],[11,18],[12,18],[13,18],[15,18],[16,18],[17,18],[18,18],[19,18],[20,18],[21,18],[22,18],[23,18],[24,18],[27,18],[28,18],[29,18],[30,18],[31,18],[36,18],[37,18],[8,19],[9,19],[10,19],[11,19],[12,19],[15,19],[16,19],[17,19],[18,19],[19,19],[20,19],[21,19],[22,19],[23,19],[24,19],[28,19],[29,19],[32,19],[33,19],[34,19],[35,19],[9,20],[10,20],[11,20],[12,20],[15,20],[16,20],[17,20],[18,20],[19,20],[20,20],[21,20],[22,20],[23,20],[24,20],[29,20],[9,21],[10,21],[11,21],[12,21],[15,21],[16,21],[17,21],[18,21],[19,21],[20,21],[21,21],[22,21],[23,21],[24,21],[25,21],[26,21],[29,21],[30,21],[9,22],[12,22],[15,22],[22,22],[25,22],[26,22],[30,22],[9,23],[12,23],[15,23],[22,23],[25,23],[27,23],[30,23],[9,24],[12,24],[16,24],[21,24],[25,24],[27,24],[30,24],[8,25],[11,25],[13,25],[16,25],[21,25],[24,25],[27,25],[30,25],[7,26],[11,26],[14,26],[17,26],[21,26],[24,26],[27,26],[30,26],[6,27],[10,27],[14,27],[17,27],[20,27],[24,27],[27,27],[30,27],[6,28],[9,28],[14,28],[17,28],[20,28],[23,28],[27,28],[30,28],[6,29],[9,29],[14,29],[17,29],[20,29],[22,29],[27,29],[30,29],[7,30],[8,30],[15,30],[16,30],[21,30],[22,30],[28,30],[29,30]] X_SIZE = 42 Y_SIZE = 31 def get_random_color(): return [ urandom.randint(0, 255), urandom.randint(0, 255), urandom.randint(0, 255), ] def move(x, y, dir_x, dir_y): x += dir_x y += dir_y if dir_x > 0 and x+X_SIZE >= X_MAX: x = 0 return x, y, dir_x, dir_y def render_disp(x, y, fg_color,counter,speed): with display.open() as disp: disp.clear() disp.rect(0, 0, X_MAX, Y_MAX, col=[0,5,50], filled=True) disp.rect(0, 70, X_MAX, Y_MAX, col=[0,70,0], filled=True) disp.print('speed: '+str(speed), font=display.FONT8, fg=[200,200,100], bg=[0,5,50],posx=100) disp.print('Sheeps: '+str(counter), font=display.FONT12, fg=[200,200,100], bg=[0,5,50]) for i, j in (SHEEP): disp.pixel(x+i, y+j, col=fg_color) disp.update() def render_leds(x,fg_color): mymini=1 mymaxi=(X_MAX-X_SIZE) my_led = int(10-(float(x) / mymaxi * 10)) for i in range(0, 11): leds.prep(i, [0, 0, 0]) leds.prep(my_led, fg_color) leds.update() def main(): SHEEPCOUNTER=0 x = 1 y = 40 dir_x = X_STEP dir_y = Y_STEP fg_color = get_random_color() while True: pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) if pressed & buttons.BOTTOM_LEFT != 0: if dir_x>1: dir_x-=1 if pressed & buttons.BOTTOM_RIGHT != 0: dir_x+=1 x, y, dir_x, dir_y = move(x,y,dir_x,dir_y) if x >= (X_MAX-X_SIZE-dir_x-2): fg_color = get_random_color() SHEEPCOUNTER+=1 render_disp(x, y, fg_color,SHEEPCOUNTER,dir_x) render_leds(x,fg_color) main()