static void draw_board(int m, int n) { int i, j, x, y, len; x = 100 + n * D ; y = 100 + m * D ; for (i = x - R; i <= x +R; i++) for (j = y - R; j <= y + R; j++) { switch (board[m][n]) { case BLACK: len = sqrt((x - i)*(x - i) + (y -j)*(y -j)); if (len <= R) { fb_draw_point(i, j, 0x00); fb_draw_point(xres() - 200 + D / 2 + (x - i), R + 10 + (y -j), 0xFF); } break; case WHITE: len = sqrt((x - i)*(x - i) + (y -j)*(y -j)); if (len <= R) { fb_draw_point(i, j, 0xFF); fb_draw_point(xres() - 200 + D / 2 + (x - i), R + 10 + (y -j), 0x00); } break; case NONE: break; default: break; } } }
MyClass() { QString xres("{ 'var' : 'xres', 'name' : 'Image Width', 'type' : 'int', 'min' : 1, 'max' : 4096, 'value' : 1024 }"); QString yres("{ 'var' : 'yres', 'name' : 'Image Height', 'type' : 'int', 'min' : 1, 'max' : 4096, 'value' : 768 }"); QString samplingWidth("{ 'var' : 'samplingWidth', 'name' : 'Sampling Width', 'type' : 'float', 'min' : 1, 'max' : 8, 'value' : 3 }"); QString exposure("{ 'var' : 'exposure', 'name' : 'Exposure', 'type' : 'float', 'min' : 0.001, 'max' : 1000, 'value' : 1.0 }"); QStringList atts; atts << xres << yres << samplingWidth << exposure; addAttributes(atts); }
VImage VImage::new_from_image( std::vector<double> pixel ) { VImage onepx = VImage::black( 1, 1, VImage::option()->set( "bands", bands() ) ); onepx = onepx.linear( to_vectorv( 1, 1.0 ), pixel ).cast( format() ); VImage big = onepx.embed( 0, 0, width(), height(), VImage::option()->set( "extend", VIPS_EXTEND_COPY ) ); big = big.copy( VImage::option()-> set( "interpretation", interpretation() )-> set( "xres", xres() )-> set( "yres", yres() )-> set( "xoffset", xres() )-> set( "yoffset", yres() ) ); return( big ); }
void init_board(void) { int i, j; startx = 50, starty = 50, endx=xres() - 50, endy = yres() - 50, scope = 0; maxn = (xres() - 500) / D, maxm = (yres() - 150) / D; if (maxn >= MAXWIDTH) maxn = MAXWIDTH - 1; if (maxm >= MAXHEIGHT) maxm = MAXHEIGHT - 1; //init board to zero for (i = 0; i<= maxn; i++) for (j = 0; j<= maxm; j++) board[j][i] = 0; printf("\033[?25l"); //隐藏光标 system("clear"); background_pic("background.bmp"); draw_board(); printlet((maxn + 2) * D + 50, 2 * D + 100, "NEXT"); print_scope(0); }
void init(void) { int i; srand(getpid()); for (i = 0; i < BOX_SIZE; i++) { box[i].cent.x = (unsigned)rand() % (xres() - 200) + 100; box[i].cent.y = (unsigned)rand() % (yres() - 200) + 100; box[i].dir = (unsigned)rand() % 4; box[i].r = 50; box[i].color = 0xaf; } }
static void change_dir__(struct circle *p) { if (p->cent.x - p->r == 0 && p->cent.y - p->r == 0) { p->dir = 1; } else if (p->cent.x - p->r == 0 && p->cent.y + p->r == yres() - 1) { p->dir = 0; } else if (p->cent.x + p->r == xres() - 1 && p->cent.y - p->r == 0) { p->dir = 2; } else if (p->cent.x + p->r == xres() - 1 && p->cent.y + p->r == yres() - 1) { p->dir = 3; } else if (p->cent.x - p->r == 0) { if (p->dir == 2) { p->dir = 1; } else { p->dir = 0; } } else if (p->cent.x + p->r == xres() - 1) { if (p->dir == 0) { p->dir = 3; } else { p->dir = 2; } } else if (p->cent.y - p->r == 0) { if (p->dir == 0) { p->dir = 1; } else { p->dir = 2; } } else if (p->cent.y + p->r == yres() - 1) { if (p->dir == 1) { p->dir = 0; } else { p->dir = 3; } } }
void move(void) { int x, y, r, l, limitx, limity; srand(getpid()); //r = rand() % 8; r = 2; y = x = rand() % 500; limitx = xres() - 2*R; limity = yres() - 2*R; while (l = 4) { switch (l){ case 1: /* x++, y++ */ for (; x <= limitx && y <= limity; x++, y += r) { dram(x,y+R*2); usleep(10000); clean(x, y+R*2); } break; case 2: /* x--, y-- */ for (; x >= 0 && y >= 0; x--, y -= r) { dram(x,y+R*2); usleep(10000); clean(x, y+R*2); } break; case 3: /* x--, y++ */ for (; x >= 0 && y <= limity; x--, y += r) { dram(x,y+R*2); usleep(10000); clean(x, y+R*2); } break; case 4: /* x++, y-- */ for (; x <= limitx && y >= 0; x++, y -= r) { dram(x,y+R*2); usleep(10000); clean(x, y+R*2); } break; default: break; } } }
void move_brick(struct brick *b, int flag) { int i, j, s, xlim, xmax, ylim; if (flag == CLEAN) for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) { xlim = b->x +(i-0) * D; clean_box(xlim, b->y + j * D, D); } else for (i = s; i < 4; i++) for (j = 0; j < 4; j++) { xlim = b->x +(i-s) * D; ylim = b->y + j * D; if (xlim >= 50 && xlim <= (xres() - 450) && brick_num[b->b1][b->b2][j][i] == 9) draw_box(xlim, ylim, D); } }
static void init_board(void) { int i, j, startx = 50, starty = 50, endx=xres() - 50, endy = yres() - 50; int BW = 1, che_count = 1, winner = 1, space = 0, col = 0; boardx = (endx - 100) / D > MAXBOARD ? MAXBOARD: (endx - 100) / D; boardy = (endy - 100) / D > MAXBOARD ? MAXBOARD: (endy - 100) / D; system("clear"); for (; startx <= endx - 400 ; startx += D) for (starty = 100; starty <= endy; starty +=D) { for (i = 0; i <= D; i++) for (j = 0; j <= D; j++) if ((i < D - 1) && (j < D -1) ) { fb_draw_point(i+startx ,j+starty , 244); } else fb_draw_point(i+startx ,j+starty ,0x00); //printdig(i+startx ,j+starty , col++); } }
/* >>> start tutorial code >>> */ int main( ){ USING_NAMESPACE_ACADO // DEFINE VALRIABLES: // --------------------------- DifferentialStateVector x(3); // the position of the pendulum (x,y,alpha) DifferentialStateVector v(3); // the associated velocities AlgebraicStateVector a(3); // the associated accelerations AlgebraicStateVector lambda(2); // the constraint forces const double L = 1.00; // the length of the pendulum const double m = 1.00; // the mass of the pendulum const double g = 9.81; // the gravitational constant const double J = m*L*L; // the inertial of the pendulum IntermediateStateVector R(3); IntermediateStateVector G(2); R.setComponent( 0, m*a(0) ); // ---------------------------------------- R.setComponent( 1, m*a(1) + m*g ); // the definition of the force residuum: R.setComponent( 2, J*a(2) ); // R := m*a - F G.setComponent( 0, x(0)-L*sin(x(2)) ); // definition of the constraint manifold G G.setComponent( 1, x(1)+L*cos(x(2)) ); // --------------------------------------- // AUTOMATIC GENERATION OF AN INDEX 1 DAE SYSTEM BASES ON THE // NEWTON EULER FORMALISM: // ----------------------------------------------------------- DifferentialEquation f; NewtonEulerFormalism( f, R, G, x, v, a, lambda ); // Define an integrator: // --------------------- IntegratorBDF integrator( f ); // Define an initial value: // ------------------------ double x_start[6]; double z_start[5]; x_start[0] = 1.9866932270683099e-01; x_start[1] = -9.8006654611577315e-01; x_start[2] = 2.0000003107582773e-01; x_start[3] = -1.4519963562050693e-04; x_start[4] = 4.7104175041346282e-04; x_start[5] = 4.4177521668741377e-04; z_start[0] = -9.5504866367984165e-01; z_start[1] = -1.9359778029074531e-01; z_start[2] = -9.7447321693831934e-01; z_start[3] = -9.5504866367984165e-01; z_start[4] = 9.6164022197092560e+00; double t_start = 0.0; double t_end = 10.0; // START THE INTEGRATION // ---------------------- integrator.set( INTEGRATOR_PRINTLEVEL, MEDIUM ); // integrator.set( INTEGRATOR_TOLERANCE, 1e-12 ); integrator.freezeAll(); integrator.integrate( x_start, z_start, t_start, t_end ); VariablesGrid xres,zres; integrator.getTrajectory(&xres,&zres,NULL,NULL,NULL,NULL); GnuplotWindow window; window.addSubplot( xres(0), "The x-position of the mass m" ); window.addSubplot( xres(1), "The y-position of the mass m" ); window.addSubplot( xres(2), "The excitation angle of the pendulum" ); window.addSubplot( xres(3), "The velocity in x-direction" ); window.addSubplot( xres(4), "The velocity in y-direction" ); window.addSubplot( xres(5), "The angular velocity" ); // window.addSubplot( zres(0), "The acceleration in x-direction" ); // window.addSubplot( zres(1), "The acceleration in y-direction" ); // window.addSubplot( zres(2), "The angular acceleration" ); window.addSubplot( zres(3), "The constraint force in x-direction" ); window.addSubplot( zres(4), "The constraint force in y-direction" ); window.plot(); return 0; }