void KbfxPlasmaCanvasItem::advance ( int phase ) { if ( phase == 0 ) { setXVelocity ( 0 ); setYVelocity ( yVelocity () * 1 - 0.001 ); } else { move ( x () + xVelocity (), y () + yVelocity () ); } }
QRect ossimQtVceShape::boundingRectAdvanced() const { int dx = int(x()+xVelocity())-int(x()); int dy = int(y()+yVelocity())-int(y()); QRect r = boundingVceShapeRect(); r.moveBy(dx,dy); return r; }
void Floater::advance(int phase) { if (!isEnabled()) return; Bridge::advance(phase); if (phase == 1 && (xVelocity() || yVelocity())) { if (Vector(origin, QPoint(x(), y())).magnitude() > vector.magnitude()) { vector.setDirection(vector.direction() + M_PI); origin = (origin == wall->startPoint()? wall->endPoint() : wall->startPoint()); setVelocity(-xVelocity(), -yVelocity()); } } }
void BouncyLogo::initPos() { initSpeed(); int trial=1000; do { move(rand()%canvas()->width(),rand()%canvas()->height()); advance(0); // 動畫不移動 } while (trial-- && xVelocity()==0.0 && yVelocity()==0.0); // trial不為0且x,y速度都為0 }
void BouncyLogo::advance(int stage) { switch ( stage ) { case 0: { double vx = xVelocity(); double vy = yVelocity(); if ( vx == 0.0 && vy == 0.0 ) { // stopped last turn initSpeed(); vx = xVelocity(); vy = yVelocity(); } double nx = x() + vx; double ny = y() + vy; if ( nx < 0 || nx >= canvas()->width() ) vx = -vx; // 換反方向 if ( ny < 0 || ny >= canvas()->height() ) vy = -vy; // 換反方向 for (int bounce=0; bounce<4; bounce++) { QCanvasItemList l=collisions(FALSE); // 沒有那麼精準的傳回所有有碰撞的canvas item for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { QCanvasItem *hit = *it; if ( hit->rtti()==logo_rtti && hit->collidesWith(this) ) { switch ( bounce ) { case 0: vx = -vx; break; case 1: vy = -vy; vx = -vx; break; case 2: vx = -vx; break; case 3: // Stop for this turn vx = 0; vy = 0; break; } setVelocity(vx,vy); break; } } } if ( x()+vx < 0 || x()+vx >= canvas()->width() ) vx = 0; if ( y()+vy < 0 || y()+vy >= canvas()->height() ) vy = 0; setVelocity(vx,vy); } break; case 1: QCanvasItem::advance(stage); break; } }
int main(int argc, char *argv[]){ double time=0; double xOld=0, yOld=0, v_xOld =0, v_yOld=0; double xNew=0, yNew=0, v_xNew=0, v_yNew=0; double K = 0.2; //k/m = constatnt K in code double k_over_m = 0; int count = 0, i=0; FILE *outp; h1 hist; const double deltaT = 0.01; outp = fopen("resist.dat", "w"); h1init(&hist, 700, 160., 490., "Distribution of Range with Varying Values of k/m"); h1labels(&hist, "Range in m", "Number of Occurences"); double angle = (pi/180)*atof(argv[1]); double initVelocity = atof(argv[2]); fprintf(outp, "# t x y v_x v_y\n"); fprintf(outp, "#--------------------\n"); v_xOld = initVelocity*cos(angle); v_yOld = initVelocity*sin(angle); while(yNew>=0){ v_xNew = xVelocity(v_xOld, deltaT, K); v_yNew = yVelocity(v_yOld, deltaT, K); xNew = position(xOld, v_xOld, deltaT); yNew = position(yOld, v_yOld, deltaT); time = deltaT*count; fprintf(outp, "%lf %lf %lf %lf %lf\n", time, xNew, yNew, v_xNew, v_xOld); count++; v_xOld = v_xNew; v_yOld = v_yNew; xOld = xNew; yOld = yNew; } for(i=0; i<10000; i++){ k_over_m = randu(0.1, 0.4); v_xOld = initVelocity*cos(angle); v_yOld = initVelocity*sin(angle); while(yNew>=0){ v_xNew = xVelocity(v_xOld, deltaT, k_over_m); v_yNew = yVelocity(v_yOld, deltaT, k_over_m); xNew = position(xOld, v_xOld, deltaT); yNew = position(yOld, v_yOld, deltaT); v_xOld = v_xNew; v_yOld = v_yNew; xOld = xNew; yOld = yNew; } h1fill(&hist, xOld, 1.0); xNew =0; xOld=0; yNew = 1e-8; yOld = 1e-8; } h1plot(&hist, ""); h1plot(&hist, "resist.pdf"); fclose(outp); return 0; }