Commits

Trammell Hudson committed e0e76ca

smooth

Comments (0)

Files changed (1)

 	for (i = 0 ; i < NUM_LEDS ; i++)
 		pixels[i][0] = pixels[i][1] = pixels[i][2] = 0xFF;
 	send_pixels();
-	//while(1);
 
-	struct sprite sprites[] = {
-		{ .v = +1, .r = 0xFF, .b = 0x00, .g = 0x00 },
-		{ .v = +2, .r = 0x00, .b = 0xFF, .g = 0x00, .pos = NUM_LEDS*LED_SCALE/2 },
-		{ .v = +3, .r = 0xFF, .b = 0xFF, .g = 0xFF },
-		{ .v = +4, .r = 0x00, .b = 0xFF, .g = 0xFF },
-		{ .v = +5, .r = 0x80, .b = 0x80, .g = 0x10 },
-		{ .v = +6, .r = 0x00, .b = 0x00, .g = 0xFF, .pos = NUM_LEDS*LED_SCALE/2 },
-		{ .v = +7, .r = 0xFF, .b = 0x00, .g = 0xFF, .pos = NUM_LEDS*LED_SCALE/2 },
-	};
-	const int num_sprites = sizeof(sprites) / sizeof(*sprites);
 
 	while (1)
 	{
 		send_pixels();
-		fade_pixels();
 
-		// Compute the next position
-		for (int i = 0 ; i < num_sprites ; i++)
+		// Smoothly fade the colors
+		uint8_t * const e1 = pixels[0];
+		uint8_t * const e2 = pixels[NUM_LEDS-1];
+
+		e2[0] = 0xFF;
+		e2[1] = 0xFF;
+		e2[2] = 0xFF;
+
+		e1[0] = 0x00;
+		e1[1] = 0x00;
+		e1[2] = 0x00;
+
+		for (uint16_t i = 1 ; i < NUM_LEDS-1 ; i++)
 		{
-			struct sprite * const s = &sprites[i];
-			int16_t pos = s->pos + s->v;
-
-			if (pos >= NUM_LEDS * LED_SCALE)
+			uint8_t * const p = pixels[i];
+			for (uint8_t j = 0 ; j < 3 ; j++)
 			{
-				pos = NUM_LEDS * LED_SCALE - 1;
-				s->v = -s->v;
-			} else
-			if (pos < 0) {
-				pos = 0;
-				s->v = -s->v;
+				uint16_t x = e1[j] * i + e2[j] * (NUM_LEDS-i);
+				x /= NUM_LEDS;
+				p[j] = x;
 			}
-				
-			s->pos = pos;
-
-			uint8_t * const p = pixels[pos / LED_SCALE];
-			p[0] = (s->r * (uint16_t) 3 + p[0]) / 4;
-			p[1] = (s->g * (uint16_t) 3 + p[1]) / 4;
-			p[2] = (s->b * (uint16_t) 3 + p[2]) / 4;
 		}
 
 		_delay_ms(30);