import timeimport thumbyimport math# BITMAP: width: 32, height: 32bitmap0 = (0,0,0,0,0,0,0,0,248,8,232,40,40,40,40,40,40,40,40,40,40,232,8,248,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,255,0,63,32,32,32,32,32,32,32,32,32,32,63,0,255,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,255,0,12,12,63,63,12,12,0,0,24,24,3,3,0,255,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,31,16,16,16,16,20,18,16,20,18,16,16,16,16,16,31,0,0,0,0,0,0,0,0)while(1): t0 = time.ticks_ms() # Get time (ms) thumby.display.fill(0) # Fill canvas to black bobRate = 250 # Set arbitrary bob rate (higher is slower) bobRange = 5 # How many pixels to move the sprite up/down (-5px ~ 5px) # Calculate number of pixels to offset sprite for bob animation bobOffset = math.sin(t0 / bobRate) * bobRange # Center the sprite using screen and bitmap dimensions and apply bob offset spriteX = int((thumby.DISPLAY_W/2) - (32/2)) spriteY = int(round((thumby.DISPLAY_H/2) - (32/2) + bobOffset)) # Draw sprite normally (0 & 1 pixels drawn) thumby.display.blit(bitmap0, spriteX, spriteY, 32, 32) # Draw sprite halfway overlapping the last sprite but do not draw 0 or black pixels thumby.display.blit(bitmap0, spriteX+8, spriteY, 32, 32, 0) thumby.display.update()