IplImage *generateStitching(IplImage *img_src1, IplImage *img_src2, CvMat *tmatrix, uchar with_borders, double blend_weight) { if (tmatrix == NULL) return NULL; if (blend_weight <= 0) blend_weight = 1; uchar mustFree1 = 0, mustFree2 = 0; IplImage *img1 = NULL, *img2 = NULL; if (img_src1->nChannels < 4) { img1 = convertTo4Channels(img_src1); mustFree1 = 1; } else { img1 = img_src1; } if (img_src2->nChannels < 4) { img2 = convertTo4Channels(img_src2); mustFree2 = 1; } else { img2 = img_src2; } if (with_borders) { drawBorders(img1, 2); drawBorders(img2, 2); } CvRect mbr = getProjectionMBR(img1, tmatrix); int64_t width = MAX(img2->width,mbr.x + mbr.width) - MIN(0, mbr.x); int64_t height = MAX(img2->height,mbr.y + mbr.height) - MIN(0, mbr.y); int64_t orig_x = MAX(0, -mbr.x); int64_t orig_y = MAX(0, -mbr.y); IplImage *prjTmp = cvCreateImage(cvSize(width, height), img1->depth, img1->nChannels); projectImg(img1, orig_x, orig_y, prjTmp, tmatrix); IplImage *final = cvCreateImage(cvSize(width, height), img1->depth, img1->nChannels); //cvSetZero(final); cvRectangle(final, cvPoint(0, 0), cvPoint(width, height), cvScalarAll(255), -1, 8, 0); my_image_copyPixels(img2, final, orig_x, orig_y); my_image_copyWeightedPixels(prjTmp, final, 0, 0, blend_weight); cvReleaseImage(&prjTmp); if (mustFree1) cvReleaseImage(&img1); if (mustFree2) cvReleaseImage(&img2); IplImage *cropped = remove_borders(final); if (cropped == NULL) { return final; } else {
Snake::Snake():AnimUT() { #ifdef debug qDebug("Snake launched"); #endif controls->addAnimationControl(animate, 200); cellSize = 15; nbCells = 20; // controls snakeItem = new SnakeItem(cellSize, nbCells); controls->addLabel("Movements"); QPushButton *upBtn = controls->addButton("Up"); connect(upBtn, SIGNAL(released()), snakeItem, SLOT(setUp())); QPushButton *downBtn = controls->addButton("Down"); connect(downBtn, SIGNAL(released()), snakeItem, SLOT(setDown())); QPushButton *leftBtn = controls->addButton("Left"); connect(leftBtn, SIGNAL(released()), snakeItem, SLOT(setLeft())); QPushButton *rightBtn = controls->addButton("Right"); connect(rightBtn, SIGNAL(released()), snakeItem, SLOT(setRight())); controls->addDivider(); score = controls->addLabel("Score : 0"); connect(snakeItem, SIGNAL(updateScore(int)), this, SLOT(updateScore(int))); // viewer drawBorders(); viewer->addItem(snakeItem); }
void Level::draw() { m_spriteBatch.renderBatch(); for (unsigned int i = 0; i < m_borders.size(); ++i) { GamaGameEngine::RigidBody *b = m_borders[i]; b->shape->draw(); } drawBorders(); }
void Panel::draw() { if (active) { drawBackground(); drawBorders(); drawChildren(); } }
void Button::draw() { if (active) { drawBackground(); drawBorders(); drawChildren(); } }
/* main gl expose ,any time sreen needs to be redrawn, this function is called by gltemplate ,all drawings are initialized in this function params:ViewInfo , global view variable defined in viewport.c return value:0 if something goes wrong with GL 1 , otherwise */ int glexpose_main(ViewInfo * view) { static int doonce = 0; if (!glupdatecamera(view)) return 0; // glEnable(GL_DEPTH_TEST); // draw_cube(); // draw_cube_tex(); if (view->activeGraph >= 0) { if (!doonce) { doonce = 1; btnToolZoomFit_clicked(NULL, NULL); btnToolZoomFit_clicked(NULL, NULL); } } else return 0; glexpose_grid(view); #if UNUSED draw_fisheye_magnifier(view); draw_magnifier(view); #endif drawBorders(view); glexpose_drawgraph(view); drawRotatingAxis(); draw_selpoly(&view->Topview->sel.selPoly); glCompSetDraw(view->widgets); // draw_stuff(); // test_color_pallete(); // drawtestpoly(); /*DEBUG*/ /* if (view->mouse.mouse_mode == MM_PAN) { glBegin(GL_LINE_STRIP); glColor4f((GLfloat) 1, (GLfloat) 0.0, (GLfloat) 0.0, (GLfloat) 1); glVertex3f((GLfloat) view->GLx, (GLfloat) view->GLy, (GLfloat) 0.001); glVertex3f((GLfloat) view->GLx2, (GLfloat) view->GLy2, (GLfloat) 0.001); glEnd(); }*/ /*DEBUG*/ return 1; }
void ThumbSlider::paintEvent(QPaintEvent *event) { QPainter painter; painter.begin(this); painter.setClipRect(event->rect()); painter.setPen(Qt::NoPen); drawBackground(&painter); drawLines(&painter); drawBorders(&painter); drawEdges(&painter); }
void ButtonRessource::draw() { float wid = GraIngame::getMenuWidth(); GraphicInterface::drawObjectMenu(id, x1 * Options::ResolutionX/wid, y1 * Options::ResolutionY, (x2-x1)* Options::ResolutionX/wid, (y2-y1) * Options::ResolutionY); char buf[6]; _itoa_s(handler->getWishedWorker(changeID), buf, 6, 10); GraphicInterface::drastring2d(x1+relativeX, y1+relativeY, GLUT_BITMAP_TIMES_ROMAN_24, buf); char bufCurrent[6]; _itoa_s(handler->getCurrentValue(changeID), bufCurrent, 6, 10); GraphicInterface::drastring2d(x1+relativeX, y1+relativeY-0.03, GLUT_BITMAP_TIMES_ROMAN_24, bufCurrent); drawBorders(); }
void render(){ display.Clear(); drawGhost(); drawBlock(CODE); drawMap(); drawBorders(); drawNextBlock(); sprintf(TEXT,"Score: %i",score); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (0)*BLOCKPIXSIZE,0,0x00FF00); sprintf(TEXT,"Highscore: %i",hscore); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (1)*BLOCKPIXSIZE,0,0x00FF00); sprintf(TEXT,"Next:"); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (4)*BLOCKPIXSIZE,0,0x00FF00); display.Render(); }
void resetGame(){ //==========================START MSG Prints Highscore while(!keyboard.s){ display.Clear(); drawMap(); drawBorders(); sprintf(TEXT,"Press 's' to start"); display.DrawString(TEXT, 0, (HEIGHT/2)*BLOCKPIXSIZE,0,0x00FF00); display.Render(); keyboard.Poll(); SDL_Delay(50); } for(int i=0;i < WIDTH;i++){ for(int ii=0;ii < HEIGHT;ii++){ map[i][ii] = 0; } } score = 0; newBlock(); }
void ScrollablePanel::draw(sf::RenderTarget& target, sf::RenderStates states) const { states.transform.translate(getPosition()); const auto oldStates = states; // Draw the borders if (m_bordersCached != Borders{0}) { drawBorders(target, states, m_bordersCached, getSize(), m_borderColorCached); states.transform.translate({m_bordersCached.getLeft(), m_bordersCached.getTop()}); } // Draw the background const sf::Vector2f innerSize = {getSize().x - m_bordersCached.getLeft() - m_bordersCached.getRight(), getSize().y - m_bordersCached.getTop() - m_bordersCached.getBottom()}; drawRectangleShape(target, states, innerSize, m_backgroundColorCached); states.transform.translate(m_paddingCached.getLeft(), m_paddingCached.getTop()); sf::Vector2f contentSize = {innerSize.x - m_paddingCached.getLeft() - m_paddingCached.getRight(), innerSize.y - m_paddingCached.getTop() - m_paddingCached.getBottom()}; if (m_verticalScrollbar.getMaximum() > m_verticalScrollbar.getLowValue()) contentSize.x -= m_verticalScrollbar.getSize().x; if (m_horizontalScrollbar.getMaximum() > m_horizontalScrollbar.getLowValue()) contentSize.y -= m_horizontalScrollbar.getSize().y; // Draw the child widgets { const Clipping clipping{target, states, {}, contentSize}; states.transform.translate(-static_cast<float>(m_horizontalScrollbar.getValue()), -static_cast<float>(m_verticalScrollbar.getValue())); drawWidgetContainer(&target, states); } m_verticalScrollbar.draw(target, oldStates); m_horizontalScrollbar.draw(target, oldStates); }
void Logbuffermessage::draw() { if ( m_active && !m_logBuffer->getMessages().empty() ) { // m_active = true; unsigned int height = 5; m_dimensions.set(m_logBuffer->getLongestLength() + ( hpadding*2 ), (15 * (m_logBuffer->getMessages().size()-1)) + height + ( vpadding*2 )); // draw background box and border drawBackground(); drawBorders(); // render text // glColor3f(1.0f, 1.0f, 1.0f); for ( unsigned int i = 0; i < m_logBuffer->getMessages().size(); i++ ) Textprinter::Instance()->print(Vector2i(m_absposition.m_x + hpadding, m_absposition.m_y + height + (i*15) + vpadding), m_logBuffer->getMessages()[i].getMsg().c_str()); } /* else m_active = false;*/ }
void Textmessage::draw() { Logbuffer::Instance()->deleteExpiredMsg(); if ( !Logbuffer::Instance()->messages.empty() ) { active = true; unsigned int height = 5; v_width = Logbuffer::Instance()->longestLength + ( hpadding*2 ); v_height = (15 * (Logbuffer::Instance()->messages.size()-1)) + height + ( vpadding*2 ); // draw background box and border drawBackground(); drawBorders(); // render text glColor3f(1.0f, 1.0f, 1.0f); for ( unsigned int i = 0; i < Logbuffer::Instance()->messages.size(); i++ ) Textprinter::Instance()->print(position.x + hpadding, position.y + height + (i*15.0f) + vpadding, Logbuffer::Instance()->messages[i]->str); } else active = false; }
void Speciesview::draw() { if (active) { unsigned int highestCount = 0; unsigned int highestAD = 0; unsigned int highestNeurons = 0; unsigned int highestSynapses = 0; unsigned int highestBodyparts = 0; // initialize sort indices // at the same time find the highest Counts for all columns vector<int> indices ( genotypes->list.size(), 0 ); for ( unsigned int i = 0; i < genotypes->list.size(); i++ ) { indices[i] = i; if ( genotypes->list[i]->count > highestCount ) highestCount = genotypes->list[i]->count; if ( genotypes->list[i]->adamdist > highestAD ) highestAD = genotypes->list[i]->adamdist; if ( genotypes->list[i]->brainzArch->ArchNeurons.size() > highestNeurons ) highestNeurons = genotypes->list[i]->brainzArch->ArchNeurons.size(); // calc total syns unsigned int totalSyns = 0; for ( unsigned int j = 0; j < genotypes->list[i]->brainzArch->ArchNeurons.size(); j++ ) totalSyns += genotypes->list[i]->brainzArch->ArchNeurons[j].ArchSynapses.size(); if ( totalSyns > highestSynapses ) highestSynapses = totalSyns; if ( genotypes->list[i]->bodyArch->archBodyparts.size() > highestNeurons ) highestNeurons = genotypes->list[i]->bodyArch->archBodyparts.size(); } // sort results for ( int i = genotypes->list.size(); i>0; i-- ) for ( int j = 0; j < i-1; j++ ) if ( genotypes->list[indices[j]]->count < genotypes->list[indices[j+1]]->count ) { unsigned keepI = indices[j]; indices[j] = indices[j+1]; indices[j+1] = keepI; } int titleNumWH = textprinter->getWidth( highestCount ); int titleColorWH = qwidth; int titlePosWH = textprinter->getWidth( genotypes->list.size() ); int titleAdWH = textprinter->getWidth( highestAD ); int titleNeuronsWH = textprinter->getWidth( highestNeurons ); int titleSynapsesWH = textprinter->getWidth( highestSynapses ); int titleBodypartsWH = textprinter->getWidth( highestBodyparts ); int colw1 = titlePosW; if ( colw1 < titlePosWH ) colw1 = titlePosWH; int colw2 = titleColorW; if ( colw2 < titleColorWH ) colw2 = titleColorWH; int colw3 = titleNumW; if ( colw3 < titleNumWH ) colw3 = titleNumWH; int colw4 = titleAdW; if ( colw4 < titleAdWH ) colw4 = titleAdWH; int colw5 = titleNeuronsW; if ( colw5 < titleNeuronsWH ) colw5 = titleNeuronsWH; int colw6 = titleSynapsesW; if ( colw6 < titleSynapsesWH ) colw6 = titleSynapsesWH; int colw7 = titleBodypartsW; if ( colw7 < titleBodypartsWH ) colw7 = titleBodypartsWH; int colspacer = 15; int col1 = colspacer; int col2 = col1+colspacer + colw1; int col3 = col2+colspacer + colw2; int col4 = col3+colspacer + colw3; int col5 = col4+colspacer + colw4; int col6 = col5+colspacer + colw5; int col7 = col6+colspacer + colw6; int col8 = col7+colspacer + colw7; v_space = -10 + titlebar; v_height = (genotypes->list.size() * (qheight+rowspacer)) + rowspacer + titlebar; v_width = col8; drawBackground(); drawBorders(); drawChildren(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); textprinter->print( absPosition.x+col1, absPosition.y+19, titlePos ); textprinter->print( absPosition.x+col2, absPosition.y+19, titleColor ); textprinter->print( absPosition.x+col3, absPosition.y+19, titleNum ); textprinter->print( absPosition.x+col4, absPosition.y+19, titleAd ); textprinter->print( absPosition.x+col5, absPosition.y+19, titleNeurons ); textprinter->print( absPosition.x+col6, absPosition.y+19, titleSynapses ); textprinter->print( absPosition.x+col7, absPosition.y+19, titleBodyparts ); for ( unsigned int i=0; i < genotypes->list.size(); i++ ) { v_space += qheight + rowspacer; glColor4f(1.0f, 1.0f, 1.0f, 1.0f); textprinter->print( absPosition.x+col1, absPosition.y+v_space+9, i+1 ); textprinter->print( absPosition.x+col3, absPosition.y+v_space+9, genotypes->list[indices[i]]->count ); textprinter->print( absPosition.x+col4, absPosition.y+v_space+9, genotypes->list[indices[i]]->adamdist ); textprinter->print( absPosition.x+col5, absPosition.y+v_space+9, genotypes->list[i]->brainzArch->ArchNeurons.size() ); // total syns unsigned int totalSyns = 0; for ( unsigned int j = 0; j < genotypes->list[i]->brainzArch->ArchNeurons.size(); j++ ) totalSyns += genotypes->list[i]->brainzArch->ArchNeurons[j].ArchSynapses.size(); textprinter->print( absPosition.x+col6, absPosition.y+v_space+9, totalSyns ); textprinter->print( absPosition.x+col7, absPosition.y+v_space+9, genotypes->list[i]->bodyArch->archBodyparts.size() ); if ( *colormode ) glColor4f(genotypes->list[indices[i]]->speciescolor.r, genotypes->list[indices[i]]->speciescolor.g, genotypes->list[indices[i]]->speciescolor.b, genotypes->list[indices[i]]->speciescolor.a); else glColor4f(genotypes->list[indices[i]]->bodyArch->color.r, genotypes->list[indices[i]]->bodyArch->color.g, genotypes->list[indices[i]]->bodyArch->color.b, genotypes->list[indices[i]]->bodyArch->color.a); glBegin(GL_QUADS); glVertex2f(absPosition.x+col2, absPosition.y+v_space+qheight); glVertex2f(absPosition.x+col2, absPosition.y+v_space); glVertex2f(absPosition.x+col2+qwidth, absPosition.y+v_space); glVertex2f(absPosition.x+col2+qwidth, absPosition.y+v_space+qheight); glEnd(); glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glBegin(GL_LINES); glVertex2f(absPosition.x+col2, absPosition.y+v_space+qheight); glVertex2f(absPosition.x+col2, absPosition.y+v_space); glVertex2f(absPosition.x+col2, absPosition.y+v_space); glVertex2f(absPosition.x+col2+qwidth, absPosition.y+v_space); glVertex2f(absPosition.x+col2+qwidth, absPosition.y+v_space); glVertex2f(absPosition.x+col2+qwidth, absPosition.y+v_space+qheight); glVertex2f(absPosition.x+col2+qwidth, absPosition.y+v_space+qheight); glVertex2f(absPosition.x+col2, absPosition.y+v_space+qheight); glEnd(); } } }
void Spectrum::update(const Sint16* stream, const int length, const float delta) { if (!_initialized || length == 0) return; int w = _image.getWidth(); int h = _image.getHeight(); int step = length / w; if (_timer.hasEnded()) { /* FFT */ for (int i = 0; i < w; ++i) { float norm_amp = stream[i * step] * (1.f/32767.f); _rawValues[i] = Complex(norm_amp, 0); } std::valarray<Complex> fftArray(_rawValues, w); audio::FFT::fft(fftArray); for (int i = 0; i < w/2; ++i) { _fftValues[i] = std::log10(std::abs(fftArray[i])) * 20; } float octaves = calculateOctave(_minFreq, _maxFreq, _barCount); unsigned int currentFreq = _minFreq; for (unsigned int i = 0; i < _barCount; ++i) { int low = lowerLimitSample(currentFreq, octaves, w/2); int hi = upperLimitSample(currentFreq, octaves, w/2); if (currentFreq > Core::Audio()->getFrequencyRate() || hi > w/2) break; // Log.Info("C: %d [L: %d / H: %d]", currentFreq, low, hi); _barFrequencies[i] = currentFreq; _barValues[i] = averageFreq(_fftValues, low, hi); currentFreq = nextCenterFreq(currentFreq, octaves); } /* END FFT */ _image.setRect(0, 0, w, h, Color::Black); drawBorders(); int bar_size = w / (float)_barCount; for (unsigned int i = 0; i < _barCount; ++i) { float scale_val = std::max(0.f, _barValues[i]); float norm_val = scale_val / 30.f; _normalizedBarValues[i] = norm_val; Color color = math::interpolate(Color(255, 64, 0), Color::Red, norm_val, math::Interpolation::Linear); // Values // Log.Info("Bar %d: %f", i, val); int y = h - norm_val * h; _image.setRect(i*bar_size, y + 1, bar_size, h - y - 2, color); } _image.updateTextureZone(0, 0, w, h); _timer.reset(); } _timer.update(delta); }
bool Game::cursesMain() { initscr(); noecho(); curs_set(FALSE); nodelay(stdscr, TRUE); keypad(stdscr,TRUE); srand(time(NULL)); // Coloring the screen start_color(); init_pair(1, COLOR_WHITE, COLOR_RED); // border init_pair(2, COLOR_GREEN, COLOR_GREEN); // barrier init_pair(3, COLOR_GREEN, COLOR_BLACK); // player init_pair(4, COLOR_RED, COLOR_BLACK); // boss // set up initial windows getmaxyx(stdscr, parent_y, parent_x); //set default space player.lives = 3; player.score = 0; player.x = 14; player.y = parent_y - (score_size + 3); WINDOW *field = newwin(parent_y - score_size, parent_x, 0, 0); WINDOW *score = newwin(score_size, parent_x, parent_y - score_size, 0); drawBorders(score); buildGame(board); int alienCount = 0; for(int i = 0; i < BOARDROWSIZE;i++) { for(int j = 0; j < BOARDCOLUMNSIZE;j++) { char temp = board[i][j]; wmove(field, i, j); waddch(field, temp); if(temp == ALIEN1 || temp == ALIEN2 || temp == ALIEN3) alienCount++; // mvwprintw(field, i, j, "%c", board[i][j]); } } numberOfAliens = alienCount; rawtime = time(NULL); alienGroup.waitTime = rawtime+8; // uncomment for cout // /* while(1) { getmaxyx(stdscr, new_y, new_x); if (new_y != parent_y || new_x != parent_x) { parent_x = new_x; parent_y = new_y; wresize(field, new_y - score_size, new_x); wresize(score, score_size, new_x); mvwin(score, new_y - score_size, 0); wclear(stdscr); wclear(field); wclear(score); drawBorders(score); } // board[20][18] = 'O'; // draw to our windows for(int i = 0; i < BOARDROWSIZE;i++) { for(int j = 0; j < BOARDCOLUMNSIZE;j++) { char piece = board[i][j]; // writeToFile("%c", piece); wmove(field, i, j); // check if our bullet should be seen if(board[i][j] == BULLET && player.bullet.enabled == true) waddch(field, board[i][j]); // if it shouldnt be seen then we remove it else if(board[i][j] == BULLET && player.bullet.enabled == false) { waddch(field, ' '); board[i][j] = ' '; wmove(field, i-1, j); waddch(field, ' '); board[i-1][j] = ' '; wmove(field, i, j); } // print everything else else { // color certain pieces switch(piece) { //border case '+': case '-': case '|': waddch(field, piece | COLOR_PAIR(1)); break; // barriers case '/': case '\\': case '#': waddch(field, piece | COLOR_PAIR(2)); break; //player case 'A': waddch(field, piece | COLOR_PAIR(3)); default: waddch(field, piece); } } } // writeToFile("\n"); } // Draw score board mvwprintw(score, 1, 2, "Score: "); mvwprintw(score, 1, 9, itoa(player.score, buffer, 10)); mvwprintw(score, 1, 70, "Lives: "); mvwprintw(score, 1, 77, itoa(player.lives, buffer, 10)); if(DEBUG == true) { string screensizex = itoa(new_x, buffer, 10); string screensizey = itoa(parent_y, buffer, 10); mvwprintw(score, 1, 30, "X: "); mvwprintw(score, 1, 34, screensizex.c_str()); mvwprintw(score, 1, 40, "Y: "); mvwprintw(score, 1, 44, screensizey.c_str()); } bool aliensMovement = true; aliensMovement = moveAliens(rawtime); alienShoot(); if(player.bullet.enabled == true) { if(player.bullet.direction == 'U') // safety check { timerCheck = clock()-timer; if(timerCheck > 15) { if(DEBUG == true) writeToFile("Current: %i,%i | New: %i,%i\n", player.bullet.x, player.bullet.y, player.bullet.x-1, player.bullet.y); char temp = board[player.bullet.x-1][player.bullet.y]; char temp2 = board[player.bullet.x-1][player.bullet.y+1]; switch(temp) { // all these will trigger the last case case 'S': case '@': case '%': case '&': case '#': case '/': case '\\': case '+': // most likely never reach here case '|': if(DEBUG == true) writeToFile("Collision with [%c]\n", temp); if(temp == ALIEN1) { player.score += 10; numberOfAliens--; } else if(temp == ALIEN2) { player.score += 20; numberOfAliens--; } else if(temp == ALIEN3) { player.score += 40; numberOfAliens--; } else if(temp == BOSS) { player.score += 150; } temp = ' '; temp2 = ' '; player.bullet.enabled = false; break; case '-': if(DEBUG == true) writeToFile("Bullet hits wall\n"); player.bullet.enabled = false; board[player.bullet.x][player.bullet.y] = ' '; break; default: // spaces and whatnot if(DEBUG == true) writeToFile("%i,%i = %c\n%i,%i\n",player.bullet.x,player.bullet.y-1,board[player.bullet.x][player.bullet.y],player.bullet.x,player.bullet.y); board[player.bullet.x-1][player.bullet.y] = BULLET; board[player.bullet.x][player.bullet.y] = ' '; player.bullet.x = player.bullet.x-1; break; } timer = clock(); } } } for(int x = 1;x<5;x++) { timerCheck = clock()-timer; if(timerCheck > 50) { char temp = ' '; switch(x) { case 1: temp = board[alienGroup.alienBullet1.x+1][alienGroup.alienBullet1.y]; if(alienGroup.alienBullet1.enabled == true) { switch(temp) { case '/': case '\\': case '#': temp = ' '; alienGroup.alienBullet1.enabled = false; board[alienGroup.alienBullet1.x][alienGroup.alienBullet1.y] = ' '; alienGroup.missles--; break; case 'A': player.lives--; board[player.x][player.y]= ' '; player.x = 14; player.y = parent_y - (score_size + 3); board[player.x][player.y] = PLAYER; alienGroup.missles--; break; case '-': if(DEBUG == true) writeToFile("Bullet hits wall\n"); alienGroup.alienBullet1.enabled = false; board[alienGroup.alienBullet1.x][alienGroup.alienBullet1.y] = ' '; alienGroup.missles--; break; default: if(DEBUG == true) writeToFile("%i,%i = %c\n%i,%i\n",player.bullet.x,player.bullet.y-1,board[player.bullet.x][player.bullet.y],player.bullet.x,player.bullet.y); board[alienGroup.alienBullet1.x+1][alienGroup.alienBullet1.y] = ALIENBULLET; board[alienGroup.alienBullet1.x][alienGroup.alienBullet1.y] = ' '; alienGroup.alienBullet1.x = alienGroup.alienBullet1.x+1; break; } /* if(temp == PLAYER) { player.lives--; player.x = 14; player.y = parent_y - (score_size + 3); board[player.x][player.y] = PLAYER; alienGroup.alienBullet1.enabled = false; alienGroup.missles--; } else if(temp == BARRIERCORNER1 || temp == BARRIERCORNER2 || temp == BARRIERMAIN) { temp = ' '; alienGroup.alienBullet1.enabled = false; alienGroup.missles--; } else if(temp == '-') { alienGroup.alienBullet1.enabled = false; alienGroup.missles--; } else { temp = BULLET; board[alienGroup.alienBullet1.x][alienGroup.alienBullet1.y] = ' '; alienGroup.alienBullet1.y += 1; }*/ } // case 2: // case 3: // case 4: default: break; } } } if(keyHit()) { key = getch(); keyChecker = keyCheck(key); if(keyChecker == true) break; // have code in CP } // refresh each window wrefresh(field); wrefresh(score); if(numberOfAliens == 0) break; } endwin(); // */ return true; }
void Brainview::draw() { column = 0; row = 0; if ( critterselection->selectedCritter == 0 ) { active = false; currentCritter = 0; } if (active) { if ( critterselection->selectedCritter != currentCritter ) { currentCritter = critterselection->selectedCritter; sensors.clear(); int sverticalpos = 0; int constraintcount = 0; for ( unsigned int i=0; i < currentCritter->brain.numberOfInputs; i++ ) { if ( currentCritter->brain.Inputs[i].id == 10000 ) { sensor s; s.sPointer = ¤tCritter->brain.Inputs[i]; s.position = Vector2f(brainview->position.x, 10); sensors.push_back(s); } else if ( currentCritter->brain.Inputs[i].id == 10001 ) { sverticalpos = 2; sensor s; s.sPointer = ¤tCritter->brain.Inputs[i]; s.position = Vector2f(brainview->position.x, 10+(spacing+v_diam)*sverticalpos); sensors.push_back(s); } else if ( currentCritter->brain.Inputs[i].id == 20000 ) { sverticalpos = 4; sensor s; s.sPointer = ¤tCritter->brain.Inputs[i]; s.position = Vector2f(brainview->position.x, 10+(spacing+v_diam)*sverticalpos); sensors.push_back(s); } else if ( currentCritter->brain.Inputs[i].id >= 30000 && currentCritter->brain.Inputs[i].id < 40000 ) { sverticalpos = 6; sensor s; s.sPointer = ¤tCritter->brain.Inputs[i]; s.position = Vector2f(brainview->position.x, 10+(spacing+v_diam)*sverticalpos +((spacing+v_diam)*(currentCritter->brain.Inputs[i].id-30000))); sensors.push_back(s); } else if ( currentCritter->brain.Inputs[i].id >= 40000 && currentCritter->brain.Inputs[i].id < 50000 ) { sverticalpos = 17; sensor s; s.sPointer = ¤tCritter->brain.Inputs[i]; s.position = Vector2f(brainview->position.x, 10+(spacing+v_diam)*sverticalpos +((spacing+v_diam)*(currentCritter->brain.Inputs[i].id-40000))); sensors.push_back(s); } else if ( currentCritter->brain.Inputs[i].id < 10000 ) { sverticalpos = 28; sensor s; s.sPointer = ¤tCritter->brain.Inputs[i]; s.position = Vector2f(brainview->position.x, 10+(spacing+v_diam)*sverticalpos +((spacing+v_diam)*(constraintcount))); sensors.push_back(s); constraintcount++; } else if ( currentCritter->brain.Inputs[i].id >= 50000 && currentCritter->brain.Inputs[i].id < 60000 ) { int vinput = currentCritter->brain.Inputs[i].id-50000; int vcolmax = currentCritter->genotype->bodyArch->retinasize * 4; int row = vinput / vcolmax; int col = vinput - (row * vcolmax); row = currentCritter->genotype->bodyArch->retinasize - row - 1; sensor s; s.sPointer = ¤tCritter->brain.Inputs[i]; s.position = Vector2f(brainview->position.x+((spacing+v_diam)*col)+10, 10+((spacing+v_diam)*row)); sensors.push_back(s); } else { cerr << "critterview: inputs don't add up" << endl; exit(0); } } // for ( unsigned int i=0; i < currentCritter->brain.numberOfInputs; i++ ) // { // sensor s; // s.sPointer = ¤tCritter->brain.Inputs[i]; // int woffset, hoffset; // if ( s.sPointer->id == 10000 ) // woffset = 100; hoffset = 50; // else // { // // woffset = v_radius+((spacing+v_diam)*column); // // hoffset = v_radius+((spacing+v_diam)*row); // woffset = 20; hoffset = 20; // } // s.position = Vector2f(woffset, hoffset); // sensors.push_back(s); // // if ( ++column == rowlength ) { column = 0; row++; } // } row = (currentCritter->brain.numberOfInputs/rowlength) + 1; neurons.clear(); for ( unsigned int i=0; i < currentCritter->brain.totalNeurons; i++ ) { neuron n; n.nPointer = ¤tCritter->brain.Neurons[i]; int woffset = v_radius+((spacing+v_diam)*column); int hoffset = 30+v_radius+((spacing+v_diam)*row*3); n.position = Vector2f(woffset, hoffset); neurons.push_back(n); if ( ++column == rowlength ) { column = 0; row++; } } } drawBackground(); drawBorders(); // draw the rest drawChildren(); // drift // neuron vs neuron unsigned int i, j, k, nrlinks; float xD, yD, dist, oneoverdistance, oneoverdistancesquared; ArchSynapse* as; // reset newpositions for ( i=0; i < neurons.size(); i++ ) { neurons[i].newposition.x = 0; neurons[i].newposition.y = 0; } // #pragma omp parallel for private(i, j, k, nrlinks, xD, yD, dist, oneoverdistancesquared, as) for ( i=0; i < neurons.size()-1; i++ ) for ( j=i+1; j < neurons.size(); j++ ) { // how many connections do they have underling nrlinks = 0; for ( k=0; k < currentCritter->genotype->brainzArch->ArchNeurons[i].ArchSynapses.size(); k++ ) { as = ¤tCritter->genotype->brainzArch->ArchNeurons[i].ArchSynapses[k]; if ( !as->isSensorNeuron && as->neuronID == j ) nrlinks++; } for ( k=0; k < currentCritter->genotype->brainzArch->ArchNeurons[j].ArchSynapses.size(); k++ ) { as = ¤tCritter->genotype->brainzArch->ArchNeurons[j].ArchSynapses[k]; if ( !as->isSensorNeuron && as->neuronID == i ) nrlinks++; } xD=neurons[j].position.x - neurons[i].position.x; yD=neurons[j].position.y - neurons[i].position.y; dist = sqrt((xD*xD)+(yD*yD)); oneoverdistance = 1.0f/dist; oneoverdistancesquared = oneoverdistance * oneoverdistance; // if ( oneoverdistancesquared < 0.00001f ) // oneoverdistancesquared = 0.00001f; if ( oneoverdistancesquared > 0.001f ) oneoverdistancesquared = 0.001f; if ( nrlinks > 0 ) { neurons[i].newposition.x += xD * oneoverdistancesquared * *attractor1 * nrlinks / 10.0f; neurons[i].newposition.y += yD * oneoverdistancesquared * *attractor1 * nrlinks / 10.0f; neurons[j].newposition.x -= xD * oneoverdistancesquared * *attractor1 * nrlinks / 10.0f; neurons[j].newposition.y -= yD * oneoverdistancesquared * *attractor1 * nrlinks / 10.0f; } // general antigravity neurons[i].newposition.x -= xD * oneoverdistancesquared * oneoverdistancesquared * *attractor3 * 100; neurons[i].newposition.y -= yD * oneoverdistancesquared * oneoverdistancesquared * *attractor3 * 100; neurons[j].newposition.x += xD * oneoverdistancesquared * oneoverdistancesquared * *attractor3 * 100; neurons[j].newposition.y += yD * oneoverdistancesquared * oneoverdistancesquared * *attractor3 * 100; } // neuron vs sensor for ( unsigned int i=0; i < neurons.size(); i++ ) for ( unsigned int j=0; j < sensors.size(); j++ ) { // how many connections do they have underling unsigned int nrlinks = 0; for ( unsigned int k=0; k < currentCritter->genotype->brainzArch->ArchNeurons[i].ArchSynapses.size(); k++ ) { ArchSynapse* as = ¤tCritter->genotype->brainzArch->ArchNeurons[i].ArchSynapses[k]; if ( as->isSensorNeuron && as->realneuronID == j ) nrlinks++; } xD=sensors[j].position.x - neurons[i].position.x; yD=sensors[j].position.y - neurons[i].position.y; dist = sqrt((xD*xD)+(yD*yD)); oneoverdistancesquared = 1.0f/(dist*dist*dist); /* if ( oneoverdistancesquared > 1.0f ) oneoverdistancesquared = 1.0f;*/ if ( oneoverdistancesquared > 0.001f ) oneoverdistancesquared = 0.001f; if ( nrlinks > 0 ) { neurons[i].newposition.x += xD * oneoverdistancesquared * *attractor2 * nrlinks * 10.0f; neurons[i].newposition.y += yD * oneoverdistancesquared * *attractor2 * nrlinks * 10.0f; } // general antigravity neurons[i].newposition.x -= xD * oneoverdistancesquared * oneoverdistancesquared * *attractor4 * 100000; neurons[i].newposition.y -= yD * oneoverdistancesquared * oneoverdistancesquared * *attractor4 * 100000; } // apply newpositions & check boundaries for ( i=0; i < neurons.size(); i++ ) { neurons[i].position.x += neurons[i].newposition.x; neurons[i].position.y += neurons[i].newposition.y; float miny = (v_radius*2)+((spacing+v_diam) * ((sensors.size()/rowlength)+1) ); float leftborder = 20.0f; if ( neurons[i].position.x+v_radius > *brainview->v_widthP ) neurons[i].position.x = *brainview->v_widthP-v_radius; if ( neurons[i].position.x < v_radius+leftborder ) neurons[i].position.x = v_radius+leftborder; if ( neurons[i].position.y+v_radius > *brainview->v_heightP ) neurons[i].position.y = *brainview->v_heightP-v_radius; if ( neurons[i].position.y < miny ) neurons[i].position.y = miny; } // draw brain // connections glBegin(GL_LINES); float dimmed = 0.20f; // glColor4f(1.0f, 1.0f, 1.0f, 1.0f); for ( unsigned int i=0; i < neurons.size(); i++ ) { // if ( neurons[i].nPointer->output ) // { // if ( neurons[i].nPointer->isMotor ) // glColor4f(0.0f, 0.0f, 0.5f, 1.0f); // else if ( neurons[i].nPointer->isInhibitory ) // glColor4f(0.5f, 0.0f, 0.0f, 1.0f); // else // glColor4f(0.0f, 0.5f, 0.0f, 1.0f); // } // else // { // if ( neurons[i].nPointer->isMotor ) // glColor4f(0.0f, 0.0f, dimmed, 1.0f); // else if ( neurons[i].nPointer->isInhibitory ) // glColor4f(dimmed, 0.0f, 0.0f, 1.0f); // else // glColor4f(0.0f, dimmed, 0.0f, 1.0f); // } for ( unsigned int j=0; j < currentCritter->genotype->brainzArch->ArchNeurons[i].ArchSynapses.size(); j++ ) { ArchSynapse* as = ¤tCritter->genotype->brainzArch->ArchNeurons[i].ArchSynapses[j]; if ( !as->isSensorNeuron && currentCritter->brain.Neurons[as->neuronID].output || as->isSensorNeuron && currentCritter->brain.Inputs[as->realneuronID].output ) { if ( as->isSensorNeuron ) glColor4f(0.0f, dimmed, 0.0f, 1.0f); else if ( !neurons[as->neuronID].nPointer->isInhibitory ) glColor4f(0.0f, dimmed, 0.0f, 1.0f); else glColor4f(dimmed, 0.0f, 0.0f, 1.0f); glVertex2f(neurons[i].position.x+brainview->absPosition.x, neurons[i].position.y+brainview->absPosition.y); if ( as->isSensorNeuron ) { glVertex2f(brainview->absPosition.x+sensors[as->realneuronID].position.x, brainview->absPosition.y+sensors[as->realneuronID].position.y); } else { glVertex2f(brainview->absPosition.x+neurons[as->neuronID].position.x, brainview->absPosition.y+neurons[as->neuronID].position.y); } } } // } } glEnd(); glBegin(GL_QUADS); // inputs for ( unsigned int i=0; i < sensors.size(); i++ ) { if ( sensors[i].sPointer->output ) glColor4f(0.0f, 1.0f, 0.0f, 1.0f); else glColor4f(0.0f, dimmed, 0.0f, 1.0f); // glScaled(sensors[i].sPointer->output, sensors[i].sPointer->output, sensors[i].sPointer->output); // cerr << sensors[i].sPointer->output << endl; // float nv_radius = sensors[i].sPointer->output * v_radius; float nv_radius = v_radius; glVertex2f(sensors[i].position.x+brainview->absPosition.x-nv_radius, sensors[i].position.y+brainview->absPosition.y+nv_radius); glVertex2f(sensors[i].position.x+brainview->absPosition.x-nv_radius, sensors[i].position.y+brainview->absPosition.y-nv_radius); glVertex2f(sensors[i].position.x+brainview->absPosition.x+nv_radius, sensors[i].position.y+brainview->absPosition.y-nv_radius); glVertex2f(sensors[i].position.x+brainview->absPosition.x+nv_radius, sensors[i].position.y+brainview->absPosition.y+nv_radius); } // neurons for ( unsigned int i=0; i < neurons.size(); i++ ) { // if ( neurons[i].nPointer->output ) // { if ( neurons[i].nPointer->isMotor ) glColor4f(0.3f, 0.3f, 1.0f, 1.0f); else if ( neurons[i].nPointer->isInhibitory ) glColor4f(1.0f, 0.0f, 0.0f, 1.0f); else glColor4f(0.0f, 1.0f, 0.0f, 1.0f); float nv_radius = abs(neurons[i].nPointer->potential * (v_diam / *brain_maxfiringthreshold)); // show minimum if ( nv_radius < 0.5f ) nv_radius = 0.5f; glVertex2f(neurons[i].position.x+brainview->absPosition.x-nv_radius, neurons[i].position.y+brainview->absPosition.y+nv_radius); glVertex2f(neurons[i].position.x+brainview->absPosition.x-nv_radius, neurons[i].position.y+brainview->absPosition.y-nv_radius); glVertex2f(neurons[i].position.x+brainview->absPosition.x+nv_radius, neurons[i].position.y+brainview->absPosition.y-nv_radius); glVertex2f(neurons[i].position.x+brainview->absPosition.x+nv_radius, neurons[i].position.y+brainview->absPosition.y+nv_radius); } glEnd(); } }
void Infostats::draw() { if (active) { // updateAbsPosition(); drawBackground(); drawBorders(); unsigned int colWidth = (position.x+v_width-position.x) / 4; unsigned int col1 = position.x + colWidth; unsigned int col2 = col1 + colWidth; unsigned int col3 = col2 + colWidth; unsigned int col4 = col3 + colWidth; float linespacer = 0.0f; glColor3f(0.7f, 0.7f, 0.7f); glBegin(GL_LINES); glVertex2f(col2, position.y + linespacer); glVertex2f(col2, (position.y+v_height) - linespacer); glEnd(); glColor3f(1.0f, 1.0f, 1.0f); // glEnable(GL_TEXTURE_2D); // row counter unsigned int rc=1; // statsSnapshot* ss = &statsBuffer->snapshots[statsBuffer->snapshots.size()-1]; // HEADING // COLUMN 1 Textprinter::Instance()->print(position.x+hsp, position.y+vsp*rc, "brain"); rc++; Textprinter::Instance()->print(position.x+hsp, position.y+vsp*rc, "avg neurons:"); if ( statsBuffer->current.critters > 0 ) Textprinter::Instance()->printR(col2-hsp, position.y+vsp*rc, "%1.2f", (float)statsBuffer->current.neurons / statsBuffer->current.critters); else Textprinter::Instance()->printR(col2-hsp, position.y+vsp*rc, "%1.2f", 0.0f); rc++; Textprinter::Instance()->print(position.x+hsp, position.y+vsp*rc, "avg synapses:"); if ( statsBuffer->current.critters > 0 ) Textprinter::Instance()->printR(col2-hsp, position.y+vsp*rc, "%1.2f", (float)statsBuffer->current.synapses / statsBuffer->current.critters); else Textprinter::Instance()->printR(col2-hsp, position.y+vsp*rc, "%1.2f", 0.0f); rc++; Textprinter::Instance()->print(position.x+hsp, position.y+vsp*rc, "avg synapses/neuron:"); if ( statsBuffer->current.neurons > 0 ) Textprinter::Instance()->printR(col2-hsp, position.y+vsp*rc, "%1.2f", (float)statsBuffer->current.synapses / statsBuffer->current.neurons); else Textprinter::Instance()->printR(col2-hsp, position.y+vsp*rc, "%1.2f", 0.0f); rc++; Textprinter::Instance()->print(position.x+hsp, position.y+vsp*rc, "avg adam distance:"); if ( statsBuffer->current.critters > 0 ) Textprinter::Instance()->printR(col2-hsp, position.y+vsp*rc, "%1.2f", (float)statsBuffer->current.adamdistance / statsBuffer->current.critters); else Textprinter::Instance()->printR(col2-hsp, position.y+vsp*rc, "%1.2f", 0.0f); // COLUMN 2 rc = 1; Textprinter::Instance()->print(col2+hsp, position.y+vsp*rc, "body"); rc++; Textprinter::Instance()->print(col2+hsp, position.y+vsp*rc, "avg body parts:"); if ( statsBuffer->current.critters > 0 ) Textprinter::Instance()->printR(col4-hsp, position.y+vsp*rc, "%1.2f", (float)statsBuffer->current.bodyparts / statsBuffer->current.critters); else Textprinter::Instance()->printR(col4-hsp, position.y+vsp*rc, "%1.2f", 0.0f); rc++; Textprinter::Instance()->print(col2+hsp, position.y+vsp*rc, "avg weight:"); if ( statsBuffer->current.critters > 0 ) Textprinter::Instance()->printR(col4-hsp, position.y+vsp*rc, "%1.2f", (float)statsBuffer->current.weight / statsBuffer->current.critters); else Textprinter::Instance()->printR(col4-hsp, position.y+vsp*rc, "%1.2f", 0.0f); // glDisable(GL_TEXTURE_2D); } }
int main (int argc, char *argv[]) { srand ( time(NULL) ); sound.LoadSound("blockHit","hit.wav"); sound.LoadSound("horizontal","horizon2.wav"); sound.LoadSound("rotate","rotate.wav"); loadHighscore(&hscore); resetGame(); while (keyboard.Quit == false) { if(keyboard.r){ keyboard.Clear(); resetGame(); } if(keyboard.p){ SDL_Delay(100); keyboard.Poll(); keyboard.Clear(); while(!keyboard.p){ keyboard.Poll(); display.Clear(); drawBorders(); sprintf(TEXT,"Game is paused."); display.DrawString(TEXT, 0, (HEIGHT/2)*BLOCKPIXSIZE,0,0x00FF00); display.Render(); SDL_Delay(50); } } int speed = 0; speed = score/2400; if(speed > 40){speed = 40;} if(!(cycle% (60-speed)) || keyboard.Down){fallBlock(); HorizontalStrip(); if(keyboard.Down)keyboard.Clear(); } keyboard.Poll(); if(keyboard.Left && InvasiveCheckPass(blockx-1,blocky,blockt,blockr)){ --blockx; keyboard.Clear();} if(keyboard.Right && InvasiveCheckPass(blockx+1,blocky,blockt,blockr)){++blockx; keyboard.Clear();} if(keyboard.Up && InvasiveCheckPass(blockx,blocky,blockt,blockr+1)){ blockr = (++blockr > 3) ? 0 : blockr; updateBlockBoundaries(); sound.PlaySound("rotate",80,0); keyboard.Clear(); } if(keyboard.Space){ while(InvasiveCheckPass(blockx,blocky+1,blockt,blockr)){fallBlock(); HorizontalStrip();} gridLockBlock(); keyboard.Clear(); SDL_Delay(80); } blockx = (blockx< -minxcord) ? -minxcord : ((blockx > (WIDTH-1)-maxxcord) ? (WIDTH-1)-maxxcord : blockx); render(); char TXT[128]; if(speed > 30){sprintf(TXT,"EXTREME PENTRIX: %i",hscore);} else{sprintf(TXT,"Pentrix Highscore: %i",hscore);} display.Caption(TXT); SDL_Delay (4); cycle = (++cycle > 239) ? 1 : cycle; } return 0; }
void Slider::draw(sf::RenderTarget& target, sf::RenderStates states) const { states.transform.translate(getPosition()); // Draw the borders around the track if (m_bordersCached != Borders{0}) { if (m_mouseHover && m_borderColorHoverCached.isSet()) drawBorders(target, states, m_bordersCached, getSize(), m_borderColorHoverCached); else drawBorders(target, states, m_bordersCached, getSize(), m_borderColorCached); states.transform.translate({m_bordersCached.getLeft(), m_bordersCached.getTop()}); } // Draw the track if (m_spriteTrack.isSet() && m_spriteThumb.isSet()) { if (m_mouseHover && m_spriteTrackHover.isSet()) m_spriteTrackHover.draw(target, states); else m_spriteTrack.draw(target, states); } else // There are no textures { if (m_mouseHover && m_trackColorHoverCached.isSet()) drawRectangleShape(target, states, getInnerSize(), m_trackColorHoverCached); else drawRectangleShape(target, states, getInnerSize(), m_trackColorCached); } states.transform.translate({-m_bordersCached.getLeft() + m_thumb.left, -m_bordersCached.getTop() + m_thumb.top}); // Draw the borders around the thumb if (m_bordersCached != Borders{0}) { if (m_mouseHover && m_borderColorHoverCached.isSet()) drawBorders(target, states, m_bordersCached, {m_thumb.width, m_thumb.height}, m_borderColorHoverCached); else drawBorders(target, states, m_bordersCached, {m_thumb.width, m_thumb.height}, m_borderColorCached); states.transform.translate({m_bordersCached.getLeft(), m_bordersCached.getTop()}); } // Draw the thumb if (m_spriteTrack.isSet() && m_spriteThumb.isSet()) { if (m_mouseHover && m_spriteThumbHover.isSet()) m_spriteThumbHover.draw(target, states); else m_spriteThumb.draw(target, states); } else // There are no textures { const sf::Vector2f thumbInnerSize = {m_thumb.width - m_bordersCached.getLeft() - m_bordersCached.getRight(), m_thumb.height - m_bordersCached.getTop() - m_bordersCached.getBottom()}; if (m_mouseHover && m_thumbColorHoverCached.isSet()) drawRectangleShape(target, states, thumbInnerSize, m_thumbColorHoverCached); else drawRectangleShape(target, states, thumbInnerSize, m_thumbColorCached); } }