forked from badger/home
-
Notifications
You must be signed in to change notification settings - Fork 0
Add Christmas countdown app with falling snowflakes #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dceb3ea
Initial plan
Copilot 1eb11b2
Add Christmas countdown app with falling snowflakes
Copilot 5f6fdce
Fix date calculation for leap years and year boundaries
Copilot 6444d73
Reorder text layout and optimize performance
Copilot 16c0b05
Improve variable naming for clarity in next year calculation
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import time | ||
| import random | ||
| from badgeware import screen, PixelFont, shapes, brushes, io, run, Matrix | ||
|
|
||
| # Christmas colors | ||
| BG_COLOR = (10, 20, 40) # Dark blue night sky | ||
| TEXT_COLOR = (255, 255, 255) # White text | ||
| SNOWFLAKE_COLOR = (240, 248, 255) # Light snow color | ||
|
|
||
| # Pre-create brushes for performance | ||
| BG_BRUSH = brushes.color(*BG_COLOR) | ||
| TEXT_BRUSH = brushes.color(*TEXT_COLOR) | ||
| SNOWFLAKE_BRUSH = brushes.color(*SNOWFLAKE_COLOR) | ||
|
|
||
| # Load font | ||
| large_font = PixelFont.load("/system/assets/fonts/ziplock.ppf") | ||
| small_font = PixelFont.load("/system/assets/fonts/nope.ppf") | ||
|
|
||
| class Snowflake: | ||
| """A single falling snowflake""" | ||
| def __init__(self): | ||
| self.reset() | ||
|
|
||
| def reset(self): | ||
| """Reset snowflake to top of screen with random properties""" | ||
| self.x = random.randint(0, 160) | ||
| self.y = random.randint(-20, 0) # Start slightly above screen | ||
| self.size = random.randint(1, 2) # Small snowflakes | ||
| self.speed = random.uniform(0.3, 0.8) # Gentle fall speed | ||
| self.drift = random.uniform(-0.2, 0.2) # Slight horizontal drift | ||
|
|
||
| def update(self): | ||
| """Update snowflake position""" | ||
| self.y += self.speed | ||
| self.x += self.drift | ||
|
|
||
| # Reset if fallen off screen | ||
| if self.y > 120: | ||
| self.reset() | ||
|
|
||
| # Wrap horizontally | ||
| if self.x < 0: | ||
| self.x = 160 | ||
| elif self.x > 160: | ||
| self.x = 0 | ||
|
|
||
| def draw(self): | ||
| """Draw the snowflake""" | ||
| screen.brush = SNOWFLAKE_BRUSH | ||
| screen.draw(shapes.circle(int(self.x), int(self.y), self.size)) | ||
|
|
||
| # Create snowflakes | ||
| snowflakes = [Snowflake() for _ in range(15)] | ||
|
|
||
| # Base days in each month (non-leap year) | ||
| BASE_DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | ||
|
|
||
| def get_days_until_christmas(): | ||
| """Calculate days until next Christmas (Dec 25)""" | ||
| now = time.localtime() | ||
| current_year = now[0] | ||
| current_month = now[1] | ||
| current_day = now[2] | ||
|
|
||
| # Determine which Christmas to count down to | ||
| christmas_year = current_year | ||
| if current_month == 12 and current_day > 25: | ||
| # After Christmas, count to next year | ||
| christmas_year += 1 | ||
|
|
||
| # Helper function to get days in month for a specific year | ||
| def get_days_in_month(year): | ||
| days = BASE_DAYS_IN_MONTH.copy() | ||
| is_leap = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) | ||
| if is_leap: | ||
| days[1] = 29 | ||
| return days | ||
|
|
||
| # Calculate day of year for current date | ||
| current_days_in_month = get_days_in_month(current_year) | ||
| current_day_of_year = sum(current_days_in_month[:current_month-1]) + current_day | ||
|
|
||
| # Calculate day of year for Christmas | ||
| if christmas_year == current_year: | ||
| # Christmas this year | ||
| christmas_day_of_year = sum(current_days_in_month[:11]) + 25 # December 25 | ||
| days_left = christmas_day_of_year - current_day_of_year | ||
| else: | ||
| # Christmas next year | ||
| days_left_this_year = sum(current_days_in_month) - current_day_of_year | ||
| # Calculate days from Jan 1 to Christmas in next year | ||
| next_year_days = get_days_in_month(christmas_year) | ||
| days_jan1_to_christmas = sum(next_year_days[:11]) + 25 # Jan 1 to Dec 25 | ||
| days_left = days_left_this_year + days_jan1_to_christmas | ||
|
|
||
| return max(0, days_left) | ||
|
|
||
| def update(): | ||
| # Clear screen with dark blue background | ||
| screen.brush = BG_BRUSH | ||
| screen.clear() | ||
|
|
||
| # Update and draw snowflakes (backdrop) | ||
| for snowflake in snowflakes: | ||
| snowflake.update() | ||
| snowflake.draw() | ||
|
|
||
| # Calculate days until Christmas | ||
| days = get_days_until_christmas() | ||
|
|
||
| # Draw countdown | ||
| screen.font = large_font | ||
| screen.brush = TEXT_BRUSH | ||
|
|
||
| # Main number (at top) | ||
| days_text = str(days) | ||
| w, h = screen.measure_text(days_text) | ||
| screen.text(days_text, 80 - (w // 2), 30) | ||
|
|
||
| # Labels | ||
| screen.font = small_font | ||
| label = "days until" | ||
| w, _ = screen.measure_text(label) | ||
| screen.text(label, 80 - (w // 2), 60) | ||
|
|
||
| label2 = "Christmas" | ||
| w, _ = screen.measure_text(label2) | ||
| screen.text(label2, 80 - (w // 2), 75) | ||
|
|
||
| if __name__ == "__main__": | ||
| run(update) | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.