saved 38 bytes
This commit is contained in:
parent
bd99f557b8
commit
041bae2942
|
@ -25,33 +25,35 @@
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
#include "../random/prng.h"
|
#include "../random/prng.h"
|
||||||
|
|
||||||
|
|
||||||
void ltn_ant() {
|
void ltn_ant() {
|
||||||
clear_screen(0);
|
clear_screen(0);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char x , y;
|
unsigned char x, y;
|
||||||
char dx, dy; /* Vector can only be: (0,1),(1,0),(0,-1),(-1,0) */
|
unsigned char ox, oy; /* Used to set old pixels so brightness 2 */
|
||||||
char ox, oy; /* Used to set old pixels so brightness 2 */
|
signed char dx, dy; /* Vector can only be (0,1),(1,0),(0,-1),(-1,0) */
|
||||||
} ant;
|
} ant;
|
||||||
|
|
||||||
char temp, i = 0;
|
signed char temp;
|
||||||
uint16_t cycles = 500;
|
unsigned int cycles = 500;
|
||||||
|
|
||||||
/* Random startposition and direction */
|
/* Random start position and direction */
|
||||||
ant.x = random8() % NUM_COLS;
|
ant.x = random8() % NUM_COLS;
|
||||||
ant.y = random8() % NUM_ROWS;
|
ant.y = random8() % NUM_ROWS;
|
||||||
|
|
||||||
/* Make sure we do have a valid vector */
|
/* Make sure we do have a valid vector */
|
||||||
|
ant.dx = (random8() % 3) - 1;
|
||||||
do {
|
do {
|
||||||
ant.dx = (random8() % 3) - 1;
|
|
||||||
ant.dy = (random8() % 3) - 1;
|
ant.dy = (random8() % 3) - 1;
|
||||||
} while(ant.dx == ant.dy);
|
} while(ant.dx == ant.dy);
|
||||||
|
|
||||||
ant.ox = 0;
|
ant.ox = ant.x;
|
||||||
ant.oy = 0;
|
ant.oy = ant.y;
|
||||||
|
|
||||||
while(cycles != 0) {
|
while(cycles != 0) {
|
||||||
if(get_pixel((pixel) {ant.x, ant.y}) == 0) { /* If the pixel is not set turn it on */
|
/* If the pixel is not set turn it on */
|
||||||
|
if(get_pixel((pixel) {ant.x, ant.y}) == 0) {
|
||||||
setpixel((pixel) {ant.x, ant.y}, 3);
|
setpixel((pixel) {ant.x, ant.y}, 3);
|
||||||
|
|
||||||
temp = ant.dx;
|
temp = ant.dx;
|
||||||
|
@ -59,10 +61,9 @@ void ltn_ant() {
|
||||||
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 */
|
/* Lets the last pixel be darker than the latest */
|
||||||
if(i == 1)
|
if((ant.ox != ant.x) || (ant.oy != ant.y))
|
||||||
setpixel((pixel) {ant.ox, ant.oy}, 2);
|
setpixel((pixel) {ant.ox, ant.oy}, 2);
|
||||||
else
|
|
||||||
i = 1;
|
|
||||||
ant.ox = ant.x;
|
ant.ox = ant.x;
|
||||||
ant.oy = ant.y;
|
ant.oy = ant.y;
|
||||||
|
|
||||||
|
@ -76,21 +77,18 @@ void ltn_ant() {
|
||||||
|
|
||||||
wait(100);
|
wait(100);
|
||||||
|
|
||||||
ant.x += ant.dx;
|
/* Playing field is modeled after a torus */
|
||||||
ant.y += ant.dy;
|
if(ant.x == 0 && ant.dx < 0)
|
||||||
|
ant.x = NUM_COLS - 1;
|
||||||
|
else
|
||||||
|
ant.x = (ant.x + ant.dx) % UNUM_COLS;
|
||||||
|
|
||||||
/* The ant will appear on the oppisite side of the field if it would leave */
|
if(ant.y == 0 && ant.dy < 0)
|
||||||
if(ant.x <= 0)
|
ant.y = NUM_ROWS - 1;
|
||||||
ant.x += (NUM_ROWS - 1);
|
else
|
||||||
if(ant.x >= NUM_ROWS)
|
ant.y = (ant.y + ant.dy) % UNUM_ROWS;
|
||||||
ant.x -= (NUM_ROWS + 1);
|
|
||||||
if(ant.y <= 0)
|
|
||||||
ant.y += (NUM_COLS - 1);
|
|
||||||
if(ant.y >= NUM_COLS)
|
|
||||||
ant.y -= (NUM_COLS + 1);
|
|
||||||
|
|
||||||
cycles--;
|
cycles--;
|
||||||
}
|
}
|
||||||
wait(300);
|
wait(300);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue