Commits

Trammell Hudson  committed a9865e1

Add some color and try to save code space

  • Participants
  • Parent commits bafc2d0

Comments (0)

Files changed (2)

File fireworks/draw.c

 	int32_t h
 )
 {
+/* save code space
 	if (x < 0 || y < 0 || x >= VSCREEN_WIDTH || y >= VSCREEN_HEIGHT)
 		return;
 
 	if (w <= (1 << VSCREEN_SHIFT) || h <= (1 << VSCREEN_SHIFT))
 		return;
+*/
 
 	x >>= VSCREEN_SHIFT;
 	y >>= VSCREEN_SHIFT;
 	w >>= VSCREEN_SHIFT;
 	h >>= VSCREEN_SHIFT;
 
+/* save code space
 	if (x + w > SCREEN_WIDTH)
 		w = SCREEN_WIDTH - 1;
 	if (y + h > SCREEN_HEIGHT)
 		h = SCREEN_HEIGHT - 1;
+*/
 
 	pulse_set_draw_window(
 		x,

File fireworks/fireworks.c

 
 static digit_t last_sec, last_min, last_hour;
 static digit_t cur_sec, cur_min, cur_hour;
-static digit_t next_sec, next_min, next_hour;
+static digit_t next_sec;
 
 void
 init(void)
 	const uint32_t now_ms
 )
 {
-	uint32_t cur_ms = now_ms;
-	uint32_t ms = cur_ms % 1000; cur_ms /= 1000;
+	uint32_t cur_ms = now_ms / 1000;
 	const uint32_t sec = cur_ms % 60; cur_ms /= 60;
 	const uint8_t min = cur_ms % 60; cur_ms /= 60;
 	const uint8_t hour = cur_ms %= 24;
+	static uint8_t fade_to_black;
 
 	if (cur_sec.value != sec)
 	{
 			animate_draw(&last_sec, COLOR_BLACK);
 			last_sec.value = cur_sec.value;
 			last_sec.first = 1;
-			last_sec.start.ms = now_ms + 100;
-			last_sec.end.ms = now_ms + 900;
+			last_sec.start.ms = now_ms;
+			last_sec.end.ms = now_ms + 700;
 			last_sec.start.color = cur_sec.last.color;
-			last_sec.end.color = COLOR_BLACK;
+
+			// Pick a bright color for the flash
+			uint8_t r = rand() & 3;
+			last_sec.end.color.red = (r == 1) ? 0xFF : 0;
+			last_sec.end.color.blue = (r == 2 || r == 0) ? 0xFF : 0;
+			last_sec.end.color.green = (r == 3) ? 0xFF : 0;
+
 			last_sec.start.scale = cur_sec.last.scale;
-			last_sec.end.scale = 80 << VSCREEN_SHIFT;
+			last_sec.end.scale = 60 << VSCREEN_SHIFT;
 			last_sec.start.x = cur_sec.last.x;
 			last_sec.start.y = cur_sec.last.y;
-			last_sec.end.x = - (100 << VSCREEN_SHIFT);
-			last_sec.end.y = VSCREEN_HEIGHT/2 - (80 << VSCREEN_SHIFT);
+			last_sec.end.x = (15 << VSCREEN_SHIFT) - (50 << VSCREEN_SHIFT);
+			last_sec.end.y = VSCREEN_HEIGHT/2 - (50 << VSCREEN_SHIFT);
 
 			next_sec = last_sec;
 			next_sec.start.ms = now_ms + 500;
+			next_sec.end.color = COLOR_BLACK;
 			next_sec.end.scale = next_sec.start.scale;
 			next_sec.end.x = next_sec.start.x;
 			next_sec.end.y = next_sec.start.y;
 
 			animate(&last_sec, now_ms);
+			fade_to_black = 0;
 		}
 
 		cur_sec.value = sec;
 
 		animate(&cur_sec, now_ms);
 	} else {
+		// Halfway through the explosion, make the colors switch
+		// to fade to black
+		if (now_ms > last_sec.start.ms + 300 && !fade_to_black)
+		{
+			last_sec.start.color = last_sec.end.color;
+			last_sec.end.color = COLOR_BLACK;
+			fade_to_black = 1;
+		}
+			
 		animate(&last_sec, now_ms);
 		animate(&cur_sec, now_ms);
 		animate(&next_sec, now_ms);
 			animate_draw(&last_min, COLOR_BLACK);
 			last_min.value = cur_min.value;
 			last_min.first = 1;
-			last_min.start.ms = now_ms + 500;
+			last_min.start.ms = now_ms + 100;
 			last_min.end.ms = now_ms + 900;
 			last_min.start.color = cur_min.last.color;
 			last_min.end.color = COLOR_BLACK;
 			last_min.start.scale = cur_min.last.scale;
-			last_min.end.scale = 80 << VSCREEN_SHIFT;
+			last_min.end.scale = 60 << VSCREEN_SHIFT;
 			last_min.start.x = cur_min.last.x;
 			last_min.start.y = cur_min.last.y;
-			last_min.end.x = - (80 << VSCREEN_SHIFT);
-			last_min.end.y = VSCREEN_HEIGHT/2 - (80 << VSCREEN_SHIFT);
+			last_min.end.x = cur_min.end.x - (50 << VSCREEN_SHIFT);
+			last_min.end.y = VSCREEN_HEIGHT/2 - (50 << VSCREEN_SHIFT);
 			animate(&last_min, now_ms);
 		}
 
 			animate_draw(&last_hour, COLOR_BLACK);
 			last_hour.value = cur_hour.value;
 			last_hour.first = 1;
-			last_hour.start.ms = now_ms + 500;
-			last_hour.end.ms = now_ms + 900;
+			last_hour.start.ms = now_ms + 200;
+			last_hour.end.ms = now_ms + 1900;
 			last_hour.start.color = cur_hour.last.color;
 			last_hour.end.color = COLOR_BLACK;
 			last_hour.start.scale = cur_hour.last.scale;
-			last_hour.end.scale = 80 << VSCREEN_SHIFT;
+			last_hour.end.scale = 60 << VSCREEN_SHIFT;
 			last_hour.start.x = cur_hour.last.x;
 			last_hour.start.y = cur_hour.last.y;
 			last_hour.end.x = - (80 << VSCREEN_SHIFT);
 		cur_hour.end.color = COLOR_WHITE;
 
 		cur_hour.start.ms = now_ms;
-		cur_hour.end.ms = now_ms + 1200;
+		cur_hour.end.ms = now_ms + 2200;
 
 		cur_hour.end.scale = (10 << VSCREEN_SHIFT);
 		cur_hour.end.y = VSCREEN_HEIGHT/2;