Skip to content

Commit

Permalink
Made themes a bit easier - new themes can be added to themes.py and n…
Browse files Browse the repository at this point in the history
…eopix.py can be left alone
  • Loading branch information
naztronaut committed Apr 25, 2020
1 parent cdaddb8 commit 76fd926
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
18 changes: 4 additions & 14 deletions RaspberryPi/neopix.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,11 @@
def theme_colors():
if theme == 'random':
return random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
elif theme == 'valentines':
valentines_size = len(themes.valentines)
# return random.randint(0, 255), random.randint(0, 128), random.randint(0, 36)
chosen_color = themes.valentines[random.randint(0, valentines_size)-1]
return chosen_color[0], chosen_color[1], chosen_color[2]
elif theme == 'cool':
cool_size = len(themes.cool)
chosen_color = themes.cool[random.randint(0, cool_size)-1]
return chosen_color[0], chosen_color[1], chosen_color[2]
elif theme == 'nature':
nature_size = len(themes.nature)
chosen_color = themes.nature[random.randint(0, nature_size)-1]
return chosen_color[0], chosen_color[1], chosen_color[2]
else:
print("Unknown theme. Choose from valentines, cool, nature, and random only")
chosen_theme = themes.pick_theme(theme)
size = len(chosen_theme)
color = chosen_theme[random.randint(0, size-1)]
return color[0], color[1], color[2]


if led_status == 'on':
Expand Down
13 changes: 12 additions & 1 deletion RaspberryPi/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@
[0, 55, 0],
[0, 128, 128],
[128, 128, 0]
]
]


def pick_theme(theme):
if theme == 'valentines':
return valentines
elif theme == 'cool':
return cool
elif theme == 'nature':
return nature
else:
return valentines # Default will be sent if the theme doesn't match anything else

0 comments on commit 76fd926

Please sign in to comment.