Rotate silly guy parts

This commit is contained in:
2026-03-10 20:45:55 -04:00
parent f59fb3131e
commit 1f7c589d80

View File

@@ -1,9 +1,9 @@
#include "palette_manip.h" #include "palette_manip.h"
#include <pebble.h> #include <pebble.h>
// declare general static pointers // declare general statics
static Window *s_main_window; static Window *s_main_window;
static GFont custom_font; static GFont s_custom_font;
static TextLayer *s_time_layer; static TextLayer *s_time_layer;
static BitmapLayer *s_guy_head_layer; static BitmapLayer *s_guy_head_layer;
static BitmapLayer *s_guy_butt_layer; static BitmapLayer *s_guy_butt_layer;
@@ -17,14 +17,16 @@ static GBitmap *s_head_next;
static GBitmap *s_butt_next; static GBitmap *s_butt_next;
// declare lookup tables // declare lookup tables
static const uint32_t randomHeadPool[] = { static const uint8_t s_head_count = 22;
static const uint32_t s_random_heads[] = {
RESOURCE_ID_H001, RESOURCE_ID_H002, RESOURCE_ID_H003, RESOURCE_ID_H004, RESOURCE_ID_H001, RESOURCE_ID_H002, RESOURCE_ID_H003, RESOURCE_ID_H004,
RESOURCE_ID_H005, RESOURCE_ID_H006, RESOURCE_ID_H007, RESOURCE_ID_H008, RESOURCE_ID_H005, RESOURCE_ID_H006, RESOURCE_ID_H007, RESOURCE_ID_H008,
RESOURCE_ID_H009, RESOURCE_ID_H010, RESOURCE_ID_H011, RESOURCE_ID_H012, RESOURCE_ID_H009, RESOURCE_ID_H010, RESOURCE_ID_H011, RESOURCE_ID_H012,
RESOURCE_ID_H013, RESOURCE_ID_H014, RESOURCE_ID_H015, RESOURCE_ID_H016, RESOURCE_ID_H013, RESOURCE_ID_H014, RESOURCE_ID_H015, RESOURCE_ID_H016,
RESOURCE_ID_H017, RESOURCE_ID_H018, RESOURCE_ID_H019, RESOURCE_ID_H020, RESOURCE_ID_H017, RESOURCE_ID_H018, RESOURCE_ID_H019, RESOURCE_ID_H020,
RESOURCE_ID_H021, RESOURCE_ID_H022}; RESOURCE_ID_H021, RESOURCE_ID_H022};
static const uint32_t randomButtPool[] = { static const uint8_t s_butt_count = 26;
static const uint32_t s_random_butts[] = {
RESOURCE_ID_B001, RESOURCE_ID_B002, RESOURCE_ID_B003, RESOURCE_ID_B004, RESOURCE_ID_B001, RESOURCE_ID_B002, RESOURCE_ID_B003, RESOURCE_ID_B004,
RESOURCE_ID_B005, RESOURCE_ID_B006, RESOURCE_ID_B007, RESOURCE_ID_B008, RESOURCE_ID_B005, RESOURCE_ID_B006, RESOURCE_ID_B007, RESOURCE_ID_B008,
RESOURCE_ID_B009, RESOURCE_ID_B010, RESOURCE_ID_B011, RESOURCE_ID_B012, RESOURCE_ID_B009, RESOURCE_ID_B010, RESOURCE_ID_B011, RESOURCE_ID_B012,
@@ -32,7 +34,8 @@ static const uint32_t randomButtPool[] = {
RESOURCE_ID_B017, RESOURCE_ID_B018, RESOURCE_ID_B019, RESOURCE_ID_B020, RESOURCE_ID_B017, RESOURCE_ID_B018, RESOURCE_ID_B019, RESOURCE_ID_B020,
RESOURCE_ID_B021, RESOURCE_ID_B022, RESOURCE_ID_XB001, RESOURCE_ID_XB002, RESOURCE_ID_B021, RESOURCE_ID_B022, RESOURCE_ID_XB001, RESOURCE_ID_XB002,
RESOURCE_ID_XB003, RESOURCE_ID_XB004}; RESOURCE_ID_XB003, RESOURCE_ID_XB004};
static const GColor8 darkBGColorPool[] = { static const uint8_t s_color_count = 22;
static const GColor8 s_dark_bg_colors[] = {
// Red // Red
GColorFolly, GColorRed, GColorFolly, GColorRed,
// Orange // Orange
@@ -50,7 +53,7 @@ static const GColor8 darkBGColorPool[] = {
// Brown // Brown
GColorRoseVale}; GColorRoseVale};
static void update_minute() { static void update_minute_1() {
// get a tm structure // get a tm structure
time_t temp = time(NULL); time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp); struct tm *tick_time = localtime(&temp);
@@ -63,8 +66,46 @@ static void update_minute() {
text_layer_set_text(s_time_layer, s_time_buffer); text_layer_set_text(s_time_layer, s_time_buffer);
} }
static void update_minute_30() {
update_minute_1();
// update butt on half-hour boundaries
gbitmap_destroy(s_butt_current);
s_butt_current = s_butt_next;
replace_gbitmap_color(GColorGreen, s_random_color_next, s_butt_current, NULL);
replace_gbitmap_color(s_random_color_current, s_random_color_next, s_head_current, NULL);
// update current color so it can be referenced for later replacement
s_random_color_current = s_random_color_next;
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);
// calc next values
s_butt_next = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // next color
}
static void update_minute_60() {
update_minute_1();
// update head on hour boundaries
gbitmap_destroy(s_head_current);
s_head_current = s_head_next;
replace_gbitmap_color(GColorGreen, s_random_color_next, s_head_current, NULL);
replace_gbitmap_color(s_random_color_current, s_random_color_next, s_butt_current, NULL);
// update current color so it can be referenced for later replacement
s_random_color_current = s_random_color_next;
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
// calc next values
s_head_next = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // next color
}
static void minute_handler(struct tm *tick_time, TimeUnits units_changed) { static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
update_minute(); if (tick_time->tm_min % 60 == 0) {
update_minute_60();
} else if (tick_time->tm_min % 30 == 0) {
update_minute_30();
} else {
update_minute_1();
}
} }
// define contents of the Window upon load // define contents of the Window upon load
@@ -82,7 +123,7 @@ static void main_window_load(Window *window) {
// set up info layers // set up info layers
s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(110, 94), PBL_IF_ROUND_ELSE(260, 200), 32)); s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(110, 94), PBL_IF_ROUND_ELSE(260, 200), 32));
text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_background_color(s_time_layer, GColorClear);
text_layer_set_font(s_time_layer, custom_font); text_layer_set_font(s_time_layer, s_custom_font);
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
// add layers as children to window // add layers as children to window
@@ -110,25 +151,26 @@ static void init() {
.unload = main_window_unload}); .unload = main_window_unload});
// load initial batch of silly guy parts into memory // load initial batch of silly guy parts into memory
s_head_current = gbitmap_create_with_resource(randomHeadPool[rand() % 22]); s_head_current = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
s_butt_current = gbitmap_create_with_resource(randomButtPool[rand() % 26]); s_butt_current = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
s_head_next = gbitmap_create_with_resource(randomHeadPool[rand() % 22]); s_head_next = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
s_butt_next = gbitmap_create_with_resource(randomButtPool[rand() % 26]); s_butt_next = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
// pick starting colors // pick starting colors
s_random_color_current = darkBGColorPool[rand() % 22]; s_random_color_current = s_dark_bg_colors[rand() % s_color_count];
s_random_color_next = darkBGColorPool[rand() % 22];
replace_gbitmap_color(GColorGreen, s_random_color_current, s_head_current, NULL); replace_gbitmap_color(GColorGreen, s_random_color_current, s_head_current, NULL);
replace_gbitmap_color(GColorGreen, s_random_color_current, s_butt_current, NULL); replace_gbitmap_color(GColorGreen, s_random_color_current, s_butt_current, NULL);
// don't overwrite current color, as it will need to be replaced
s_random_color_next = s_dark_bg_colors[rand() % s_color_count];
// load custom font // load custom font
custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_RETRO_COMPUTER_32)); s_custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_RETRO_COMPUTER_32));
// show the Window on the watch, with animated=true // show the Window on the watch, with animated=true
window_stack_push(s_main_window, true); window_stack_push(s_main_window, true);
// make sure the time is displayed from the start // make sure the time is displayed from the start
update_minute(); update_minute_1();
// register with TickTimerService // register with TickTimerService
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler); tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
@@ -141,6 +183,7 @@ static void deinit() {
gbitmap_destroy(s_butt_current); gbitmap_destroy(s_butt_current);
gbitmap_destroy(s_head_next); gbitmap_destroy(s_head_next);
gbitmap_destroy(s_butt_next); gbitmap_destroy(s_butt_next);
fonts_unload_custom_font(s_custom_font);
window_destroy(s_main_window); window_destroy(s_main_window);
} }