Exemplo n.º 1
0
int det_cell_status(int x, int y)
{
	if (field[x][y] == 0) {
		if (living_neighbors(x,y) == 3) /* new born */ return 1;
		else return 0;
	} else {
		if (living_neighbors(x,y) < 2) /* solitude */ return 0;
		else {
			if (living_neighbors(x,y) > 3) /* overpopulation */ return 0;
			else /* nothing happened */ return 1;
		}
	}
}
Exemplo n.º 2
0
void conway_run(int8_t *start_pic)
{
	old_fb = start_pic;
	new_fb = led_matrix_set_fb(old_fb);
	uint8_t	changed = 1; // first time anyway

	led_matrix_set_pixel(8, 4, 1);
	led_matrix_set_pixel(8, 5, 1);
	led_matrix_set_pixel(8, 6, 1);

		
	led_matrix_set_pixel(7, 5, 1);
	led_matrix_set_pixel(7, 11, 1);

	led_matrix_set_pixel(8, 10, 1);
	led_matrix_set_pixel(8, 11, 1);
	led_matrix_set_pixel(8, 12, 1);

	app_reset_tick();
	app_start_tick();

	while(1) {
	if(old_fb == new_fb) {
		uart_puts("the same!!!\n");
		//malloc new fb
	} 

		for(uint8_t x = 0; x < SIZE_X; x ++) {
			for(uint8_t y = 0; y < SIZE_Y; y ++) {
				uint8_t neighbors = living_neighbors(x,y);
				if(neighbors == 3) {
					if(is_dead(x,y)) {
						changed = 1;
					}
					set_alive(x,y);
				}else if(neighbors == 2) {
					if(is_alive(x,y)) {
						set_alive(x,y);
					}else{
						set_dead(x,y);
					}
				}else {
					
					if(is_alive(x,y)) {
						changed = 1;
					}
					set_dead(x,y);
				}
			}
		}
		if(changed == 0) {
			reset_fb();
			app_stop_tick();
			app_reset_tick();
			return;	
		}
		changed = 0;
		/*	while(app_get_tick()) {
			uart_puts("waiting\n");
			_delay_ms(10);
			}*/
		for(int k = 0; k < 50; k++) {
			_delay_ms(10);
		}
		app_dec_tick();
		old_fb = new_fb;
		new_fb = led_matrix_set_fb(new_fb);
	}
}