Commits

Trammell Hudson committed e6c1945

crazy color sprites

Comments (0)

Files changed (1)

 
 
 #define NUM_LEDS ((int16_t) (32 * 5))
+#define LED_SCALE 8
 
 static inline void clock(const uint8_t value)
 {
 	for (i = 0 ; i < NUM_LEDS ; i++)
 	{
 		uint8_t * const p = pixels[i];
-		p[0] >>= 1;
-		p[1] >>= 1;
-		p[2] >>= 1;
+		uint8_t j;
+		for (j = 0 ; j < 3 ; j++)
+		{
+			uint16_t v = (p[j] * (uint16_t) 31) / 32;
+			if (v > 0xFF)
+				v = 0xFF;
+			p[j] = v;
+		}
 	}
 }
 
 
 	struct sprite sprites[] = {
 		{ .v = +1, .r = 0xFF, .b = 0x00, .g = 0x00 },
-		{ .v = -1, .r = 0x00, .b = 0xFF, .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 = -2, .r = 0x00, .b = 0x00, .g = 0xFF, .pos = NUM_LEDS/2 },
-		{ .v = +2, .r = 0xFF, .b = 0x00, .g = 0xFF, .pos = NUM_LEDS/2 },
+		{ .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);
 
 			struct sprite * const s = &sprites[i];
 			int16_t pos = s->pos + s->v;
 
-			if (pos >= NUM_LEDS)
+			if (pos >= NUM_LEDS * LED_SCALE)
 			{
-				pos = NUM_LEDS - 1;
+				pos = NUM_LEDS * LED_SCALE - 1;
 				s->v = -s->v;
 			} else
 			if (pos < 0) {
 				
 			s->pos = pos;
 
-			uint8_t * const p = pixels[pos];
-			p[0] = s->r;
-			p[1] = s->g;
-			p[2] = s->b;
+			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);