uint8_t tick() { if (state == 0) { state = 1; left_bar = 0; right_bar = 0; flash_light = 0; winner = 0; end = 0; } int8_t y; for(y = 0; y < LED_HEIGHT; y++) { setLedXY(0, y, y < left_bar / 7 ? 7 : y == left_bar / 7 ? left_bar % 7 : 0); setLedXY(3, y, y < right_bar / 7 ? 7 : y == right_bar / 7 ? right_bar % 7 : 0); } draw_flash(flash_light ? 7 : 1); if(rand()%100 < 50 - 20*flash_light) flash_light = !flash_light; if(winner == 1) draw_winner1(); if(winner == 2) draw_winner2(); if(winner > 0 && --end == 0) { state = 0; return 1; } return 0; }
static uint8_t tick(void) { for(int i = 0; i < N_RACERS; i++) { struct racer *r = racers + i; /* printf("racer %i: %ix%i MODE=%i\n", i, r->x, r->y, r->mode); */ if (r->mode == MODE_DEAD) { /* Spawn a new */ r->mode = MODE_ALIVE; r->x = rand() % LED_WIDTH; r->y = rand() % LED_HEIGHT; r->dir = rand() % 4; r->rgb[0] = 0x7f + (rand() & 0x7f); r->rgb[1] = 0x7f + (rand() & 0x7f); r->rgb[2] = 0x7f + (rand() & 0x7f); break; } else { if (r->mode == MODE_ALIVE) setLedXY(r->x, r->y, r->rgb[0], r->rgb[1], r->rgb[2]); else if (r->mode == MODE_ZOMBIE) /* setLedXY(r->x, r->y, 255 - r->rgb[0], 255 - r->rgb[1], 255 - r->rgb[2]); */ setLedXY(r->x, r->y, 0, 0, 0); int should_turn = r->mode == MODE_ALIVE && (rand() & 0xF) == 0; if (!should_turn && try_go(r, r->dir)) { /* Went further in direction */ } else { int new_dir; if (r->dir == DIR_UP || r->dir == DIR_DOWN) { if ((rand() & 1) == 0) new_dir = DIR_LEFT; else new_dir = DIR_RIGHT; } else { if ((rand() & 1) == 0) new_dir = DIR_UP; else new_dir = DIR_DOWN; } if (try_go(r, new_dir)) { /* Ok */ } else { /* Give other direction a try */ new_dir = (new_dir + 2) % 4; if (try_go(r, new_dir)) { /* Ok */ } else { /* Die */ r->mode = (r->mode + 1) % 3; /* Reverse */ r->dir = (r->dir + 2) % 4; } } } } } return 0; }
void pixeldraw(int x, int y, int color) { uint8_t r[] = {0,145,255,0 ,255,0 ,255,0 ,127,0 ,127,127,0 ,0 ,0 ,255}; uint8_t g[] = {0,0 ,0 ,0 ,0 ,255,255,255,255,255,127,255,127,127,0 ,255}; uint8_t b[] = {0,145 ,0 ,255,255,0 ,0 ,255,127,127,255,0 ,127,0 ,127,255}; x+=3; y+=3; setLedXY(x*3,y*3,r[color],g[color],b[color]); setLedXY(x*3+1,y*3+1,r[color],g[color],b[color]); setLedXY(x*3,y*3+1,r[color],g[color],b[color]); setLedXY(x*3+1,y*3,r[color],g[color],b[color]); }
uint8_t tick() { v1 += 3; v2 += 5; int rx = (cosi(v1 >> 2) >> 5) + 2; int ry = (sini(v2 >> 2) >> 5) + 2; int x, y; for(y = 0; y < LED_HEIGHT; y++) { for(x = 0; x < LED_WIDTH; x++) { int dx = x - rx; int dy = y - ry; int d = sqrti(dx * dx + dy * dy); int q = ( (sini(x * 8 + (v1)) + sini(y * 8 + (v2)) + sini(d << 5)) >> 2) + 128; int a = (q * 0xffff / 0x10000) >> 6; setLedXY(x, y, a); } } return 0; }
void draw_filledCircleSlice( unsigned int x, unsigned int y, double rad, uint8_t r, uint8_t g, uint8_t b, uint16_t slice_begin, uint16_t slice_end) { uint8_t i,j; if(slice_begin > slice_end) { swap_(slice_begin,slice_end); } for(i=0;i<(rad*2);i++) { for(j=0;j<(rad*2);j++) { double dist = pythagoras( j,i ); if(dist <= rad-1) { setLedXY(y-j,x+i,r,g,b); }else if(dist < rad) { // dla_plot(y-j,x+i,r,g,b,1-(dist-rad+1)); } } } }
uint8_t tick_random() { uint8_t x, y; for(x = 0; x < LED_WIDTH; x++) { for(y = 0; y < LED_HEIGHT; y++) { setLedXY(x, y, rand()&7); } } return 0; }
static uint8_t tick(void) { float time = getSysTick() / 10000.0f; char text[128]; snprintf(text, 127, "Device Time: %.1fs", time); struct zint_symbol zs; memset(&zs, 0, sizeof(zs)); zs.input_mode = DATA_MODE; zs.option_1 = 3; /* zs.option_2 = 2; */ int qr_res = qr_code(&zs, (unsigned char *)text, strlen(text)); if (qr_res) { /* printf("Error: %i\n", qr_res); */ } int zoom = MAX(1, MIN(LED_WIDTH / (zs.width + (BORDER * 2)), LED_HEIGHT / (zs.rows + (BORDER * 2)))); static int old_width = 0; if (old_width != zs.width) { old_width = zs.width; lcdFillRGB(255, 255, 255); } int x0 = (LED_WIDTH - zoom * zs.width) / 2; int y0 = (LED_HEIGHT - zoom * zs.rows) / 2; for(int y = 0; y < zs.width; y++) { for(int x = 0; x < zs.rows; x++) { for(int y1 = y * zoom; y1 < (y + 1) * zoom; y1++) { for(int x1 = x * zoom; x1 < (x + 1) * zoom; x1++) { if (module_is_set(&zs, x, y)) { setLedXY(x0 + x1, y0 + y1, 0, 0, 0); } else { setLedXY(x0 + x1, y0 + y1, 255, 255, 255); } } } } } time++; return 0; }
static void dla_plot(int x, int y, uint8_t r,uint8_t g , uint8_t b, float br) { uint8_t o_red = 0; uint8_t o_green = 0; uint8_t o_blue = 0; getLedXY(x,y,&o_red,&o_green,&o_blue); r=br*r+((1-br)*o_red); g=br*g+((1-br)*o_green); b=br*b+((1-br)*o_blue); setLedXY(x, y, r,g,b); }
static void pixeldraw(int x, int y, int color) { uint8_t r[] = {0,105,255,0 ,255,0 ,255,0 ,127,0 ,127,127,0 ,0 ,0 ,255}; uint8_t g[] = {0,0 ,0 ,0 ,0 ,255,255,255,255,255,127,255,127,127,0 ,255}; uint8_t b[] = {0,105 ,0 ,255,255,0 ,0 ,255,127,127,255,0 ,127,0 ,127,255}; y+=1; for(int i = 0;i<5;i++) { for(int j = 0;j<5;j++) { setLedXY(x*6+j,y*6+i,r[color],g[color],b[color]); } } }
void draw_filledCircle( unsigned int x, unsigned int y, double rad, uint8_t r, uint8_t g, uint8_t b ) { uint8_t i,j; for(i=0;i<rad;i++) { for(j=0;j<(i+1);j++) { double dist = pythagoras( j,i ); if(dist <= rad-1) { setLedXY(y-j,x+i,r,g,b); setLedXY(y+j,x+i,r,g,b); setLedXY(y+j,x-i,r,g,b); setLedXY(y-j,x-i,r,g,b); setLedXY(y-i,x-j,r,g,b); setLedXY(y-i,x+j,r,g,b); setLedXY(y+i,x+j,r,g,b); setLedXY(y+i,x-j,r,g,b); }else if(dist < rad) { dla_plot(y-j,x+i,r,g,b,1-(dist-rad+1)); dla_plot(y+j,x+i,r,g,b,1-(dist-rad+1)); dla_plot(y+j,x-i,r,g,b,1-(dist-rad+1)); dla_plot(y-j,x-i,r,g,b,1-(dist-rad+1)); dla_plot(y-i,x+j,r,g,b,1-(dist-rad+1)); dla_plot(y+i,x+j,r,g,b,1-(dist-rad+1)); dla_plot(y+i,x-j,r,g,b,1-(dist-rad+1)); dla_plot(y-i,x-j,r,g,b,1-(dist-rad+1)); } } } }
static uint8_t tick() { static int8_t m = 0; static int8_t d = 1; int8_t x; // clear for(x = 0; x < LED_WIDTH * LED_HEIGHT; x++) setLedXY(x & 3, x >> 2, 0); // < looks nice, but does not work when LED_WIDTH/HEIGHT changes m += d; if(m < 1 || m == LED_HEIGHT - 1) d = -d; // draw row for(x = 0; x < LED_WIDTH; x++) setLedXY(x, m, 7); return 0; }
uint8_t tick_ball() { // bounce if(x == BOFF || x == LED_WIDTH - BOFF - 1) { dx *= -1; } if(y == BOFF || y == LED_HEIGHT - BOFF - 1) { dy *= -1; } // move x += dx; y += dy; // display const uint8_t ball[3][3] = { {0, 1, 0}, {1, 1, 1}, {0, 1, 0}, }; for(int8_t tx = -2; tx <= 2; ++tx) { for(int8_t ty = -2; ty <= 2; ++ty) { const int8_t ax = tx + x, ay = ty + y; if(ax >= 0 && ay >= 0 && ax < LED_WIDTH && ay < LED_HEIGHT) { uint8_t bright = 0; if(abs(tx) <= 1 && abs(ty) <= 1) { bright = ball[tx+1][ty+1]; } setLedXY(ax, ay, bright); } } } return 0; }
static uint8_t tick(void) { static int a = 0; a ^= 1; for(int y = 0; y < LED_HEIGHT; y++) { for(int x = 0; x < LED_WIDTH; x++) { setLedXY( x,y,a*0x0f ); } } Delay(60); return 0; }
static uint8_t tick(void) { for(int y = 0, p = 0; y < LED_HEIGHT; y++) { for (int x = 0; x < LED_WIDTH; x++, p++) { /* Compute neighbor averages, with wrap-around. */ int16_t sa = 0, sb = 0, sc = 0; for(int j = y -1 ; j < y + 2; j++) { for(int i = x - 1; i < x + 2; i++) { int q = (j < 0 ? j + LED_HEIGHT : j >= LED_HEIGHT ? j - LED_HEIGHT : j) * LED_WIDTH + (i < 0 ? i + LED_WIDTH : i >= LED_WIDTH ? i - LED_WIDTH : i); sa += bzr_a[q]; sb += bzr_b[q]; sc += bzr_c[q]; } } /* This should be 9 but then it dies... */ sa /= 9; sb /= 9; sc /= 9; int16_t ta = (sa * (259 + sb - sc)) >> 8; int16_t tb = (sb * (259 + sc - sa)) >> 8; int16_t tc = (sc * (259 + sa - sb)) >> 8; t_bzr_a[p] = MIN(255, ta); t_bzr_b[p] = MIN(255, tb); t_bzr_c[p] = MIN(255, tc); setLedXY(x, y, t_bzr_a[p], t_bzr_b[p], t_bzr_c[p]); } } for(int y = 0, p = 0; y < LED_HEIGHT; y++) { for (int x = 0; x < LED_WIDTH; x++, p++) { bzr_a[p] = t_bzr_a[p]; bzr_b[p] = t_bzr_b[p]; bzr_c[p] = t_bzr_c[p]; } } return 0; }
void draw_char(int x,int y, char text, uint8_t r,uint8_t g, uint8_t b) { text-=32; int i; for (i = 0; i < 6; i++) { #ifdef __AVR__ char ch = pgm_read_byte(&font8x6[(int)text][i]); #else char ch = font8x6[(int)text][i]; #endif int j; for (j = 0; j < 8; j++) { if(ch & (1<<j)) { setLedXY(x+i,y+j+4,r,g,b); } } } }
void draw_flash(uint8_t b) { setLedXY(1, 3, b); setLedXY(1, 4, b); setLedXY(2, 3, b); setLedXY(2, 4, b); }
uint8_t tick_snake() { int8_t x = buffer[pointer], y = buffer[pointer + 1]; // init? if(end < 0) { new_apple(); end = 0; } // the end? if(end > 0) { for(int8_t i = length - 1; i >= 0; --i) { const int8_t cur = CYCLE(pointer - i * 2, ARRAY_SIZE(buffer)); setLedXY(buffer[cur], buffer[cur + 1], (end % 3) * 2 + (i == 0) * 3); } ++end; if(end > 9) { end = -1; length = 1; return 1; } else { return 0; } } // game step or animation? if(tick == 0) { // move switch(direction) { case 0: ++x; break; case 1: ++y; break; case 2: --x; break; case 3: --y; break; } x = CYCLE(x, LED_WIDTH); y = CYCLE(y, LED_HEIGHT); // save pointer = (pointer + 2) % ARRAY_SIZE(buffer); buffer[pointer] = x; buffer[pointer + 1] = y; // eaten? if(apple[0] == x && apple[1] == y) { ++length; new_apple(); } // collision if(collision(x, y, 1)) { end = 1; } // paint start of tail const int8_t last = CYCLE(pointer - 2, ARRAY_SIZE(buffer)); setLedXY(buffer[last], buffer[last+1], 3); // clear tail const int8_t end = CYCLE(pointer - length * 2, ARRAY_SIZE(buffer)); setLedXY(buffer[end], buffer[end + 1], 0); // paint apple setLedXY(apple[0], apple[1], MAX_TICK); // paint head setLedXY(x, y, 7); } else { // pulsing apple setLedXY(apple[0], apple[1], tick); } // tick on if(++tick >= MAX_TICK) { tick = 0; } return 0; }
void draw_winner1(void) { setLedXY(2, 1, 7); setLedXY(1, 2, 7); setLedXY(1, 0, 7); }
void draw_winner2(void) { setLedXY(1, 1, 7); setLedXY(2, 2, 7); setLedXY(2, 0, 7); }