Older pixels are now darker

This commit is contained in:
alu 2010-04-11 11:37:31 +00:00
parent 074f114ee4
commit 253c094682
1 changed files with 29 additions and 15 deletions

View File

@ -31,9 +31,10 @@ void ltn_ant() {
struct { struct {
char x , y; char x , y;
char dx, dy; /* Vector can only be: (0,1),(1,0),(0,-1),(-1,0) */ char dx, dy; /* Vector can only be: (0,1),(1,0),(0,-1),(-1,0) */
char ox, oy; /* Used to set old pixels so brightness 2 */
} ant; } ant;
int temp; char temp, i = 0;
/* Random startposition and direction */ /* Random startposition and direction */
ant.x = random8() % NUM_COLS; ant.x = random8() % NUM_COLS;
@ -53,23 +54,36 @@ void ltn_ant() {
do { do {
if(get_pixel((pixel) {ant.x, ant.y}) == 0) { /* If the pixel is not set turn it on */ if(get_pixel((pixel) {ant.x, ant.y}) == 0) { /* If the pixel is not set turn it on */
setpixel((pixel) {ant.x, ant.y}, 3); setpixel((pixel) {ant.x, ant.y}, 3);
temp = ant.dx; temp = ant.dx;
ant.dx = ant.dy; ant.dx = ant.dy;
ant.dy = -temp; /* Turn 90 degrees to the right */ ant.dy = -temp; /* Turn 90 degrees to the right */
/* Lets the last pixel be darker than the latest */
if(i == 1)
setpixel((pixel) {ant.ox, ant.oy}, 2);
i = 1;
ant.ox = ant.x;
ant.oy = ant.y;
} else { } else {
setpixel((pixel) {ant.x, ant.y}, 0); setpixel((pixel) {ant.x, ant.y}, 0);
temp = ant.dy; temp = ant.dy;
ant.dy = ant.dx; ant.dy = ant.dx;
ant.dx = -temp; /* Turn 90 degrees to the left */ ant.dx = -temp; /* Turn 90 degrees to the left */
} }
wait(100); wait(100);
ant.x = ant.x + ant.dx; ant.x += ant.dx;
ant.y = ant.y + ant.dy; ant.y += ant.dy;
} while(ant.x >= 0 &&
ant.x < NUM_COLS &&
ant.y >= 0 &&
ant.y < NUM_ROWS); /* Make sure we won't leave the matrix. (Mr. Smith hates it outside the matrix, you know?) */
} while (ant.x >= 0 && ant.x < NUM_COLS && ant.y >= 0 && ant.y < NUM_ROWS); /* Make sure we won't leave the matrix wait(300);
* (Mr. Smith hates it outside the matrix, you know?)
*/
} }