void GraphNode::calcBonded() { std::vector<Bond *>::iterator it; float bondLength; bonded.x = 0.f; bonded.y = 0.f; for(it = bonds.begin(); it != bonds.end(); it++) { bondLength = pow(getx() - (*it)->getPartnerX(), 2) + pow(gety() - (*it)->getPartnerY(), 2); if (bondLength > params->bondLength()) { bonded.x += 1 * (*it)->strength() * 10000 * (getx() - (*it)->getPartnerX()) / (bondLength - params->bondLength()); bonded.y += 1 * (*it)->strength() * 10000 * (gety() - (*it)->getPartnerY()) / (bondLength - params->bondLength()); } else if (bondLength < params->bondLength()) { bonded.x += -1 * (*it)->strength() * 10000 * (getx() - (*it)->getPartnerX()) / (bondLength - params->bondLength()); bonded.y += -1 * (*it)->strength() * 10000 * (gety() - (*it)->getPartnerY()) / (bondLength - params->bondLength()); } } }
/* * get the min/max fields of a set with fixed x/y range */ int getsetminmax_c(Quark **sets, int nsets, double *xmin, double *xmax, double *ymin, double *ymax, int ivec) { double vmin_t, vmax_t, *vmin, *vmax, bvmin, bvmax, *vec, *bvec; int i, n; int first = TRUE, hits; if (nsets < 1 || !sets) { return RETURN_FAILURE; } if (ivec == 1) { bvmin = *xmin; bvmax = *xmax; vmin = ymin; vmax = ymax; } else { bvmin = *ymin; bvmax = *ymax; vmin = xmin; vmax = xmax; } for (i = 0; i < nsets; i++) { Quark *pset = sets[i]; if (set_is_drawable(pset)) { if (ivec == 1) { bvec = getx(pset); vec = gety(pset); } else { bvec = gety(pset); vec = getx(pset); } n = set_get_length(pset); hits = minmaxrange(bvec, vec, n, bvmin, bvmax, &vmin_t, &vmax_t); if (hits == RETURN_SUCCESS) { if (first) { *vmin = vmin_t; *vmax = vmax_t; first = FALSE; } else { *vmin = MIN2(vmin_t, *vmin); *vmax = MAX2(vmax_t, *vmax); } } } } if (first == FALSE) { return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
void SeaActor::renderSea(int xMin, int xMax, int zMin, int zMax, int inc, bool trick) { int s = 900; int vel = 7; int zstart = sc->time / vel + zMin; //6 quad/s int zend= sc->time / vel + zMax; //6 quad/s int ofs = sc->time * s / vel; int r = 80; int b = 240; for(int z = zstart; z < zend; z+=inc) { glBegin(GL_QUAD_STRIP); int old1 = gety(xMin, z); int old2 = gety(xMin, z+inc); int oldc1 = getc(xMin, z); int oldc2 = getc(xMin, z+inc); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64*inc), inttot16(0)); glColor3b(r, oldc1, b); glVertex3v16((xMin+0)*s, old1, -(z+0)*s+ofs); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64*inc), inttot16(64*inc)); glColor3b(r, oldc2, b); glVertex3v16((xMin+0)*s, old2, -(z+inc)*s+ofs); bool tex = false; for(int x = xMin; x < xMax; x+=inc) { int new1 = gety(x+inc, z); int new2; if(trick && z == zend-1 && (x/inc)%2 == 0) new2 = (old2+gety(x+inc*2, z+inc))/2; else new2 = gety(x+inc, z+inc); int newc1 = getc(x+inc, z); int newc2 = getc(x+inc, z+inc); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64*tex*inc), inttot16(0)); glColor3b(r, newc1, b); glVertex3v16((x+inc)*s, new1, -(z+0)*s+ofs); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64*tex*inc), inttot16(64*inc)); glColor3b(r, newc2, b); glVertex3v16((x+inc)*s, new2, -(z+inc)*s+ofs); tex = !tex; old1 = new1; old2 = new2; oldc1 = newc1; oldc2 = newc2; } glEnd(); } }
static void searching_ball(Info * info) { info->sched_var.count ++; //mylogfd(SCHFD, "count = %d\n", info->sched_var.count); if (IsDoorSeen(info)) { if (getDoorMidx(info) != 0 && getDoorMidx(info) < info->sched_var.door_dis) { info->sched_var.door_dis = getDoorMidx(info); info->sched_var.door_count = info->sched_var.count; } } if (getGreenSum(info) > info->sched_var.max_green_sum) { info->sched_var.max_green_sum = getGreenSum(info); info->sched_var.max_green_count = info->sched_var.count; } if (IsBallSeen(info)) { mylogfd(SCHFD, "[sche]search_ball->forwarding_ball\n"); info->last_cmd = CMD_FORWARD; info->state = FORWARDING_BALL; mylogfd(SCHFD,"[sche]left %d %d %d %d, right %d %d %d %d\n", info->video_info->is_ball_seen, info->video_info->is_ball_acc, info->video_info->ball_acc_pos.x, info->video_info->ball_acc_pos.y, info->video_info2->is_ball_seen, info->video_info2->is_ball_acc, info->video_info2->ball_acc_pos.x, info->video_info2->ball_acc_pos.y); info->destP.x = gety(info); info->destP.y = - getx(info); if (!info->video_info->is_ball_acc && !info->video_info2->is_ball_acc) { info->destP.x = 100; info->destP.y = 0; } do_forward(info, DEFAULT_A); return; } if (info->sched_var.count >= 90 || checkDone()) { mylogfd(SCHFD, "[sche]searching_ball->change_place checkdone\n"); info->state = CHANGE_PLACE; do_search_ball(info, info->sched_var.search_dir); return; } }
void Shape::d_markAnchorTilt() { if(!pixdebug) return; int x1 = getmaxx(); int y1 = gety(x1); // tilt check with maxx pixel offset to the center pixel using y int y2 = (y1 > getcy()) ? getminy() : getmaxy(); int x2 = getx(y2); int o = x1 - x2; int a = ( y1 > y2 ) ? y1 - y2 : y2 - y1; // threshold check and return if within int threshold = (o > a) ? o/10 : a/10; if (threshold <= 0) threshold = 5; if (abs(o - a) < threshold) return; if( o > 0 && a > 0 ) { if( y2 > y1 ) d_pixmap->setPen(0, 255, 255); else d_pixmap->setPen(255, 0, 255); d_pixmap->markHLine( x1, x2, y1); d_pixmap->markHLine( x1, x2, y1+1); d_pixmap->markHLine( x1, x2, y1-1); d_pixmap->markVLine( y1, y2, x1); d_pixmap->markVLine( y1, y2, x1+1); d_pixmap->markVLine( y1, y2, x1-1); } }
int CVideo::set_help_string(const std::string& str) { font::remove_floating_label(help_string_); const SDL_Color color = { 0, 0, 0, 0xbb }; int size = font::SIZE_LARGE; while(size > 0) { if(font::line_width(str, size) > getx()) { size--; } else { break; } } const int border = 5; font::floating_label flabel(str); flabel.set_font_size(size); flabel.set_position(getx()/2, gety()); flabel.set_bg_color(color); flabel.set_border_size(border); help_string_ = font::add_floating_label(flabel); const SDL_Rect& rect = font::get_floating_label_rect(help_string_); font::move_floating_label(help_string_,0.0,-double(rect.h)); return help_string_; }
int gg() { findfirst("*.*",&f,0x3f); gprintf("%s",f.ff_name); moveto(wi[status.active_window].x1+5,gety()+10); return(0); }
void SpriteEx::draw(const GraphicsContext &gc) { int color; switch (spriteType) { case ST_PLAYER: color = YELLOW; break; case ST_ENEMY: color = GREEN; break; case ST_BULLET: color = GREY; break; case ST_ENEMY_BULLET: color = RED; break; default: color = BLACK; break; } int x = getx() + gc.xofst; x -= parent->getViewPort()->getx(); int y = gety() + gc.yofst; y -= parent->getViewPort()->gety(); int time = parent->getParent()->getCounter(); if (anim != NULL) { anim->drawFrame (gc.buffer, state, dir, time, x, y); } else { rectfill (gc.buffer, x, y, x + w, y + h, color); } #ifdef DEBUG if (parent->getParent()->isDebug()) { rect (gc.buffer, x, y, x + w, y + h, color); alfont_textprintf_ex(gc.buffer, parent->smallfont, x, y - 16, GREEN, -1, "hp: %i", hp); } #endif }
void draw_real_part(int begin, int end) { complex comp; comp.real = 0, comp.image = 0; double round_x, round_el_array; int i = 0; setcolor(YELLOW); moveto(width / 2, height / 2); int x_0 = getx(); int y_0 = gety(); for(double x = begin; x <= end; x += 0.1) { comp = trigonometric_interpolation(x); double coord_x = x_0 + x * 60; double coord_y = y_0 + comp.real * 20; double invert_y = (coord_y - y_0) * 2; round_x = round(x * 1000000) / 1000000; round_el_array = round(array_values[i][0] * 10000000) / 10000000; if (round_x == round_el_array) { setcolor(RED); setfillstyle(1, RED); circle(coord_x, coord_y - invert_y, 7); floodfill(coord_x, coord_y - invert_y, RED); setcolor(YELLOW); i++; if (i == n) i = 0; } if (x == begin) moveto(coord_x, coord_y - invert_y); lineto(coord_x, coord_y - invert_y); } }
void Waypoint::sety ( double yIn ) { // update position Ped::Twaypoint::sety ( yIn ); // inform user emit positionChanged ( getx(), gety() ); }
void Player::die() { // create a timer parent->setTimer(50, Game::MSG_PLAYER_DIED); Explosion *e = new Explosion(parent, getx(), gety(), 100); parent->add (e); kill(); // kill this sprite }
int main(void) { //Initialize variables float x[] = {2,5,3}, weight[W], nextw[W], y, epsilon = 0.02, error = 999, thresh_hold = 0.01, bias = 0, deltaw, output; int size = sizeof(float) * N, correct = 0, i, z, j; j=z=0; //Set weights for all weight variables to 50 for (i = 0; i < W; i++) { weight[i] = 50; } while(error > thresh_hold) { output = gety(bias,x,weight,W); //printing expected and acutal values printf("Expected Value: %f\n", desired); printf("Actual value: %f\n\n", output); error = desired - output; //Adjusting weights //As there are only two weights, a loop isn't required. for (i = 0; i < W; i++) { deltaw = epsilon*x[i]*error; nextw[i] = weight[i] + deltaw; weight[i] = nextw[i]; } for (i = 0; i < W; i++) { printf("Weight %d = %f\n", i, weight[i]); } z++; if(z==9) { z=j=0; } } }
A::~A() { int i; for (i=0; i < 5; i++) delete datos [i]; delete cadena; settextstyle (0,0,1); outtext ("Destruyendo"); moveto (0,gety() + 10); }
void wp_boomerang_proj::returnTick() { if (!owner->isDisabled() && owner->hasBoomerang() && weapon != NULL) { returnx = owner->getx(); returny = owner->gety(); } else { //player has died, so just fly away inconspicuously returnx = (vx > 0 ? 306 : -50); //basically move it off the screen is the point here returny = gety(); } s32 myx = getx(); s32 myy = gety(); s32 dist = (s32)sqrt((myx-returnx)*(myx-returnx)+(myy-returny)*(myy-returny)); setRawSpeed(getRawvx()-((myx-returnx)/(dist/RETURNSTR)), getRawvy()-((myy-returny)/(dist/RETURNSTR))); }
int gettty(void) { int rc; if (rc = gety()) return(rc); if (linebuf[0]=='.' && linebuf[1]==0) return(EOF); return(0); }
static void search_ball(Info * info) { //info->destP.x = gety(info); //info->destP.y = getx(info)+50; //do_forward(info,DEFAULT_A); /*if (is_start == 0 && POSITI !=0) { run_rota(45,POSITI); run_forward(50,200); //run_rotaR(25); //run_forward(40,200); is_start = 1; }*/ //--- by hanlei if (IsBallCatch(info)) { info->state = BALL_CATCHED; info->sched_var.waitlost = 3; info->sched_var.doorseen = 0; mylogfd(SCHFD, "[sche]State changing:SEARCH_BALL->ball_catched\n"); if (!IsDoorSeen(info)) do_rota_with_ball(info, POSITI*360, 1); return; } if (IsMiddle(info)) { if (info->sched_var.waitforward -- == 0) { info->sched_var.waitforward = SCHED_waitforward_TIME; info->last_cmd = CMD_FORWARD; info->state = FORWARDING_BALL; info->destP.x = gety(info); info->destP.y = - getx(info); mylogfd(SCHFD, "[sche]SEARCH_BALL->forwarding_ball\n"); do_forward(info, DEFAULT_A); return; } } else { info->sched_var.count = 0; info->sched_var.door_count = 0; info->sched_var.door_dis = 10000; info->sched_var.max_green_sum = 0; info->sched_var.max_green_count = 0; if (IsBallAllSeen(info)) info->sched_var.wait = 0; else if (IsBallSeen(info)) info->sched_var.wait = 1; else info->sched_var.wait = 3; int dir ; if (START_FLAG == 0){ START_FLAG = 1; dir = POSITI; } dir = info->sched_var.search_dir; // search_ball -- redwalker if (IsBallSeen(info) && IsRight(info)) dir = -1; if (IsBallSeen(info) && IsLeft(info)) dir = 1; info->state = SEARCHING_BALL; mylogfd(SCHFD, "[sche]SEARCH_BALL->search_ball\n"); info->last_cmd = CMD_SEARCH_BALL; info->sched_var.search_dir = dir; do_search_ball(info, dir); } }
int main() { int Karta, Tryb; Karta = DETECT; initgraph(&Karta, &Tryb, "d:\\tc\\bgi\\"); setgraphmode(Tryb); moveto(90,50); spirala(getmaxx()/2,getx(),gety()); getch(); closegraph(); }
int gettty(void) { int rc; rc = gety(); if(rc) return rc; if(linebuf[0] == '.' && linebuf[1] == 0) return EOF; return 0; }
void ScoreText::draw(BITMAP *buffer, int xofst, int yofst) { int x = getx(); int y = gety(); draw_sprite (buffer, cache, x, y); if (x + cache->w > SCREEN_W) { draw_sprite (buffer, cache, x - SCREEN_W, y); } }
static void catching_ball(Info* info) { if (IsBallCatch(info)) { mylogfd(SCHFD, "[sche]State changing:catching_ball->ball_catched\n"); info->state = BALL_CATCHED; info->sched_var.doorseen = 0; info->sched_var.waitlost = 3; do_stop(info); if (!IsDoorSeen(info)) do_rota_with_ball(info, -POSITI*360, 1); // get in a paramiter -- redwalker } else if (!IsBallAllSeen(info)) { mylogfd(SCHFD, "[sche]catching_ball->SEARCH_BALL\n"); info->state = SEARCH_BALL; do_stop(info); } else if (!IsBallVeryNear(info)) { mylogfd(SCHFD, "[sche]catching_ball->forwarding_ball\n"); info->state = FORWARDING_BALL; info->destP.x = gety(info); info->destP.y = - getx(info); do_forward(info, DEFAULT_A); } else if (checkDone()) { mylogfd(SCHFD,"[sche]checkDone catching_ball \n"); info->last_cmd = CMD_CATCH_BALL; info->destP.x = gety(info); info->destP.y = - getx(info); do_catch_ball(info); } if (IsMiddle(info)) { do_adjust(-1); } if (IsLeft(info)) { do_adjust(1); } if (IsRight(info)) { do_adjust(0); } }
void Explosion::draw(const GraphicsContext &gc) { int x = getx() - parent->getViewPort()->getx(); int y = gety() - parent->getViewPort()->gety(); drawing_mode (DRAW_MODE_TRANS, NULL, 0, 0); set_trans_blender (0, 0, 0, 128); circlefill (gc.buffer, x, y, size, RED); circlefill (gc.buffer, x, y, size * 2 / 3, YELLOW); drawing_mode (DRAW_MODE_SOLID, NULL, 0, 0); }
int main() { int i, j; ll d, xm, ym; scanf("%d\n", &n); for(i = 0; i < n; i++) scanf("%lld %lld\n", &x[i], &y[i]); scanf("%lld\n", &d); minx = miny = -INF; maxx = maxy = INF; for(i = 0; i < n; i++) { minx = MAX(minx, xline(x[i] - d, y[i])); maxx = MIN(maxx, xline(x[i] + d, y[i])); miny = MAX(miny, yline(x[i], y[i] - d)); maxy = MIN(maxy, yline(x[i], y[i] + d)); } if(minx > maxx || miny > maxy) { printf("impossible\n"); return 0; } ans = INF; xm = median(x, n); ym = median(y, n); check(xm,ym); check(getx(minx,miny,true ),gety(minx,miny,true )); check(getx(minx,miny,true ),gety(minx,miny,false)); check(getx(minx,maxy,false),gety(minx,maxy,false)); check(getx(minx,maxy,true ),gety(minx,maxy,false)); check(getx(maxx,maxy,false),gety(maxx,maxy,true )); check(getx(maxx,maxy,false),gety(maxx,maxy,false)); check(getx(maxx,miny,true ),gety(maxx,miny,true )); check(getx(maxx,miny,false),gety(maxx,miny,true )); int border[4][3] = { {minx, 1, -minx}, {maxx, 1, -maxx}, {miny, -1, miny}, {maxy, -1, maxy} }; for(i = 0; i < 4; i++) { for(j = 0; j < n; j++) { pts[j*2] = x[j]; pts[j*2+1] = border[i][0] + border[i][1] * y[j]; } xm = median(pts, n * 2); ym = border[i][1] * xm + border[i][2]; check(xm,ym); } printf("%lld\n", ans); return 0; }
void draw() { for (float i = 0; i < sx; i++) { for (float j = 0; j < sy; j++) { glBegin(GL_QUADS); glNormal3f(getx((i+0.5)/sx,(j+0.5)/sy), gety((i+0.5)/sx, (j+0.5)/sy), getz((i+0.5)/sx,(j+0.5)/sy)); glVertex3f(getx(i/sx, j/sy), gety(i/sx, j/sy), getz(i/sx, j/sy)); glVertex3f(getx((i+1)/sx, j/sy), gety((i+1)/sx, j/sy), getz((i+1)/sx, j/sy)); glVertex3f(getx((i+1)/sx, (j+1)/sy), gety((i+1)/sx, (j+1)/sy), getz((i+1)/sx, (j+1)/sy)); glVertex3f(getx(i/sx, (j+1)/sy), gety(i/sx, (j+1)/sy), getz(i/sx, (j+1)/sy)); glEnd(); } } }
void draw_function(int begin, int end) { moveto(width / 2, height / 2); setcolor(MAGENTA); int x_0 = getx(); int y_0 = gety(); for (double x = begin; x <= end; x += 0.1) { double y = f(x); double coord_x = x_0 + x * 60; double coord_y = y_0 + y * 20; double invert_y = (coord_y - y_0) * 2; if (x == begin) moveto(coord_x, coord_y - invert_y); lineto(coord_x, coord_y - invert_y); } }
/*! \fn CvGaborFeature::writeTXT(const char *filename) const */ void CvGaborFeature::writeTXT(const char *filename) const { FILE * file; file = fopen (filename,"a"); int x = getx(); int y = gety(); int Mu = getMu(); int Nu = getNu(); double merror = geterror(); fprintf (file, "%d %d %d %d %f\n",x, y, Nu, Mu, merror); fclose(file); }
void SpriteEx::onCol(Sprite *s) { SpriteEx *se = dynamic_cast<SpriteEx *>(s); SpriteType st = se->getSpriteType(); if (spriteType == ST_HEART2 && st == ST_DROPZONE) { parent->addScore(SCORE_DELIVER_HEART); parent->getParent().playSample("Plop"); parent->decHeartCount(); parent->dropHeart(); parent->add (new ScoreText(parent, SCORE_DELIVER_HEART, getx(), gety())); kill(); } }
int main(void){ float tempx,tempy,oldx,oldy,newx,newy; newx=0.1; newy=0.5; do{ oldx=newx; oldy=newy; newx=oldx+getx(oldx,oldy); newy=oldy+gety(oldx,oldy); printf("oldx=%f\toldy=%f\n",oldx,oldy); printf("newx=%f\tnewy=%f\n",newx,newy); }while(fabs(oldx-newx)>=0.001||fabs(oldy-newy)>=0.001); printf("\nThe final solution is:\nx=%f\ny=%f\n",newx,newy); return(0); }
static void start(Info * info){ mylogfd(SCHFD, "[sche]start\n"); info->destP.x = gety(info)+100; info->destP.y = getx(info)+POSITI*200; do_run(info); if(IsBallSeen(info)) info->state = FORWARDING_BALL; if(checkDone()) info->state = SEARCH_BALL; /* if(checkDone()) { mylogfd(SCHFD, "[sche]rotate_end\n"); // do_forward -- redwalker if(checkDone()){ info->state = SEARCH_BALL; mylogfd(SCHFD,"[sche]start->search_ball\n"); }*/ }
void flood(Cell maze[][16],Queue *q,int n) { int d = 0; int x = 0; int y = 0; int n1 = n; int n2 = 0; while (!empty(q)) { floodLevel(n1,d,q); d++; n2 = n1; n1 = 0; for (;n2 > 0;n2--) { /* Check neighbors of each cell in queue */ x = getx(qfront(q)); y = gety(qfront(q)); if (!(savingPath && !visited(&maze[x][y + 1])) && openNorth(maze,x,y) && getDist(&maze[x][y + 1]) == 255 && !checked(&maze[x][y + 1])) { in(q,&maze[x][y + 1]); n1++; } if (!(savingPath && !visited(&maze[x + 1][y])) && openEast(maze,x,y) && getDist(&maze[x + 1][y]) == 255 && !checked(&maze[x + 1][y])) { in(q,&maze[x + 1][y]); n1++; } if (!(savingPath && !visited(&maze[x][y - 1])) && openSouth(maze,x,y) && getDist(&maze[x][y - 1]) == 255 && !checked(&maze[x][y - 1])) { in(q,&maze[x][y - 1]); n1++; } if (!(savingPath && !visited(&maze[x - 1][y])) && openWest(maze,x,y) && getDist(&maze[x - 1][y]) == 255 && !checked(&maze[x - 1][y])) { in(q,&maze[x - 1][y]); n1++; } out(q); } } }
//Choose the move! void Player :: choose_move(Grid &GD){ coord_x = 0; coord_y = 0; int input; do{ input = getch(); input = (char)input; if(input == 'i'){ move_up(input,GD); } else if(input == 'k'){ move_down(input,GD); } else if(input == 'l'){ move_right(input,GD); } else if(input == 'j'){ move_left(input,GD); } cout << "Coordinate now is: " << "(" << coord_x << "," << coord_y << ")" << endl; cout << "Coordinate old is: " << "(" << coord_x_old << "," << coord_y_old << ")" << endl; //Show Grid everytime after move show_grid(GD); }while(input != 'm'); choice += 1; int k; int i = 1; do{ k = GD.check_entered(i, getx(), gety()); i++; }while(i <= choice); if(k == 0){ GD.setcoord_entered(choice,coord_x,coord_y); } cout << "Entered Coordinate is: " << "(" << coord_x << "," << coord_y << ")" << endl; }