int main(int argc,char **argv){ int aliveCellNumber = 0; int generation = 0; int idPattern; signal(SIGINT, intHandler); running_status= RUN; game_status= RUNNING; header(); srand(time(NULL)); idPattern = menu(); cellNumber = cols*rows; griddist = (struct t_grid*)malloc( cellNumber *sizeof(struct t_grid) ); if (griddist == NULL) exit(-1); gridnext = (struct t_grid*)malloc( cellNumber *sizeof(struct t_grid) ); if (gridnext == NULL) exit(-2); init_blank(griddist, cellNumber); init_blank(gridnext, cellNumber); aliveCellNumber = fill_univers(idPattern, griddist,cols,rows); while (isRunning()){ monitorclear(); displayGrid(griddist,cols,rows); printf("\n Generation %d | %d living cell(s) | ctrl-c pour terminer \n", generation, aliveCellNumber); next(&generation); generation++; aliveCellNumber = computeNext(); swap_mat(); } printf("\n Generation %d | %d living cell(s) | Finished! \n", generation, aliveCellNumber); if (griddist != NULL) free(griddist); if (gridnext != NULL) free(gridnext); return 0; }
// main function int main(void) { // coord of endpoints of line int x1, y1, x2, y2; char **grid; // set up dynamic memory 2D array grid = malloc(MAX_ROW * sizeof(char*)); for (int row = 0; row < MAX_ROW; row++) { grid[row] = malloc(MAX_COL * sizeof(char)); // add blank chars to each element for (int col = 0; col < MAX_COL; col++) { grid[row][col] = BLANK; } } // ask the user for width and height x1 = getint("Enter starting X: "); y1 = getint("Enter starting Y: "); x2 = getint("Enter ending X: "); y2 = getint("Enter ending Y: "); // check all values are in range if (inRange(x1, 0, MAX_COL) and inRange(y1, 0, MAX_ROW) and inRange(y1, 0, MAX_COL) and inRange(y2, 0, MAX_ROW)) { // add the end points to the array grid[y1][x1] = DOT; grid[y2][x2] = DOT; // draw line between the two points drawLine(x1, y1, x2, y2, grid); // display the grid displayGrid(grid); } // end of program // free memory for (int i = 0; i < MAX_ROW; i++) { free(grid[i]); } free(grid); // end pause; return 0; }
/** ========================= Main function ==========================*/ int main (){ init(); Serial.begin(9600); randomSeed(analogRead(3)); // randomSeed() initializes the pseudo-random number generator pinMode(SEL, INPUT); digitalWrite(SEL, HIGH); tft.initR(INITR_BLACKTAB); // initialize a ST7735R chip initializeGrid(); displayGrid(); gamePlay(); return 0; }
//path finding algorithm based on Lee's algorithm void findPath () { //Init entryNode->label = 0; //Wave expansion print(1, 1, "Pathfinder initialized, starting wave expansion...\n"); startStopwatch (); expand (&entryNode, 1); //use wave expansion expansionTime = stopStopwatch (); displayGrid (); //print results //Backtrace print(1, 1, "Tracing back path...\n\n"); startStopwatch (); backTrace (); backTraceTime = stopStopwatch (); displayPath (); //print results }
void run() { SDL_Surface *screen; bool loopRunning = true; if(SDL_Init(SDL_INIT_VIDEO) != 0) { std::cout<<"Can't initialize SDL"<<SDL_GetError()<<std::endl; exit(1); } atexit(SDL_Quit); screen = SDL_SetVideoMode(rtBlock::WIDTH * rtLevel::GRID_WIDTH, rtBlock::HEIGHT * rtLevel::GRID_HEIGHT, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); if (screen == NULL) { std::cout<<"Unable to set video mode: "<<SDL_GetError()<<std::endl; exit(1); } SDL_WM_SetCaption("Level Editor", NULL); rtResource::init(); SDL_Event event; while(loopRunning) { while(SDL_PollEvent(&event)) { if (SDL_QUIT == event.type) loopRunning = false; else if (SDL_KEYDOWN == event.type && SDLK_ESCAPE == event.key.keysym.sym) loopRunning = false; else handleEvent(event); } SDL_FillRect(screen, NULL, 0x0); displayGrid(screen); SDL_Flip(screen); } rtResource::cleanup(); }
/* Purpose: To execute the grid and display current layer * Pre: Current layer exists, * Starting list exists, * stringstream with user input * Post: Executes the grid and displays current layer * Author: Matthew James Harrison ******************************************************************************/ void run(Layer &layer, StartingList &startingList, stringstream &ss) { /* If no junk data */ if (!hasJunk(ss)) { /* Save file */ saveToFile(DATA_PATH, layer); /* Execute */ execute(layer, startingList); /* Display */ utls::clear(); displayGrid(layer); displayMessage(MSG_EXECUTE); /* Revert by loading file */ loadFromFile(DATA_PATH, layer, startingList); } else { displayMessage(MSG_INV_COMMAND); } }
void gamePlay() { // detect the movement of the cursor int initHoriz = analogRead(HORIZ); int initVerti = analogRead(VERT); while(true) { oldCursorX = cursorX; oldCursorY = cursorY; int finalHoriz = analogRead(HORIZ); int finalVerti = analogRead(VERT); int select = digitalRead(SEL); // HIGH(1) if not pressed, LOW(0) if pressed int deltaHoriz = (finalHoriz - initHoriz)/100; int deltaVerti = -(finalVerti - initVerti)/100; cursorX += deltaHoriz; cursorY += deltaVerti; int whetherFull = full(); //int whetherMove = blockMoved(); // cursur has moved if (oldCursorX!=cursorX || oldCursorY!=cursorY) { // backup the current grid before updating the tiles, for undo() function gridBackup(); updateTile(deltaVerti, deltaHoriz); // check if any further movements can be made if(whetherFull && noMoreAdd) {continueGame = 0;} else { continueGame = 1; createNew(); } displayGrid(); delay(50); } // Undo: button of joystick has been pressed if (select == 0) { score-=plus; undo(); displayGrid(); } // if the game is over, display game over screen and break the while loop int gameEnd = gameOverCheck(); if (gameEnd) {break;} // test: print out the values of coordinates to serial-mon //Serial.print(" whetherMove: "); //Serial.print(whetherMove); Serial.print(" continueGame: "); Serial.print(continueGame); Serial.print(" cursorX: "); Serial.print(cursorX); Serial.print(" cursorY: "); Serial.print(cursorY); Serial.print(" SEL= "); Serial.print(select,DEC); Serial.println(); delay(10); } }
void doMeander(grid* unsolvedGrid) { meander(unsolvedGrid); displayGrid(unsolvedGrid); }
// main function int main(void) { // coord of endpoints of line int x1 = -2, y1 = -2, x2, y2; char **grid; int isDone = 0; // set up dynamic memory 2D array grid = malloc(MAX_ROW * sizeof(char*)); for (int row = 0; row < MAX_ROW; row++) { grid[row] = malloc(MAX_COL * sizeof(char)); // add blank chars to each element for (int col = 0; col < MAX_COL; col++) { grid[row][col] = BLANK; } } while (not isDone) { // ask the user for width and height x2 = getint("Enter X: "); y2 = getint("Enter Y: "); // check if point is on grid if (inRange(x2, 0, MAX_COL) and inRange(y2, 0, MAX_ROW)) { // add the end points to the array grid[y2][x2] = DOT; if (x1 != -2 and y1 != -2) { // draw line between the two points drawLine(x1, y1, x2, y2, grid); } // add current point to previous point x1 = x2; y1 = y2; // display the grid displayGrid(grid); } else if (x2 == -1 or y2 == -1) { // quit isDone = 1; } else { // invalid input printf("XY coord not in range.\n"); } } // end of program // free memory for (int i = 0; i < MAX_ROW; i++) { free(grid[i]); } free(grid); // end pause; return 0; }
/** * Display of the RGB histograms data */ bool HSLOverlay::draw(const OFX::DrawArgs& args) { bool hasGridBeenDisplayed = false; // grid has not been displayed yet // height of the window (image for test) // width of the window (image for test) OfxPointI size = _plugin->_clipSrc->getPixelRodSize(args.time); const double step = size.x / (double)(getOverlayData()._data._step - 1); double heightH, heightS, heightL; heightH = heightS = heightL = size.y; if(!(_plugin->_paramDisplayTypeSelection->getValue() == 1)) { // get max of the three channels const Number maxH = *(std::max_element(getOverlayData()._data._bufferHue.begin(), getOverlayData()._data._bufferHue.end())); const Number maxS = *(std::max_element(getOverlayData()._data._bufferSaturation.begin(), getOverlayData()._data._bufferSaturation.end())); const Number maxL = *(std::max_element(getOverlayData()._data._bufferLightness.begin(), getOverlayData()._data._bufferLightness.end())); // Adapt maximal value (3 cases) if(maxH > maxS && maxH > maxL) // H is the max { heightS = maxS * heightH / maxH; heightL = maxL * heightH / maxH; } else if(maxS > maxH && maxS > maxL) // S is the max { heightH = maxH * heightS / maxS; heightL = maxL * heightS / maxS; } else // L is the max { heightH = maxH * heightL / maxL; heightS = maxS * heightL / maxL; } } float selectionMultiplier = (float)_plugin->_paramSelectionMultiplierSelection->getValue(); // Display on screen if specified (HSL) if(_plugin->_paramOverlayHSelection->getValue()) // HUE CHANNEL { if(!hasGridBeenDisplayed) // if grid has not been displayed yet { displayGrid(size.y, size.x); // display grid on screen hasGridBeenDisplayed = true; // set grid has already been displayed to true } displayASpecificHistogram(getOverlayData()._data._bufferHue, getOverlayData()._selectionData._bufferHue, step, heightH, size.x, redHisto, selectionMultiplier); if(getOnlyChannelSelectedHSL() == eSelectedChannelH) { displaySelectionPoints(getOverlayData()._selectionData._bufferHue, step, size.x, redHisto); // selection points displayAverageBar(getOverlayData()._averageData._averageHue, averageHisto, size.x, size.y, step); // average bar displayHueIndicator(size, kPrecisionHueIndicator); // indicator } } if(_plugin->_paramOverlaySSelection->getValue()) // SATURATION CHANNEL { if(!hasGridBeenDisplayed) // if grid has not been displayed yet { displayGrid(size.y, size.x); // display grid on screen hasGridBeenDisplayed = true; // set grid has already been displayed to true } displayASpecificHistogram(getOverlayData()._data._bufferSaturation, getOverlayData()._selectionData._bufferSaturation, step, heightS, size.x, greenHisto, selectionMultiplier); if(getOnlyChannelSelectedHSL() == eSelectedChannelS) { displaySelectionPoints(getOverlayData()._selectionData._bufferSaturation, step, size.x, greenHisto); // selection points displayAverageBar(getOverlayData()._averageData._averageSaturation, averageHisto, size.x, size.y, step); // average bar displaySaturationIndicator(size); // indicator } } if(_plugin->_paramOverlayLSelection->getValue()) // LIGHTNESS CHANNEL { if(!hasGridBeenDisplayed) // if grid has not been displayed yet { displayGrid(size.y, size.x); // display grid on screen hasGridBeenDisplayed = true; // set grid has already been displayed to true } displayASpecificHistogram(getOverlayData()._data._bufferLightness, getOverlayData()._selectionData._bufferLightness, step, heightL, size.x, blueHisto, selectionMultiplier); if(getOnlyChannelSelectedHSL() == eSelectedChannelL) { displaySelectionPoints(getOverlayData()._selectionData._bufferLightness, step, size.x, blueHisto); // selection points displayAverageBar(getOverlayData()._averageData._averageLightness, averageHisto, size.x, size.y, step); // average bar displayLightnessIndicator(size); // indicator } } // Display border (separate from histograms to eliminate blending) if(_plugin->_paramOverlayHSelection->getValue()) displayASpecificHistogramBorder(getOverlayData()._data._bufferHue, step, heightH, size.x, redHisto); // H if(_plugin->_paramOverlaySSelection->getValue()) displayASpecificHistogramBorder(getOverlayData()._data._bufferSaturation, step, heightS, size.x, greenHisto); // S if(_plugin->_paramOverlayLSelection->getValue()) displayASpecificHistogramBorder(getOverlayData()._data._bufferLightness, step, heightL, size.x, blueHisto); // L return true; }
/** * Display of the RGB histograms data */ bool RGBOverlay::draw(const OFX::DrawArgs& args) { _isGriddisplay = false; // height of the window (image for test) // width of the window (image for test) const OfxPointI size = _plugin->_clipSrc->getPixelRodSize(args.time); const double step = size.x / (double)(getOverlayData()._data._step - 1); double heightR, heightG, heightB; heightR = heightG = heightB = size.y; if(!(_plugin->_paramDisplayTypeSelection->getValue() == 1)) { // get max of the three channels Number maxR = *(std::max_element(getOverlayData()._data._bufferRed.begin(), getOverlayData()._data._bufferRed.end())); Number maxG = *(std::max_element(getOverlayData()._data._bufferGreen.begin(), getOverlayData()._data._bufferGreen.end())); Number maxB = *(std::max_element(getOverlayData()._data._bufferBlue.begin(), getOverlayData()._data._bufferBlue.end())); if(maxR > maxG && maxR > maxB) // R is the max { heightG = maxG * heightR / maxR; heightB = maxB * heightR / maxR; } else if(maxG > maxR && maxG > maxB) // G is the max { heightR = maxR * heightG / maxG; heightB = maxB * heightG / maxG; } else // B is the max { heightR = maxR * heightB / maxB; heightG = maxG * heightB / maxB; } } float selectionMultiplier = (float)_plugin->_paramSelectionMultiplierSelection->getValue(); // get selection multiplier from plugin // display on screen if specified (RGB) if(_plugin->_paramOverlayRSelection->getValue()) // RED CHANNEL { if(!_isGriddisplay) // if grid has not been already displayed { displayGrid(size.y, size.x); // display grid _isGriddisplay = true; // set display grid to true } displayASpecificHistogram(getOverlayData()._data._bufferRed, getOverlayData()._selectionData._bufferRed, step, heightR, size.x, redHisto, selectionMultiplier); if(getOnlyChannelSelectedRGB() == eSelectedChannelR) { displaySelectionPoints(getOverlayData()._selectionData._bufferRed, step, size.x, redHisto); // selection points displayAverageBar(getOverlayData()._averageData._averageRed, averageHisto, size.x, size.y, step); // average bar displayRedIndicator(size); // indicator } } if(_plugin->_paramOverlayGSelection->getValue()) // GREEN CHANNEL { if(!_isGriddisplay) // if grid has not been already displayed { displayGrid(size.y, size.x); // display grid _isGriddisplay = true; // set display grid to true } displayASpecificHistogram(getOverlayData()._data._bufferGreen, getOverlayData()._selectionData._bufferGreen, step, heightG, size.x, greenHisto, selectionMultiplier); if(getOnlyChannelSelectedRGB() == eSelectedChannelG) { displaySelectionPoints(getOverlayData()._selectionData._bufferGreen, step, size.x, greenHisto); // selection points displayAverageBar(getOverlayData()._averageData._averageGreen, averageHisto, size.x, size.y, step); // average // bar displayGreenIndicator(size); // indicator } } if(_plugin->_paramOverlayBSelection->getValue()) // BLUE CHANNEL { if(!_isGriddisplay) // if grid has not been already displayed { displayGrid(size.y, size.x); // display grid _isGriddisplay = true; // set display grid to true } displayASpecificHistogram(getOverlayData()._data._bufferBlue, getOverlayData()._selectionData._bufferBlue, step, heightB, size.x, blueHisto, selectionMultiplier); if(getOnlyChannelSelectedRGB() == eSelectedChannelB) { displaySelectionPoints(getOverlayData()._selectionData._bufferBlue, step, size.x, blueHisto); // selection points displayAverageBar(getOverlayData()._averageData._averageBlue, averageHisto, size.x, size.y, step); // average bar displayBlueIndicator(size); // indicator } } // Display border (separate from histograms to eliminate blending) if(_plugin->_paramOverlayRSelection->getValue()) displayASpecificHistogramBorder(getOverlayData()._data._bufferRed, step, heightR, size.x, redHisto); // R if(_plugin->_paramOverlayGSelection->getValue()) displayASpecificHistogramBorder(getOverlayData()._data._bufferGreen, step, heightG, size.x, greenHisto); // G if(_plugin->_paramOverlayBSelection->getValue()) displayASpecificHistogramBorder(getOverlayData()._data._bufferBlue, step, heightB, size.x, blueHisto); // B return true; }