static void draw_strands(Layer* layer, GContext * ctx) { //Strands graphics_context_set_stroke_color(ctx, GColorYellow); int direction_last = DOWN; uint8_t n_strands = (lantern_inner_width/STRAND_SEP)+1; for(int s=0; s< n_strands; s++) { GPoint strand = (GPoint){inner_offset_x + s*STRAND_SEP, 0}; graphics_draw_pixel(ctx, strand); graphics_draw_pixel(ctx, (GPoint){strand.x+1, strand.y}); for(int i=0;i<real_strand_len;i++) { int direction = strand_directions[i]; if(rand() % P_CONFORMS == 0) // usually follow the other strands, but sometimes don't conform direction = rand() % (N_DIRS); if(direction > RIGHT + N_GRAVITY + N_BIAS) { //Persistence direction = direction_last; } else if(direction > RIGHT + N_GRAVITY + N_BIAS) { //Wind bias direction direction = bias; } else if(direction > RIGHT) { direction = DOWN; } if(direction == DOWN) strand.y++; else if(direction == LEFT) strand.x--; else if(direction == RIGHT) strand.x++; graphics_draw_pixel(ctx, strand); graphics_draw_pixel(ctx, (GPoint){strand.x+1, strand.y}); graphics_draw_pixel(ctx, (GPoint){strand.x, strand.y+1}); direction_last = direction; } } }
static void put_pixel(void* ctx, int x, int y, int minuteY) { if (y < minuteY && (x + y) % 2 == 0) { graphics_draw_pixel(ctx, GPoint(x, y)); } else if (y >= minuteY) { graphics_draw_pixel(ctx, GPoint(x, y)); } }
static void hour_display_update_proc(Layer *layer, GContext* ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); unsigned int angle = (t->tm_hour % 12) * 30; GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, center, 48); for (unsigned int i = 0; i < 360; i += 15) { if ((i != angle) && (i != (angle + 15)) && (i != ((angle - 15 + 360) % 360)) ) { gpath_rotate_to(s_hour_segment_path, (TRIG_MAX_ANGLE / 360) * i); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, s_hour_segment_path); } } // Stray pixels graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, center, 5); graphics_context_set_stroke_color(ctx, GColorBlack); if ((angle != 0) && (angle != 330)) { graphics_draw_pixel(ctx, GPoint(71, 77)); graphics_draw_pixel(ctx, GPoint(71, 78)); } }
void month_display_layer_update_callback(Layer *me, GContext* ctx) { (void)me; PblTm t; get_time(&t); unsigned int angle = (t.tm_mon + 1) * 15; GPoint center = grect_center_point(&me->frame); center.y += 10; graphics_context_set_fill_color(ctx, GColorWhite); graphics_draw_arc(ctx, center, 42, 20, 0, angle); //graphics_draw_line(ctx, GPoint(7, center.y), GPoint(20, center.y)); //graphics_draw_line(ctx, GPoint(124, center.y), GPoint(137, center.y)); for (int x = 0; x < 2; x++) for (int y = 0; y < 2; y++) { graphics_draw_pixel(ctx, GPoint(center.x - 01 + x, center.y + 18 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 13 + x, center.y + 13 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 13 + x, center.y + 13 + y)); } }
/* * Progress line */ EXTFN void progress_layer_update_callback(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, BACKGROUND_COLOR); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); graphics_context_set_fill_color(ctx, BAR_CHART_MARKS); graphics_context_set_stroke_color(ctx, BAR_CHART_MARKS); graphics_context_set_stroke_width(ctx, 2); for (uint8_t i = 0; i <= 120; i += 12) { graphics_draw_pixel(ctx, GPoint(i, 8)); graphics_draw_pixel(ctx, GPoint(i, 7)); } for (uint8_t i = 0; i <= get_internal_data()->highest_entry; i++) { if (!get_internal_data()->ignore[i]) { uint16_t height = get_internal_data()->points[i] / 500; uint8_t i2 = i * 2; #ifdef PBL_COLOR graphics_context_set_stroke_color(ctx, bar_color(height)); #endif graphics_draw_line(ctx, GPoint(i2, 8 - height), GPoint(i2, 8)); } } }
static void hour_display_layer_update_callback(Layer *layer, GContext* ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); // Because of how we're drawing the segments I'm not currently // accounting for per-minute moving of the hour hand. //unsigned int angle = (((t.tm_hour % 12) * 30) + (t.tm_min/2)); unsigned int angle = (t->tm_hour % 12) * 30; GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, center, 48); for (unsigned int i = 0; i < 360; i+=15) { if ((i != angle) && (i != (angle + 15)) && (i != ((angle-15+360) % 360)) ) { gpath_rotate_to(hour_segment_path, (TRIG_MAX_ANGLE / 360) * i); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, hour_segment_path); } } // Due to (I assume) rounding/precision errors with rotation // of paths there's a few stray pixels left behind after the // above method of drawing segments. // This draws a circle over almost all the stray pixels--at the // cost of not quite matching the mock-up. graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, center, 5); // But there's still two stray pixels left--and enlarging the cover // up circle to fit them starts to be obvious so we touch them up // individually. graphics_context_set_stroke_color(ctx, GColorBlack); if ((angle != 0) && (angle != 330)) { graphics_draw_pixel(ctx, GPoint(71, 77)); graphics_draw_pixel(ctx, GPoint(71, 78)); } }
static void update_particles(Layer *layer, GContext *ctx) { int i = 0; for( i = 0 ; i < MAX_DOTS; i++ ) { dotVelocity[i] += GRAVITY * TICK_RATE_MS; // dotY[i] += 1.0/(dotVelocity[i] * TICK_RATE_MS)*80000; // fix these scaling hacks. // dotX[i] += 1.0 + (dotVelocity[i] * TICK_RATE_MS)/100000; dotY[i] += 1.0/(dotVelocity[i] * TICK_RATE_MS)*x_scaling_factor; // fix these scaling hacks. dotX[i] += 1.0 + (dotVelocity[i] * TICK_RATE_MS)/y_scaling_factor; // dotY[i] += (dotVelocity[i] * TICK_RATE_MS)/s_scaling_factor; // fix these scaling hacks. // dotX[i] += (dotVelocity[i] * TICK_RATE_MS)/s_scaling_factor; // dotX[i] += sin( angle * 180.0/3.1415967) * 4; if( enableZigZagging ) { dotX[i] += sin( i * 180.0 / 3.1415967) * zigZagDepth; // give it some zig-zag. dotY[i] += cos( i * 180.0 / 3.1415967) * zigZagDepth; // give it some zig-zag. } if ( (dotX[i] >= 144) || (dotX[i] <= 1) ) { dotX[i] = s_sprite->x + s_sprite->offset_x + rand() % 10; dotY[i] = s_sprite->y + s_sprite->offset_y + rand() % 15; dotVelocity[i] = 1 + (rand() % 2)/0.3; } if( (dotY[i] >= 168) || (dotY[i] <= 1) ) { dotX[i] = s_sprite->x + s_sprite->offset_x + rand() % 10; dotY[i] = s_sprite->y + s_sprite->offset_y + rand() % 15; dotVelocity[i] = 1 + (rand() % 2)/0.3; } graphics_draw_pixel(ctx,GPoint( dotX[i], dotY[i])); } }
static void paint_battery_icon(BatteryIcon *aIcon, GContext *aCtx, GRect r, GPoint aCenter, int32_t aRadius, bool aZoomedIn) { graphics_context_set_stroke_color(aCtx, GColorWhite); uint8_t percent = battery_icon_get_percent(aIcon); #ifdef PBL_COLOR graphics_context_set_fill_color(aCtx, GColorMalachite); graphics_fill_circle(aCtx, aCenter, aRadius); #endif for (int32_t x = 0; x < r.size.w; ++x) { for (int32_t y = 0; y < r.size.h; ++y) { if (point_in_circle(x-aCenter.x, y-aCenter.y, aCenter.y)) { graphics_context_set_stroke_color(aCtx, GColorWhite); if (!point_in_arc(percent, x-aCenter.x, y-aCenter.y, aCenter.y)) { #ifdef PBL_COLOR graphics_context_set_stroke_color(aCtx, GColorDarkGray); graphics_draw_pixel(aCtx, GPoint(x, y)); #else if (pattern25(x,y)) { graphics_context_set_stroke_color(aCtx, GColorBlack); } #endif } #ifndef PBL_COLOR graphics_draw_pixel(aCtx, GPoint(x, y)); #endif } } } graphics_context_set_fill_color(aCtx, GColorBlack); graphics_fill_circle(aCtx, aCenter, aRadius * (1.f-RING_WIDTH)); // text static char buffer[] = "100"; snprintf(buffer, sizeof(buffer)/sizeof(buffer[0]), "%d", percent); graphics_draw_text(aCtx, buffer, fonts_get_system_font(BATTERY_FONT), GRect(0, (r.size.h - BATTERY_TEXT_ADJUSTMENT) / 2, r.size.w, BATTERY_FONT_SIZE), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); }
static void update_proc_draw_pixel(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GPoint pixel = GPoint(0, 0); for (int i=0; i<bounds.size.w; i++){ for (int j=0; j<bounds.size.h; j++){ pixel.x=i; pixel.y=j; graphics_context_set_stroke_color(ctx, rand() % 2 ? GColorWhite: GColorBlack); graphics_draw_pixel(ctx, pixel); } } }
static void charge_layer_update_callback(Layer *layer, GContext *ctx) { BatteryChargeState batChargeState = battery_state_service_peek(); GColor charge_color = GColorClear; // Select color for battery charge if (batChargeState.charge_percent >= 60) { charge_color = GColorGreen; } else if (batChargeState.charge_percent >= 25) { charge_color = GColorChromeYellow; } else { charge_color = GColorRed; } // Fill the battery frame graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, s_bat_frame_path_ptr); // Draw battery charge graphics_context_set_fill_color(ctx, charge_color); int h = (100 - batChargeState.charge_percent) / 5 + 1; graphics_fill_rect(ctx, GRect(3, h, 8, 21 - h), 0, GCornerNone); // Clear overwritten part (outside of battery) graphics_context_set_stroke_color(ctx, GColorClear); graphics_draw_pixel(ctx, GPoint(3, 1)); graphics_draw_pixel(ctx, GPoint(10, 1)); // Stroke the battery frame graphics_context_set_stroke_color(ctx, (conf.fiboDisplay == FiboDispZoomed) ? s_legibleColor : gcolor_legible_over(conf.backgroundColor)); gpath_draw_outline(ctx, s_bat_frame_path_ptr); graphics_context_set_compositing_mode(ctx, GCompOpSet); if (batChargeState.is_charging) { // Draw charging icon graphics_draw_bitmap_in_rect(ctx, s_charging_image, gbitmap_get_bounds(s_charging_image)); } else if (batChargeState.is_plugged) { // Draw plugged icon graphics_draw_bitmap_in_rect(ctx, s_plugged_image, gbitmap_get_bounds(s_plugged_image)); } }
void path_layer_update_callback(Layer *me, GContext *ctx) { (void)me; graphics_context_set_stroke_color(ctx, GColorBlack); GPoint p0, p1; if (nb_points < 2) { return; } for (int i = 0; i < ((nb_points > NUM_POINTS ? NUM_POINTS : nb_points) - 1); i++) { p0 = pts[(NUM_POINTS+cur_point-i) % NUM_POINTS]; p1 = pts[(NUM_POINTS+cur_point-i-1) % NUM_POINTS]; p0.x = (XINI + (p0.x * SCREEN_W / (map_scale/10))) % MAP_VSIZE_X; p0.y = (YINI - (p0.y * SCREEN_W / (map_scale/10))) % MAP_VSIZE_Y; p1.x = (XINI + (p1.x * SCREEN_W / (map_scale/10))) % MAP_VSIZE_X; p1.y = (YINI - (p1.y * SCREEN_W / (map_scale/10))) % MAP_VSIZE_Y; graphics_draw_line( ctx, p0, p1 ); } for (int i = 0; i < s_live.nb; i++) { p0.x = (XINI + (s_live.friends[i].xpos * SCREEN_W / (map_scale/10))) % MAP_VSIZE_X; p0.y = (YINI - (s_live.friends[i].ypos * SCREEN_W / (map_scale/10))) % MAP_VSIZE_Y; graphics_draw_pixel(ctx, p0); graphics_draw_circle(ctx, p0, 3); if (i == 0) { #if DEBUG snprintf(s_data.debug2, sizeof(s_data.debug2), "%d|%d\n" "%d|%d\n" "%d|%d\n" "%d|%d\n", s_live.friends[i].xpos,s_live.friends[i].ypos, p0.x,p0.y, pathFrame.origin.x,pathFrame.origin.y, s_live.friends[i].name_frame.origin.x,s_live.friends[i].name_frame.origin.y ); #endif } } }
void dim_layer_update_proc(DimLayer* dim_layer, GContext *ctx) { DimLayerData* data = layer_get_data(dim_layer); GRect bounds = layer_get_bounds(dim_layer); graphics_context_set_stroke_color(ctx, (data->dim_mode == DimModeBright ? GColorWhite : GColorBlack)); for (register int16_t y = bounds.origin.y; y < bounds.origin.y + bounds.size.h; y++) { for (register int16_t x = bounds.origin.x + y % 2; x < bounds.origin.x + bounds.size.w; x += 2) { graphics_draw_pixel(ctx, GPoint(x, y)); } } }
/* * Draws linear gradient using graphics_draw_pixel() + draws info about used method. */ static void update_proc_draw_pixel(Layer *layer, GContext *ctx) { // determines gray value per row, // calculates dithered pixel color per pixel, and // uses graphics_draw_pixel for each pixel to draw the actual color for (int16_t y = 0; y < s_window_size.h; y++) { const uint8_t row_gray = gray_for_row(y); for (int16_t x = 0; x < s_window_size.w; x++) { graphics_context_set_stroke_color(ctx, color_for_gray(x, y, row_gray)); graphics_draw_pixel(ctx, GPoint(x, y)); } } draw_method_feedback(ctx, "draw_pixel"); }
static void draw_tile(GContext* ctx, size_t x, size_t y, bool fg) { for (size_t j = 0; j < TILE_SIZE; j++) { for (size_t i = 0; i < TILE_SIZE; i++) { if (get_pixel(i, j, fg)) { graphics_context_set_stroke_color(ctx, backColor); } else { graphics_context_set_stroke_color(ctx, foreColor); } graphics_draw_pixel(ctx, GPoint( ORIGIN_X + x*TILE_SIZE + i, ORIGIN_Y + y*TILE_SIZE + j)); } } };
void graphics_draw_arc(GContext *ctx, GPoint p, int radius, int thickness, int start, int end) { start = start % 360; end = end % 360; while (start < 0) start += 360; while (end < 0) end += 360; if (end == 0) end = 360; float sslope = (float)cos_lookup(start * TRIG_MAX_ANGLE / 360) / (float)sin_lookup(start * TRIG_MAX_ANGLE / 360); float eslope = (float)cos_lookup(end * TRIG_MAX_ANGLE / 360) / (float)sin_lookup(end * TRIG_MAX_ANGLE / 360); if (end == 360) eslope = -1000000; int ir2 = (radius - thickness) * (radius - thickness); int or2 = radius * radius; for (int x = -radius; x <= radius; x++) for (int y = -radius; y <= radius; y++) { int x2 = x * x; int y2 = y * y; if ( (x2 + y2 < or2 && x2 + y2 >= ir2) && ( (y > 0 && start < 180 && x <= y * sslope) || (y < 0 && start > 180 && x >= y * sslope) || (y < 0 && start <= 180) || (y == 0 && start <= 180 && x < 0) || (y == 0 && start == 0 && x > 0) ) && ( (y > 0 && end < 180 && x >= y * eslope) || (y < 0 && end > 180 && x <= y * eslope) || (y > 0 && end >= 180) || (y == 0 && end >= 180 && x < 0) || (y == 0 && start == 0 && x > 0) ) ) graphics_draw_pixel(ctx, GPoint(p.x + x, p.y + y)); } }
void draw_ticks(GContext *ctx, GPoint center, int radius, int num_ticks, int ticks_modulo, int thick) { graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_fill_color(ctx, GColorWhite); for (int i = 0; i < num_ticks; i += 1) { GPoint p = tick_point(center, radius, i * 360 / num_ticks); if (i % ticks_modulo == 0) { if (thick) { graphics_fill_rect(ctx, GRect(p.x - 1, p.y - 1, 3, 3), 0, GCornerNone); } else { GPoint p1 = tick_point(center, radius + 1, i * 360 / num_ticks); GPoint p2 = tick_point(center, radius - 1, i * 360 / num_ticks); graphics_context_set_stroke_width(ctx, 1); graphics_draw_line(ctx, p1, p2); } } else { graphics_draw_pixel(ctx, p); } } }
void update_graph(struct Layer* layer, GContext* ctx) { graphics_context_set_fill_color(ctx, BG_COLOR); graphics_fill_rect(ctx, FULL_SCREEN, 0, GCornerNone); float hourpos = 12 - (hours + minutes / 60.0f); float minpos = (minutes) / 5.0f; graphics_context_set_stroke_color(ctx, TIME_COLOR); graphics_draw_line(ctx, GPoint((int)(18 + 9 * minpos), 22), GPoint((int)(18 + 9 * minpos), 146)); graphics_draw_line(ctx, GPoint(10, (int)(30 + 9 * hourpos)), GPoint(134, (int)(30 + 9 * hourpos))); graphics_draw_circle(ctx, GPoint((int)(18 + 9 * minpos), (int)(30 + 9 * hourpos)), 2); graphics_context_set_stroke_color(ctx, TEXT_COLOR); for (int i = 0; i < 13; i++) for (int j = 0; j < 13; j++) graphics_draw_pixel(ctx, GPoint(18 + 9 * i, 30 + 9 * j)); graphics_draw_rect(ctx, GRect(9, 21, 126, 126)); }
void update_layer(Layer *me, GContext* ctx) { //watchface drawing char text[10]; graphics_context_set_stroke_color(ctx,GColorWhite); graphics_context_set_text_color(ctx, GColorWhite); //draw background graphics_draw_bitmap_in_rect(ctx,background,GRect(0,0,144,168)); //get tick_time time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); //get weekday strftime(text, 10, "%A", tick_time); //lowercase text[0] += 32; if(weekday == 1) graphics_draw_text(ctx, text, raleway_font, GRect(0,-6,144,100), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); //dumb friday fix if(text[0] == 'f'){ graphics_draw_pixel(ctx, GPoint(49,0)); graphics_draw_pixel(ctx, GPoint(50,0)); } strftime(text, 10, "%d", tick_time); if(date == 1) graphics_draw_text(ctx, text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(0,62,144,100), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); strftime(text, 10, "%B", tick_time); //lowercase text[0] += 32; if(month == 1) graphics_draw_text(ctx, text, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(0,114,144,100), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); //draw hands GPoint center = GPoint(71,99); int16_t secondHandLength = 64; int16_t minuteHandLength = 54; int16_t hourHandLength = 34; GPoint secondHand; GPoint minuteHand; GPoint hourHand; int32_t second_angle = TRIG_MAX_ANGLE * tick_time->tm_sec / 60; secondHand.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.y; secondHand.x = (int16_t)(sin_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.x; if(seconds == 1) graphics_draw_line(ctx, center, secondHand); int32_t minute_angle = TRIG_MAX_ANGLE * tick_time->tm_min / 60; minuteHand.y = (int16_t)(-cos_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.y; minuteHand.x = (int16_t)(sin_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.x; graphics_draw_line(ctx, center, minuteHand); int32_t hour_angle = (TRIG_MAX_ANGLE * (((tick_time->tm_hour % 12) * 6) + (tick_time->tm_min / 10))) / (12 * 6); hourHand.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.y; hourHand.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.x; graphics_draw_line(ctx, center, hourHand); //I didn't like how a 2px path rotated, so I'm using two lines next to each other //I need to move the pixels from vertically adjacent to horizontally adjacent based on the position bool addX = (tick_time->tm_min > 20 && tick_time->tm_min < 40) || tick_time->tm_min < 10 || tick_time->tm_min > 50; center.x+=addX?1:0; center.y+=!addX?1:0; minuteHand.x+=addX?1:0; minuteHand.y+=!addX?1:0; graphics_draw_line(ctx, center, minuteHand); center.x-=addX?1:0; center.y-=!addX?1:0; addX = (tick_time->tm_hour >= 4 && tick_time->tm_hour <= 8) || tick_time->tm_hour < 2 || tick_time->tm_hour > 10; center.x+=addX?1:0; center.y+=!addX?1:0; hourHand.x+=addX?1:0; hourHand.y+=!addX?1:0; graphics_draw_line(ctx, center, hourHand); }
void draw_tile(GContext* ctx, size_t x, size_t y, bool fg) { if (persist_exists(COLOR1_KEY)) { char colorname[20]; persist_read_string(COLOR1_KEY, colorname, sizeof(colorname)); if(strcmp(colorname, "1") == 0){g_Color1 = GColorPictonBlue;} else if(strcmp(colorname, "2") == 0){g_Color1 = GColorDukeBlue;} else if(strcmp(colorname, "3") == 0){g_Color1 = GColorOxfordBlue;} else if(strcmp(colorname, "4") == 0){g_Color1 = GColorWhite;} else if(strcmp(colorname, "5") == 0){g_Color1 = GColorLightGray;} else if(strcmp(colorname, "6") == 0){g_Color1 = GColorBlack;} else if(strcmp(colorname, "7") == 0){g_Color1 = GColorYellow;} else if(strcmp(colorname, "8") == 0){g_Color1 = GColorChromeYellow;} else if(strcmp(colorname, "9") == 0){g_Color1 = GColorRed;} else if(strcmp(colorname, "10") == 0){g_Color1 = GColorDarkCandyAppleRed;} else if(strcmp(colorname, "11") == 0){g_Color1 = GColorBrightGreen;} else if(strcmp(colorname, "12") == 0){g_Color1 = GColorGreen;} else if(strcmp(colorname, "13") == 0){g_Color1 = GColorIslamicGreen;} else if(strcmp(colorname, "14") == 0){g_Color1 = GColorVividViolet;} else if(strcmp(colorname, "15") == 0){g_Color1 = GColorPurple;} else if(strcmp(colorname, "16") == 0){g_Color1 = GColorImperialPurple;} else {g_Color1 = GColorPictonBlue;} }else {g_Color1 = GColorPictonBlue;} if (persist_exists(COLOR2_KEY)) { char colorname[20]; persist_read_string(COLOR2_KEY, colorname, sizeof(colorname)); if(strcmp(colorname, "1") == 0){g_Color2 = GColorPictonBlue;} else if(strcmp(colorname, "2") == 0){g_Color2 = GColorDukeBlue;} else if(strcmp(colorname, "3") == 0){g_Color2 = GColorOxfordBlue;} else if(strcmp(colorname, "4") == 0){g_Color2 = GColorWhite;} else if(strcmp(colorname, "5") == 0){g_Color2 = GColorLightGray;} else if(strcmp(colorname, "6") == 0){g_Color2 = GColorBlack;} else if(strcmp(colorname, "7") == 0){g_Color2 = GColorYellow;} else if(strcmp(colorname, "8") == 0){g_Color2 = GColorChromeYellow;} else if(strcmp(colorname, "9") == 0){g_Color2 = GColorRed;} else if(strcmp(colorname, "10") == 0){g_Color2 = GColorDarkCandyAppleRed;} else if(strcmp(colorname, "11") == 0){g_Color2 = GColorBrightGreen;} else if(strcmp(colorname, "12") == 0){g_Color2 = GColorGreen;} else if(strcmp(colorname, "13") == 0){g_Color2 = GColorIslamicGreen;} else if(strcmp(colorname, "14") == 0){g_Color2 = GColorVividViolet;} else if(strcmp(colorname, "15") == 0){g_Color2 = GColorPurple;} else if(strcmp(colorname, "16") == 0){g_Color2 = GColorImperialPurple;} else {g_Color2 = GColorBlack;} }else {g_Color2 = GColorBlack;} for (size_t j = 0; j < TILE_SIZE; j++) { for (size_t i = 0; i < TILE_SIZE; i++) { if (get_pixel(i, j, fg)) { graphics_context_set_stroke_color(ctx, g_Color1);//Color1 kirk } else { graphics_context_set_stroke_color(ctx, g_Color2);//Color2 } graphics_draw_pixel(ctx, GPoint( ORIGIN_X + x*TILE_SIZE + i, ORIGIN_Y + y*TILE_SIZE + j)); } } };
/*\ |*| DrawArc function thanks to Cameron MacFarland (http://forums.getpebble.com/profile/12561/Cameron%20MacFarland) \*/ void graphics_draw_arc(GContext *ctx, GPoint center, int radius, int thickness, int start_angle, int end_angle, GColor c) { int32_t xmin = 65535000, xmax = -65535000, ymin = 65535000, ymax = -65535000; int32_t cosStart, sinStart, cosEnd, sinEnd; int32_t r, t; while (start_angle < 0) start_angle += TRIG_MAX_ANGLE; while (end_angle < 0) end_angle += TRIG_MAX_ANGLE; start_angle %= TRIG_MAX_ANGLE; end_angle %= TRIG_MAX_ANGLE; if (end_angle == 0) end_angle = TRIG_MAX_ANGLE; if (start_angle > end_angle) { graphics_draw_arc(ctx, center, radius, thickness, start_angle, TRIG_MAX_ANGLE, c); graphics_draw_arc(ctx, center, radius, thickness, 0, end_angle, c); } else { // Calculate bounding box for the arc to be drawn cosStart = cos_lookup(start_angle); sinStart = sin_lookup(start_angle); cosEnd = cos_lookup(end_angle); sinEnd = sin_lookup(end_angle); r = radius; // Point 1: radius & start_angle t = r * cosStart; if (t < xmin) xmin = t; if (t > xmax) xmax = t; t = r * sinStart; if (t < ymin) ymin = t; if (t > ymax) ymax = t; // Point 2: radius & end_angle t = r * cosEnd; if (t < xmin) xmin = t; if (t > xmax) xmax = t; t = r * sinEnd; if (t < ymin) ymin = t; if (t > ymax) ymax = t; r = radius - thickness; // Point 3: radius-thickness & start_angle t = r * cosStart; if (t < xmin) xmin = t; if (t > xmax) xmax = t; t = r * sinStart; if (t < ymin) ymin = t; if (t > ymax) ymax = t; // Point 4: radius-thickness & end_angle t = r * cosEnd; if (t < xmin) xmin = t; if (t > xmax) xmax = t; t = r * sinEnd; if (t < ymin) ymin = t; if (t > ymax) ymax = t; // Normalization xmin /= TRIG_MAX_RATIO; xmax /= TRIG_MAX_RATIO; ymin /= TRIG_MAX_RATIO; ymax /= TRIG_MAX_RATIO; // Corrections if arc crosses X or Y axis if ((start_angle < angle_90) && (end_angle > angle_90)) { ymax = radius; } if ((start_angle < angle_180) && (end_angle > angle_180)) { xmin = -radius; } if ((start_angle < angle_270) && (end_angle > angle_270)) { ymin = -radius; } // Slopes for the two sides of the arc float sslope = (float)cosStart/ (float)sinStart; float eslope = (float)cosEnd / (float)sinEnd; if (end_angle == TRIG_MAX_ANGLE) eslope = -1000000; int ir2 = (radius - thickness) * (radius - thickness); int or2 = radius * radius; graphics_context_set_stroke_color(ctx, c); for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) { int x2 = x * x; int y2 = y * y; if ( (x2 + y2 < or2 && x2 + y2 >= ir2) && ( (y > 0 && start_angle < angle_180 && x <= y * sslope) || (y < 0 && start_angle > angle_180 && x >= y * sslope) || (y < 0 && start_angle <= angle_180) || (y == 0 && start_angle <= angle_180 && x < 0) || (y == 0 && start_angle == 0 && x > 0) ) && ( (y > 0 && end_angle < angle_180 && x >= y * eslope) || (y < 0 && end_angle > angle_180 && x <= y * eslope) || (y > 0 && end_angle >= angle_180) || (y == 0 && end_angle >= angle_180 && x < 0) || (y == 0 && start_angle == 0 && x > 0) ) ) graphics_draw_pixel(ctx, GPoint(center.x+x, center.y+y)); } } } }
static void update_layer_callback(Layer *layer, GContext* ctx) { GRect bounds = layer_get_frame(layer); // minutes = 59; graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorWhite); // Draw minutes arc int32_t minutes_angle = 360 * minutes / 60; if(minutes_angle <= 90){ graphics_draw_arc(ctx, center, INNER_RADIUS, INNER_RADIUS, 270, 270 + minutes_angle); } else { graphics_draw_arc(ctx, center, INNER_RADIUS, INNER_RADIUS, 270, 360); graphics_draw_arc(ctx, center, INNER_RADIUS, INNER_RADIUS, 0, minutes_angle - 90); } // Draw bitmap pattern graphics_context_set_compositing_mode(ctx, GCompOpAnd); graphics_draw_bitmap_in_rect(ctx, image, bounds); // Draw hours arc int32_t hours_angle = 360 * ((hours % 12) * 60 + minutes) / (12 * 60); if(hours_angle <= 90){ graphics_draw_arc(ctx, center, OUTER_RADIUS, OUTER_THICKNESS, 270, 270 + hours_angle); } else { graphics_draw_arc(ctx, center, OUTER_RADIUS, OUTER_THICKNESS, 270, 360); graphics_draw_arc(ctx, center, OUTER_RADIUS, OUTER_THICKNESS, 0, hours_angle - 90); } graphics_draw_pixel(ctx, GPoint(center.x-1, center.y - OUTER_RADIUS + 2)); // round end effect graphics_draw_pixel(ctx, GPoint(center.x-1, center.y - OUTER_RADIUS + 3)); // round end effect // Draw hour dot GPoint hourDot; hours_angle = TRIG_MAX_ANGLE * ((hours % 12) * 60 + minutes) / (12 * 60); hourDot.y = (int16_t)(-cos_lookup(hours_angle) * (OUTER_RADIUS - OUTER_THICKNESS/2) / TRIG_MAX_RATIO) + center.y; hourDot.x = (int16_t)(sin_lookup(hours_angle) * (OUTER_RADIUS - OUTER_THICKNESS/2) / TRIG_MAX_RATIO) + center.x; graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, hourDot, DOT_RADIUS); if(hours >= 12){ graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, hourDot, DOT_RADIUS - 2); } // Draw center dot if bluetooth connected if(bluetooth_connected){ graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, center, DOT_RADIUS + 3); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, center, DOT_RADIUS); graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, center, DOT_RADIUS - 2); } else { graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(center.x - (DOT_RADIUS + 4), center.y - (DOT_RADIUS + 4), 2*(DOT_RADIUS + 4), 2*(DOT_RADIUS + 4)), 0, 0); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, GRect(center.x - DOT_RADIUS, center.y - DOT_RADIUS, 2*DOT_RADIUS, 2*DOT_RADIUS), 0, 0); graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(center.x - (DOT_RADIUS - 2), center.y - (DOT_RADIUS - 2), 2*(DOT_RADIUS - 2), 2*(DOT_RADIUS - 2)), 0, 0); } // Draw dates graphics_context_set_text_color(ctx, GColorWhite); graphics_draw_text(ctx, date_str, custom_font, GRect(0, 142, 144, 23), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); }
// Draws hands onto the given layer static void draw_hands(Layer* layer, GContext* ctx) { gpath_rotate_to(hour_ptr, (TRIG_MAX_ANGLE * timedata[0] / 12) + (TRIG_MAX_ANGLE * timedata[1] / 720.0f)); graphics_context_set_fill_color(ctx, GColorWhite); gpath_draw_filled(ctx, hour_ptr); // minute hand gpath_rotate_to(minute_ptr, (TRIG_MAX_ANGLE * timedata[1] / 60) + (TRIG_MAX_ANGLE * timedata[2] / 3600.0f)); graphics_context_set_fill_color(ctx, GColorWhite); gpath_draw_filled(ctx, minute_ptr); // seconds get some extra attention here-- the same as above, but with an extra little counterweight type thing on the opposite site GPoint sec0 = (GPoint) { .x = (int16_t)(center.x + -sin_lookup(TRIG_MAX_ANGLE * timedata[2] / 60) * 18 / TRIG_MAX_RATIO), .y = (int16_t)(center.y + cos_lookup(TRIG_MAX_ANGLE * timedata[2] / 60) * 18 / TRIG_MAX_RATIO) }; GPoint sec1 = (GPoint) { .x = (int16_t)(center.x + sin_lookup(TRIG_MAX_ANGLE * timedata[2] / 60) * 72 / TRIG_MAX_RATIO), .y = (int16_t)(center.y + -cos_lookup(TRIG_MAX_ANGLE * timedata[2] / 60) * 72 / TRIG_MAX_RATIO) }; graphics_context_set_stroke_color(ctx, GColorYellow ); graphics_context_set_stroke_width(ctx, 3); graphics_draw_line(ctx, center, sec1); graphics_context_set_stroke_width(ctx, 6); graphics_draw_line(ctx, center, sec0); graphics_context_set_fill_color(ctx, GColorYellow ); graphics_fill_circle(ctx, center, 5); graphics_context_set_stroke_color(ctx, GColorBlack); graphics_draw_pixel(ctx, center); } // draws face onto the given layer static void draw_face(Layer* layer, GContext* ctx) { static char buf[] = "00"; graphics_context_set_stroke_color(ctx, GColorLightGray); // draw 60 minute ticks around clock for (int i = 0; i < 60; i++) { // tic0 = start of inner point // tic1 = end of outer point GPoint tic0, tic1; // tic0 is the starting point from center, tic1 is the outer point of the tic if (i % 5 == 0) { // hour tic0 = (GPoint) { .x = (int16_t)(center.x + sin_lookup(TRIG_MAX_ANGLE * i / 60) * 69 / TRIG_MAX_RATIO), .y = (int16_t)(center.y + -cos_lookup(TRIG_MAX_ANGLE * i / 60) * 69 / TRIG_MAX_RATIO) }; tic1 = (GPoint) { .x = (int16_t)(tic0.x + sin_lookup(TRIG_MAX_ANGLE * i / 60) * 15 / TRIG_MAX_RATIO), .y = (int16_t)(tic0.y + -cos_lookup(TRIG_MAX_ANGLE * i / 60) * 15 / TRIG_MAX_RATIO) }; graphics_context_set_stroke_width(ctx, 2); /*if (i != 30) { GRect HourText = GRect((int16_t)(center.x + sin_lookup(TRIG_MAX_ANGLE * i / 60) * 54 / TRIG_MAX_RATIO)-10, (int16_t)(center.y + -cos_lookup(TRIG_MAX_ANGLE * i / 60) * 54 / TRIG_MAX_RATIO)-10, 20, 20); snprintf(buf, sizeof(buf), "%d", i/5); graphics_context_set_text_color(ctx, GColorWhite); graphics_draw_text(ctx, buf, fonts_get_system_font(FONT_KEY_GOTHIC_18), HourText, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); }*/ } else { // minute marks tic0 = (GPoint) { .x = (int16_t)(center.x + sin_lookup(TRIG_MAX_ANGLE * i / 60) * 74 / TRIG_MAX_RATIO), .y = (int16_t)(center.y + -cos_lookup(TRIG_MAX_ANGLE * i / 60) * 74 / TRIG_MAX_RATIO) }; tic1 = (GPoint) { .x = (int16_t)(tic0.x + sin_lookup(TRIG_MAX_ANGLE * i / 60) * 10 / TRIG_MAX_RATIO), .y = (int16_t)(tic0.y + -cos_lookup(TRIG_MAX_ANGLE * i / 60) * 10 / TRIG_MAX_RATIO) }; graphics_context_set_stroke_width(ctx, 1); } graphics_draw_line(ctx, tic0, tic1); } // draw the date (new and complex how scary) snprintf(buf, sizeof(buf), "%d", timedata[3]); int yDate = center.y + layer_get_frame(s_face_layer).size.h / 4; int xDate = center.x - 6; GRect date_window = GRect(xDate, yDate, 13, 18); graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_text_color(ctx, GColorBlack); graphics_fill_rect(ctx, date_window, 0, 0); graphics_draw_text(ctx, buf, fonts_get_system_font(FONT_KEY_GOTHIC_14), date_window, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); graphics_context_set_fill_color(ctx, GColorRed); gpath_move_to(chevron, GPoint(xDate + 6, yDate - 3)); gpath_rotate_to(chevron, TRIG_MAX_ANGLE * 0.5f); gpath_draw_filled(ctx, chevron); } static void tick_handler(struct tm* tick_time, TimeUnits units_changed) { // just store the time, don't bother with making a new one in the update_proc or calling update_time timedata[0] = tick_time->tm_hour % 12; timedata[1] = tick_time->tm_min; timedata[2] = tick_time->tm_sec; timedata[3] = tick_time->tm_mday; layer_mark_dirty(s_hands_layer); } static void main_window_load(Window* window) { // self-explanatory: make the main window black with one full-screen layer to display the time window_set_background_color(window, GColorBlack); s_face_layer = layer_create(layer_get_bounds(window_get_root_layer(s_window))); s_hands_layer = layer_create(layer_get_bounds(window_get_root_layer(s_window))); logo = gbitmap_create_with_resource(RESOURCE_ID_LOGO); int offset = (center.x-20); logo_layer = bitmap_layer_create(GRect(offset, 50, 40, 12)); bitmap_layer_set_bitmap(logo_layer, logo); layer_add_child(s_face_layer, bitmap_layer_get_layer(logo_layer)); layer_set_update_proc(s_face_layer, draw_face); layer_set_update_proc(s_hands_layer, draw_hands); layer_add_child(window_get_root_layer(window), s_face_layer); layer_add_child(window_get_root_layer(window), s_hands_layer); } static void main_window_unload(Window* window) { gbitmap_destroy(logo); bitmap_layer_destroy(logo_layer); layer_destroy(s_face_layer); layer_destroy(s_hands_layer); gpath_destroy(hour_ptr); gpath_destroy(minute_ptr); gpath_destroy(second_ptr); } static void init() { // initialize stuff you know the drill s_window = window_create(); window_set_window_handlers(s_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload });
static void layer_update_callback(Layer *me, GContext* ctx) { // preparations GRect bounds = layer_get_bounds(me); uint16_t width = bounds.size.w; uint16_t height = bounds.size.h; uint16_t stride = (bounds.size.w + 31) / 32 * 32; uint16_t max = (height - 1) * stride + width; uint16_t shake = stride - width; uint16_t shake_stride = shake * stride; // handle shake if (do_shake) { do_shake = false; light_enable_interaction(); for (uint16_t i = 0, j = rand(); i < NUM_FLAKES; i++, j+=31) { for (uint16_t k = 0; k < 2; k++, j+=31) { uint16_t next = flakes[i] + j % (max * 2) - max; if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) { flakes[i] = next; break; } } } last_time = 0; } // update time text time_t t = time(NULL); if (t / UPDATE_S > last_time) { last_time = t / UPDATE_S; char time_text[6]; clock_copy_time_string(time_text, sizeof(time_text)); graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, bounds, 0, GCornerNone); GRect rect = (GRect) {{0, 60}, {width, 50}}; GFont font = fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD); graphics_draw_text(ctx, time_text, font, rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); graphics_context_set_stroke_color(ctx, GColorWhite); for (uint16_t i = 0, j = rand(); i < NUM_FLAKES; i++) { if (get_pixel(ctx, flakes[i]) == GColorBlack) { graphics_draw_pixel(ctx, GPoint(flakes[i] % stride, flakes[i] / stride)); } else { for (uint16_t k = 0; k < 8; k++, j++) { uint16_t next = flakes[i] + (j % 9 / 3 - 1) * shake_stride + (j % 3 - 1) * shake; if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) { flakes[i] = next; graphics_draw_pixel(ctx, GPoint(flakes[i] % stride, flakes[i] / stride)); break; } } } } } // apply physics AccelData accel = {.x = 0, .y = 0, .z = 0}; accel_service_peek(&accel); uint16_t absx = accel.x < 0 ? -accel.x : accel.x; uint16_t absy = accel.y < 0 ? -accel.y : accel.y; uint16_t span = (absx + absy + 10) * SPEED; for (uint16_t i = 0, j = rand(), k = rand(), l = rand(); i < span; i++, j++, k++, l++) { uint16_t index = j % NUM_FLAKES; uint16_t next = flakes[index]; int16_t sideway = k % 3 == 0 ? l % 5 - 2 : 0; int16_t accx = accel.x + accel.y * sideway; int16_t accy = accel.y - accel.x * sideway; absx = accx < 0 ? -accx : accx; absy = accy < 0 ? -accy : accy; if (absx > absy || k % absy < absx) { if (accx > 0) { next++; } else { next--; } } if (absy > absx || l % absx < absy) { if (accy > 0) { next -= stride; } else { next += stride; } } if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) { graphics_context_set_stroke_color(ctx, GColorBlack); graphics_draw_pixel(ctx, GPoint(flakes[index] % stride, flakes[index] / stride)); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_pixel(ctx, GPoint(next % stride, next / stride)); flakes[index] = next; } } if (!timer) timer = app_timer_register(UPDATE_MS, timer_callback, NULL); } static void handle_accel(AccelData *accel_data, uint32_t num_samples) { // or else I will crash } static void accel_tap_handler(AccelAxisType axis, int32_t direction) { do_shake = true; } static void root_update_callback(Layer *me, GContext* ctx) { // hack to prevent screen cleaning } static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); layer_set_update_proc(window_layer, root_update_callback); GRect bounds = layer_get_bounds(window_layer); layer = layer_create(bounds); layer_set_update_proc(layer, layer_update_callback); layer_add_child(window_layer, layer); uint16_t width = bounds.size.w; uint16_t height = bounds.size.h; uint16_t stride = (bounds.size.w + 31) / 32 * 32; for (uint16_t i = 0; i < NUM_FLAKES; i++) { flakes[i] = rand() % height * stride + rand() % width; } }
void day_display_layer_update_callback(Layer *me, GContext* ctx) { (void)me; PblTm t; get_time(&t); int daysInMonth = t.tm_mon == 3 || t.tm_mon == 5 || t.tm_mon == 8 || t.tm_mon == 10 ? 30 : t.tm_mon != 1 ? 31: t.tm_year % 4 == 0 && (t.tm_year % 400 == 0 || t.tm_year % 100 != 0) ? 29 : 28; unsigned int angle = (t.tm_mday * 180) / daysInMonth; GPoint center = grect_center_point(&me->frame); center.y += 10; graphics_context_set_fill_color(ctx, GColorWhite); graphics_draw_arc(ctx, center, 62, 10, 0, angle); //graphics_draw_line(ctx, GPoint(27, center.y), GPoint(50, center.y)); //graphics_draw_line(ctx, GPoint(94, center.y), GPoint(117, center.y)); for (int x = -1; x < 3; x++) for (int y = -1; y < 3; y++) if (x + y > -2 && x + y < 4 && x - y < 3 && y - x < 3) { graphics_draw_pixel(ctx, GPoint(center.x - 00 + x, center.y + 66 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 47 + x, center.y + 47 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 47 + x, center.y + 47 + y)); } for (int x = 0; x < 2; x++) for (int y = 0; y < 2; y++) { graphics_draw_pixel(ctx, GPoint(center.x - 64 + x, center.y + 17 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 57 + x, center.y + 33 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 33 + x, center.y + 57 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 17 + x, center.y + 64 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 64 + x, center.y + 17 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 57 + x, center.y + 33 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 33 + x, center.y + 57 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 17 + x, center.y + 64 + y)); } }
void hour_display_layer_update_callback(Layer *me, GContext* ctx) { (void)me; PblTm t; get_time(&t); unsigned int angle = (t.tm_hour % 12) * 15 + 180; GPoint center = grect_center_point(&me->frame); center.y -= 10; graphics_context_set_fill_color(ctx, GColorWhite); graphics_draw_arc(ctx, center, 62, 10, 180, angle); //graphics_draw_line(ctx, GPoint(7, center.y), GPoint(20, center.y)); //graphics_draw_line(ctx, GPoint(124, center.y), GPoint(137, center.y)); for (int x = -1; x < 3; x++) for (int y = -1; y < 3; y++) if (x + y > -2 && x + y < 4 && x - y < 3 && y - x < 3) { graphics_draw_pixel(ctx, GPoint(center.x - 00 + x, center.y - 66 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 47 + x, center.y - 47 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 47 + x, center.y - 47 + y)); } for (int x = 0; x < 2; x++) for (int y = 0; y < 2; y++) { graphics_draw_pixel(ctx, GPoint(center.x - 64 + x, center.y - 17 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 57 + x, center.y - 33 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 33 + x, center.y - 57 + y)); graphics_draw_pixel(ctx, GPoint(center.x - 17 + x, center.y - 64 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 64 + x, center.y - 17 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 57 + x, center.y - 33 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 33 + x, center.y - 57 + y)); graphics_draw_pixel(ctx, GPoint(center.x + 17 + x, center.y - 64 + y)); } }
static void fibo_layer_update_callback(Layer *layer, GContext *ctx) { GColor fill_color[4]; // None, Hour, Minute, Hr+Min static int8_t h, m, fc1L, fc1R, fc2, fc3, fc5; fill_color[0] = conf.noneColor; fill_color[1] = conf.hourColor; fill_color[2] = conf.minuteColor; fill_color[3] = conf.hourMinuteColor; /* Only get new random combination on time change */ if (h != s_curr_hour) { h = s_curr_hour; m = s_curr_min / 5; // Divide by five since only values from 1-12 can be displayed fc1L = fc1R = fc2 = fc3 = fc5 = 0; get_fibo_colors(h, m, &fc1L, &fc1R, &fc2, &fc3, &fc5); } else if (m != s_curr_min / 5) { m = s_curr_min / 5; // Divide by five since only values from 1-12 can be displayed fc1L = fc1R = fc2 = fc3 = fc5 = 0; get_fibo_colors(h, m, &fc1L, &fc1R, &fc2, &fc3, &fc5); } #if ACTIVATE_COLOR_LOOP { static int8_t cnt = 0; fc5 = cnt; cnt = (cnt == 3) ? 0 : cnt + 1; } #endif // Draw the time boxes graphics_context_set_fill_color(ctx, fill_color[fc3]); graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_3x3_square, 0, GCornerNone); graphics_context_set_fill_color(ctx, fill_color[fc2]); graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_2x2_square, 0, GCornerNone); graphics_context_set_fill_color(ctx, fill_color[fc1L]); graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_1x1L_square, 0, GCornerNone); graphics_context_set_fill_color(ctx, fill_color[fc1R]); graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_1x1R_square, 0, GCornerNone); graphics_context_set_fill_color(ctx, fill_color[fc5]); s_legibleColor = gcolor_legible_over(fill_color[fc5]); // Also used for battery frame text_layer_set_text_color(s_time_layer, conf.legibleText ? s_legibleColor: conf.timeColor); text_layer_set_text_color(s_date_layer, conf.legibleText ? s_legibleColor: conf.timeColor); text_layer_set_text_color(s_week_layer, conf.legibleText ? s_legibleColor: conf.timeColor); graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_5x5_square, 0, GCornerNone); // Draw the grid graphics_context_set_stroke_color(ctx, conf.gridColor); graphics_context_set_stroke_width(ctx, 3); graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_3x3_square); graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_2x2_square); graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_1x1L_square); graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_1x1R_square); graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_5x5_square); // Draw the grid dots graphics_context_set_stroke_color(ctx, conf.dotColor); for (int16_t y = fibo[conf.fiboDisplay].s_outline.origin.y + 2; y <= fibo[conf.fiboDisplay].s_outline.origin.y + fibo[conf.fiboDisplay].s_outline.size.h; y += fibo[conf.fiboDisplay].s_1x1L_square.size.h - 1) { for (int16_t x = fibo[conf.fiboDisplay].s_outline.origin.x + 2; x <= fibo[conf.fiboDisplay].s_outline.origin.x + fibo[conf.fiboDisplay].s_outline.size.w; x += fibo[conf.fiboDisplay].s_1x1L_square.size.w - 1) { graphics_draw_pixel(ctx, GPoint(x, y)); } } // Draw the outline graphics_context_set_stroke_color(ctx, conf.outlineColor); graphics_context_set_stroke_width(ctx, 1); graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_outline); }