'''
April Showers - Monthly Special Project
'''
from codex import *
import time
import random

def background():
    display.clear()
    display.fill_rect(0, 200, 240, 40, DARK_GREEN)
    display.draw_text("April", x=75, y=40, scale=3, color=YELLOW)
    display.draw_text("Showers", x=55, y=70, scale=3, color=PINK)
    display.draw_text("Shake=Rain A=Flowers", x=0, y=215, scale=2, color=WHITE)

def rain(x, y):
    display.draw_line(x+10, y, x+10, y+20, GRAY)

def rain_type():
    '''Determine the type of rain by the amount of shaking.
       Return: True if shaken, the gap between rain lines, 
               the number of rain loops, and the delay (speed).'''
    curr = accel.read()
    time.sleep(0.2)
    count = 0
    for x in range(20):
        val = accel.read()
        if abs(curr[0]-val[0])>800 or abs(curr[1]-val[1])>800:
            count = count + 1
        curr = val
        time.sleep(0.1)
    #TODO: Return values for is_shaken, gap, rain_loops and delay
    if count >= 12:     # Heavy rain, lots of shaking
        return True, 5, 6, 0.003
    elif count >= 8:    # Regular rain
        return True, 10, 4, 0.08
    elif count >= 4:    # Light rain, gentle shake
        return True, 15, 2, 0.3
    else:                # No rain, no shaking
        return False, 0, 0, 0

def fill_lines(gap):
    global lines
    x = 5
    lines = []
    for i in range(240//gap):
        lines.append([x, random.randrange(1, 20)])
        x = x + gap

# === MAIN PROGRAM ===
background()
# -- for testing, displays on the console
fill_lines(15)
print(lines)
