void invaders_shot() { register char *p; byte i; if (inv_shot_y > 0) { SET_PIXEL(inv_shot_x, inv_shot_y); SET_PIXEL(inv_shot_x, inv_shot_y - 1); inv_shot_y += 3; if (inv_shot_y >= 100) inv_shot_y = 0; } else { if (tank_pos >= inv_pos_x && tank_pos < inv_pos_x + 6 * (inv_x_last - inv_x_first + 1)) { i = inv_x_first + (tank_pos - inv_pos_x) / 6; if (invaders_alive[i][2]) { inv_shot_y = inv_pos_y * 3 + 30; inv_shot_x = inv_pos_x * 2 + (i - inv_x_first) * 12 + 6; } else if (invaders_alive[i][1]) { inv_shot_y = inv_pos_y * 3 + 20; inv_shot_x = inv_pos_x * 2 + (i - inv_x_first) * 12 + 6; } else if (invaders_alive[i][0]) { inv_shot_y = inv_pos_y * 3 + 10; inv_shot_x = inv_pos_x * 2 + (i - inv_x_first) * 12 + 6; } } } }
void antigravity(uint8_t interval = 200 /* ms */) { // move all of the LED's upwards (we can move them in other directions in the future) for (uint8_t iteration = 0; iteration < 5; iteration++) { mp_hal_delay_ms(interval); bool wait = false; for (uint8_t row = 1; row < 5 - iteration; row++) { for (uint8_t col = 0; col < 5; col++) { // move this bit down if possible uint8_t val = GET_PIXEL(col, row); if (val) { // this is why the row for loop starts at one if (!GET_PIXEL(col, row - 1)) { SET_PIXEL(col, row, 0); SET_PIXEL(col, row - 1, val); wait = true; } } // we don't care if the LED is off } } if (!wait) { continue; } } }
void samples2coefficients(FloatImage *inbuf, char dimension) { int ii, kk; float z = sqrt(3.0) - 2.0; float lambda = (1.0 - z) * (1.0 - 1.0/z); float value; // Apply overall gain for (ii=0; ii<inbuf->size_x; ii++) for (kk=0; kk<inbuf->size_y; kk++) { value = GET_PIXEL(ii,kk) * lambda; SET_PIXEL(ii,kk,value); } for (kk=0; kk<inbuf->size_y; kk++) { // Causal initialization (first pixel of line) } // Causal recursion // Anticausal initialization // Anticausal recursion }
/* KITECH_TopologicalGlobalMapComp의 onInitialize()에서 bmp 파일의 비트맵 읽어 세선화 알고리즘을 수행하여 처리하기 때문에 수행속도가 오래 걸림. bmp 비트맵의 크기와 형태에 따라 세선화 알고리즘의 수행속도가 틀려짐. <환경 조건> 1. Tetra 로봇 플렛폼 2. Intel Core2Duo 2.1GHz 3. 950 x 850 크기의 map <실험> 1. onInitialize() 수행 속도 측정 26047ms 26078ms 26093ms 26125ms 26031ms 26031ms 26094ms 26078ms 26125ms 26047ms */ ReturnType KITECH_TopologicalGlobalMapComp::onInitialize() { PrintMessage ("KITECH_TopologicalGlobalMapComp::onInitialize()\n"); #define GET_PIXEL(image, x, y) (*(image + mapWidth * y + x)) #define SET_PIXEL(image, x, y, value) (*(image + mapWidth * y + x) = value) parameter.SetProperty(getPropertyMap()); if (!LoadProperty()) { error = -1; return OPROS_FIND_PROPERTY_ERROR; } gridBasedGlobalMap = new GridBasedGlobalMap (mapFileName.c_str(), mapResolution); if (gridBasedGlobalMap == NULL) { error = -1; return OPROS_INTERNAL_FAULT; } gridBasedGlobalMap->ExpandObstacle (1, 1, 255); gridBasedGlobalMap->ExpandObstacle (1, 255, 127); gridBasedGlobalMap->ExpandObstacle (1, 127, 63); gridBasedGlobalMap->ExpandObstacle (INTEGER(mobileSafeRadius/mapResolution), 1, 10); int mapWidth = gridBasedGlobalMap->_width; int mapHeight = gridBasedGlobalMap->_height; BYTE *inBuff = new BYTE [mapWidth*mapHeight]; BYTE *outBuff = new BYTE [mapWidth*mapHeight]; int x, y; for (y = 0; y < mapHeight; y++) { for (x = 0; x < mapWidth; x++) { BYTE pixel = gridBasedGlobalMap->GetPixelCELL (x, y); SET_PIXEL (inBuff, x, y, ((0 < pixel) ? 0 : 4)); } } CThinning thinnig; if (thinnig.MakeThinning (outBuff, inBuff, mapWidth, mapHeight) < 0) { delete [] inBuff; delete [] outBuff; error = -1; return OPROS_INTERNAL_FAULT; } for (y = 0; y < mapHeight; y++) { for (x = 0; x < mapWidth; x++) { BYTE pixel = GET_PIXEL (outBuff, x, y); BYTE pixel2 = gridBasedGlobalMap->GetPixelCELL (x, y); gridBasedGlobalMap->SetPixelCELL (x, y, pixel | pixel2); } } delete [] inBuff; delete [] outBuff; error = 0; return OPROS_SUCCESS; }
void tank_shot() { register char *p; byte x, y, i; if (shot_y > 0) { SET_PIXEL(shot_x, shot_y); SET_PIXEL(shot_x, shot_y + 1); if (shot_y > 3) { shot_y -= 3; // test if an invader was hit if (getpixel(shot_x, shot_y)) { x = (shot_x - inv_pos_x * 2) / 12 + inv_x_first; y = (shot_y - inv_pos_y * 3) / 10; if (y < 3 && x >= inv_x_first && x <= inv_x_last) { invaders_alive[x][y] = 0; inv_count--; if (x == inv_x_first) { i = inv_x_first; while (!invaders_alive[i][0] && !invaders_alive[i][1] && !invaders_alive[i][2] && i < INV_X_COUNT) i++; inv_pos_x += 6 * (i - inv_x_first); inv_x_first = i; } else if (x == inv_x_last) { i = inv_x_last; while (!invaders_alive[i][0] && !invaders_alive[i][1] && !invaders_alive[i][2] && i > 0) i--; inv_x_last = i; } } shot_y = 0; } } else shot_y = 0; } }
void draw_invader(byte xpos, byte ypos, byte no) { register char *p; register byte *ip; byte x, y; ip = &invader[no * 2 + inv_look][0][0]; for (y = ypos; y < ypos + 9; y++) { for (x = xpos; x < xpos + 10; x++) { if (*ip == 1) { SET_PIXEL(x, y); } ip++; } } }
void init_game() { byte x, y; byte *ip; register char *p; for (x = 0; x < INV_X_COUNT; x++) for (y = 0; y < INV_Y_COUNT; y++) invaders_alive[x][y] = 1; inv_x_first = 0; inv_x_last = INV_X_COUNT - 1; inv_pos_x = 1; inv_pos_y = 3; inv_dir = 1; inv_look = 0; inv_count = INV_X_COUNT * INV_Y_COUNT; tank_pos = 38; ip = &tank[0][0]; for (y = 0; y < 8; y++) { for (x = 0; x < 7; x++) { if (*ip == 1) { SET_PIXEL(x, y); } ip++; } } ip = &tank_char[0][0]; for (y = 0; y < 2; y++) { for (x = 0; x < 4; x++) { *ip = V_GETCHAR_BUF(x, y); ip++; V_SETCHAR_BUF(x, y, 0); } } }