static void key_func(unsigned char key, int x, int y) { switch (key) { case 'c': case 'C': clear_data(); break; case 'd': case 'D': dump_frames = !dump_frames; break; case 'q': case 'Q': free_data(); exit(0); break; case 'v': case 'V': dvel = !dvel; break; case 'p': dpar = !dpar; break; case 'P': for (int i = 0; i < pVector.size(); i++) pVector[i]->reset(); break; case 's': pVector.clear(); fVector.clear(); create_grid(16, true, true); for (int i = 0; i < pVector.size(); i++) pVector[i]->reset(); break; case 'S': pVector.clear(); fVector.clear(); create_grid(N, false, false); for (int i = 0; i < pVector.size(); i++) pVector[i]->reset(); break; case '@': VorticityConfinement = !VorticityConfinement; printf("Vorticity confinement %s\n", VorticityConfinement ? "on" : "off"); break; case 'f': drawLine = !drawLine; break; case ' ': pause = !pause; break; } }
VOID BuildHierarchy_Uniform() { INT i; INT num; INT num_pe; INT status; REAL den; GRID *g; GRID *gr; GRID *ng; GRID testgrid; VOXEL *v; RAY r; RAYINFO *rinfo; ELEMENT **pepa; init_masks(); pepa = MakeElementArray(&num_pe); v = init_world_voxel(pepa,num_pe); gm->world_level_grid = init_world_grid(v, pepa, num_pe); g = gm->world_level_grid; ng = create_grid(v, g, num_pe); fprintf(stderr, "Uniform Hierarchy built.\n"); }
int main(void) { char *line; t_box box; int ret; int i; ret = 0; ft_bzero(&box, (sizeof(box))); while ((ret = get_next_line(0, &line) != 0)) { if ((i = -1) && box.b_play == 0) check_player(line, &box); else if ((ft_strnequ(line, "Plateau", 7))) create_grid(line, &box); else if ((ft_strnequ(line, "Piece", 5))) { get_piece(line, &box); print_map(&box); while (i < 69999999) i++; if (!try_rush(&box)) return (0); reinitialise_box(&box); } } return (0); }
int main(int argc, char **argv) { int nbr_tetris; char **grid; t_tetrimino *tetris; t_coord co; t_path path; path.square_size = -1; path.path = ft_strnew(27); co.x = 0; co.y = 0; nbr_tetris = -1; if (argc != 2 || !(is_valid_file(argv[1]))) write(1, "error\n", 6); else if (!(nbr_tetris = process_file(argv[1], 0, &tetris))) write(1, "error\n", 6); else { grid = create_grid(nbr_tetris); path = fill_grid(grid, tetris, co, nbr_tetris); ft_strrev(path.path); grid_from_str(path.path, grid, tetris, co); display_grid(grid); free_grid(grid); } return (0); }
void GridOrient(vec3d *forward, vec3d *right) { vec3d center; int nrows, ncols; float square_size; if (The_grid != NULL) { center = The_grid->center; nrows = The_grid->nrows; ncols = The_grid->ncols; square_size = The_grid->square_size; } else { vm_vec_make(¢er, 0.0f, 0.0f, 0.0f); nrows = 20; ncols = 20; square_size = 2.0f; } The_grid = create_grid(The_grid, forward, right, ¢er, nrows, ncols, square_size); physics_init(&The_grid->physics); }
void show_transfer_window (void) { GtkBuilder *gbuilder = gtk_builder_new(); ex_builder_load_file (gbuilder, "gridform.ui"); gtk_builder_connect_signals (gbuilder, NULL); window = GTK_WIDGET(gtk_builder_get_object (gbuilder, "window")); GtkContainer *scrolledwindow_grid = GTK_CONTAINER(gtk_builder_get_object (gbuilder, "scrolledwindow_grid")); button_del = GTK_BUTTON(gtk_builder_get_object (gbuilder, "button_del")); GtkWidget *button_add = GTK_WIDGET(gtk_builder_get_object (gbuilder, "button_add")); GtkWidget *button_edit = GTK_WIDGET(gtk_builder_get_object (gbuilder, "button_edit")); gtk_widget_set_visible (button_add, FALSE); gtk_widget_set_visible (button_edit, FALSE); grid = create_grid (scrolledwindow_grid); g_signal_connect (G_OBJECT(grid), "selection_changed", G_CALLBACK (on_grid_selection_changed), NULL); g_signal_connect (G_OBJECT(button_del), "clicked", G_CALLBACK (on_button_del_clicked), NULL); fill_grid(); gtk_widget_show(window); }
void launch_new_game(t_box *box) { box->is_launch = 1; create_grid(box); put_food(box); mlx_put_image_to_window(box->mlx, box->win, box->img, 0, 0); return ; }
state_t env_start(env_t* p_env) { assert(p_env!=NULL); //p_env->cell = p_env->n_cells-1; // Put agent at random position (but not in a terminal state) create_grid(p_env); // Return first observed state return env_observe_state(p_env); }
int main(int argc, char *argv[]) { if (argc >= 2) { window_t *main_window = window_open(argv[1], NULL, WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vdemo"); if (!main_window) { printf("Cannot open main window.\n"); return 1; } pixel_t grd_bg = PIXEL(255, 240, 240, 240); pixel_t btn_bg = PIXEL(255, 240, 240, 240); pixel_t btn_fg = PIXEL(255, 186, 186, 186); pixel_t btn_text = PIXEL(255, 0, 0, 0); pixel_t lbl_bg = PIXEL(255, 240, 240, 240); pixel_t lbl_text = PIXEL(255, 0, 0, 0); my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16, lbl_bg, lbl_text); button_t *btn_confirm = create_button(NULL, NULL, "Confirm", 16, btn_bg, btn_fg, btn_text); button_t *btn_cancel = create_button(NULL, NULL, "Cancel", 16, btn_bg, btn_fg, btn_text); grid_t *grid = create_grid(window_root(main_window), NULL, 2, 2, grd_bg); if (!lbl_action || !btn_confirm || !btn_cancel || !grid) { window_close(main_window); printf("Cannot create widgets.\n"); return 1; } sig_connect( &btn_confirm->clicked, &lbl_action->label.widget, lbl_action->confirm); sig_connect( &btn_cancel->clicked, &lbl_action->label.widget, lbl_action->cancel); grid->add(grid, &lbl_action->label.widget, 0, 0, 2, 1); grid->add(grid, &btn_confirm->widget, 0, 1, 1, 1); grid->add(grid, &btn_cancel->widget, 1, 1, 1, 1); window_resize(main_window, 0, 0, 200, 76, WINDOW_PLACEMENT_CENTER); window_exec(main_window); task_retval(0); async_manager(); return 1; } else { printf("Compositor server not specified.\n"); return 1; } }
gint main (gint argc, char *argv[]) { gtk_init (&argc, &argv); create_grid (); gtk_main (); return 0; }
/* generate random grid structure with given site vacancy probability */ int run_percolation(grid *gd, double prob, int recursive_flag) { create_grid(gd, prob); start_flow(gd); if (recursive_flag) flow_recursive(gd); else flow_iterative(gd); return percolates(gd); }
void preparation(t_map **map) { char **grid; grid = NULL; g_size = size_min_square(*map); init_grid(&grid); while (backtrack(grid, *map) != 0) create_grid(&grid); print_grid(grid); delete_tab(&grid); }
// Create a nice grid -- centered at origin, 10x10, 10.0 size squares, in xz plane. grid *create_default_grid(void) { grid *rgrid; vector fvec, rvec, cvec; rgrid = create_grid(&Global_grid, vm_vec_make(&fvec, 0.0f, 0.0f, 1.0f), vm_vec_make(&rvec, 1.0f, 0.0f, 0.0f), vm_vec_make(&cvec, 0.0f, 0.0f, 0.0f), 100, 100, 5.0f); physics_init(&rgrid->physics); return rgrid; }
d_surf * _surf_load_bmp(const char * filename, const char * surfname, REAL minz, REAL maxz, REAL startX, REAL startY, REAL stepX, REAL stepY) { writelog(LOG_MESSAGE, "loading surface from BMP file %s",filename); BMP bmp; if (bmp.ReadFromFile(filename) == false) { writelog(LOG_ERROR,"Error loading surface from bitmap!"); return NULL; } size_t NN = bmp.TellWidth(); size_t MM = bmp.TellHeight(); extvec * coeff = create_extvec( NN*MM, 0, 0, 0); size_t i,j; double gray_color; double alpha; for (j = 0; j < MM; j++) { for (i = 0; i < NN; i++) { gray_color = bmp(i,j)->Red * 0.299 + bmp(i,j)->Green * 0.587 + bmp(i,j)->Blue * 0.114; alpha = bmp(i,j)->Alpha; if (alpha == 255) (*coeff)(i + (MM-1-j)*NN) = undef_value; else { if (minz != maxz) (*coeff)(i + (MM-1-j)*NN) = (maxz-minz)*gray_color/REAL(255) + minz; else (*coeff)(i + (MM-1-j)*NN) = gray_color; } } } d_grid * grd = create_grid(startX, startX + stepX*(NN-1), stepX, startY, startY + stepY*(MM-1), stepY); d_surf * res = create_surf(coeff, grd); if (surfname) res->setName(surfname); else { char * name = get_name(filename); res->setName(name); sstuff_free_char(name); } return res; };
void clique::process(const dataset & p_data, cluster_data & p_result) { m_data_ptr = &p_data; m_result_ptr = dynamic_cast<clique_data *>(&p_result); create_grid(); for (auto & block : m_result_ptr->blocks()) { if (!block.is_visited()) { expand_cluster(block); } } m_cells_map.clear(); }
void map_processing(t_e *e) { e->mlx = mlx_init(); e->win = mlx_new_window(e->mlx, WIN_W, WIN_H, WIN_N); e->ima = mlx_new_image(e->mlx, WIN_W, WIN_H); e->ima_data = mlx_get_data_addr( e->ima, &(e->ima_bits), &(e->ima_line), &(e->ima_endi)); e->grid = create_grid(e); reset(e); mlx_key_hook(e->win, key_hook, e); mlx_mouse_hook(e->win, mouse_hook, e); mlx_expose_hook(e->win, expose_hook, e); mlx_hook(e->win, 17, (1L << 17), &end_exe, e); mlx_hook(e->win, 2, (1L << 0), &key_hook_press, e); mlx_loop(e->mlx); }
static int allocate_data(void) { FieldToolbox::Create(); VelocityField = new VectorField(N, visc, dt); PrevVelocityField = new VectorField(N, visc, dt); DensityField = new ScalarField(N, diff, dt); PrevDensityField = new ScalarField(N, diff, dt); bodies.push_back(new Rectangle(Vec2f(0.5f, 0.5f), 0.001f, 0.3f, 0.2f)); create_grid(32, false, true); if (!VelocityField || !PrevVelocityField || !DensityField || !PrevDensityField) { fprintf(stderr, "cannot allocate data\n"); return (0); } return (1); }
static void init_game(s_game **game, int nb_players, char *custom_music) { s_game *tmp = NULL; int i = 0; tmp = malloc(sizeof (struct s_game)); tmp->screen = SDL_SetVideoMode(LARGEUR, HAUTEUR, 32, SDL_HWSURFACE); tmp->bomb = IMG_Load("/u/all/peccau_s/public/data/bomb.png"); tmp->fire[0] = IMG_Load("/u/all/peccau_s/public/data/node.png"); tmp->fire[1] = IMG_Load("/u/all/peccau_s/public/data/fire_h.png"); tmp->fire[2] = IMG_Load("/u/all/peccau_s/public/data/fire_v.png"); tmp->fire[3] = IMG_Load("/u/all/peccau_s/public/data/fire_nend.png"); tmp->fire[4] = IMG_Load("/u/all/peccau_s/public/data/fire_eend.png"); tmp->fire[5] = IMG_Load("/u/all/peccau_s/public/data/fire_send.png"); tmp->fire[6] = IMG_Load("/u/all/peccau_s/public/data/fire_wend.png"); for (; i < MAX_CASE - 10; i++, tmp->l_bomb.ticks[i] = 0) ; tmp->help_s = IMG_Load("/u/all/peccau_s/public/data/help.png"); tmp->help_r.x = 700; tmp->help_r.y = 325; tmp->pause = 0; tmp->trigger = 1; tmp->last_input = 0; tmp->current_time = 0; tmp->blink = 0; tmp->max_players = nb_players; tmp->custom_mus = custom_music; tmp->info = malloc(sizeof (s_game_info)); tmp->info->sec = 0; tmp->info->min = 0; tmp->info->timer_sec_s = NULL; tmp->info->timer_sec_r = NULL; tmp->info->remain = END_GAME; for (i = 0; i < MAX_CASE; i++) tmp->l_bomb.p[i] = 0; for (i = 0; i < nb_players; i++) tmp->l_bomb.pnbb[i] = 1; init_font(tmp); init_items(tmp); *game = tmp; config_fonts(*game); (*game)->tab = create_grid(*game, nb_players); }
/** * Before any simulations, this module: * - creates a grid around the study area, if needed * - determines which units are in which grid squares * * @param self the model. * @param units a list of units. */ void handle_before_any_simulations_event (struct adsm_module_t_ *self, UNT_unit_list_t *units) { local_data_t *local_data; #if DEBUG g_debug ("----- ENTER handle_before_any_simulations_event (%s)", MODEL_NAME); #endif local_data = (local_data_t *) (self->model_data); create_grid (local_data, units->spatial_index); map_units_to_polys (local_data, units); #if DEBUG g_debug ("----- EXIT handle_before_any_simulations_event (%s)", MODEL_NAME); #endif return; }
d_dem * _surf_to_dem(d_surf * srf) { shortvec * coeff = create_shortvec( srf->coeff->size() ); size_t i; REAL val; for (i = 0; i < srf->coeff->size(); i++) { val = (*(srf->coeff))(i); if (val == srf->undef_value) (*coeff)(i) = SHRT_MAX; else (*coeff)(i) = (short)val; }; d_grid * fgrd = srf->grd; d_grid * grd = create_grid(fgrd); d_dem * res = create_dem(coeff, grd); res->undef_value = SHRT_MAX; res->setName(srf->getName()); return res; };
VOID BuildHierarchy_Uniform() { INT num_pe; GRID *g; GRID *ng; VOXEL *v; ELEMENT **pepa; init_masks(); pepa = MakeElementArray(&num_pe); v = init_world_voxel(pepa,num_pe); gm->world_level_grid = init_world_grid(v, pepa, num_pe); g = gm->world_level_grid; ng = create_grid(v, g, num_pe); fprintf(stderr, "Uniform Hierarchy built.\n"); }
maze():m_grid(create_grid(0, 0)),m_barrier_grid(create_barrier_grid()) {};
void setup_Spec_LumTables_onthefly(void) { double AbsMAG; //FILTERS double LambdaFilter[NMAG][MAX_NLambdaFilter], FluxFilter[NMAG][MAX_NLambdaFilter]; double *FluxFilterOnGrid, FluxFilterInt; //InputSSP spectra double LambdaInputSSP[SSP_NAGES][SSP_NLambda], FluxInputSSP[SSP_NAGES][SSP_NLambda]; double *FluxInputSSPConv, *FluxInputSSPOnGrid, FluxInputSSPInt; //VEGA double LambdaVega[NLambdaVega], FluxVega[NLambdaVega]; double *FluxVegaConv, *FluxVegaOnGrid, FluxVegaInt; //AUX ARRAYS for FILTERS and InputSSP double LambdaFilter_SingleFilter[MAX_NLambdaFilter], FluxFilter_SingleFilter[MAX_NLambdaFilter], LambdaInputSSP_SingleAge[SSP_NLambda]; double redshift; //Loops in the code int MetalLoop, AgeLoop, snap, band, i; FILE *File_PhotTables[NMAG]; #ifdef PARALLEL if(ThisTask == 0) printf("\n\nComputing PhotTables on the fly...\n\n"); #else printf("\n\nComputing PhotTables on the fly...\n\n"); #endif read_vega_spectra(LambdaVega, FluxVega); #ifndef FULL_SPECTRA read_filters(LambdaFilter, FluxFilter); #endif setup_RedshiftTab(); read_MetalTab(); //1st loop on the mettalicity files for (MetalLoop=0;MetalLoop<SSP_NMETALLICITES;MetalLoop++) { #ifdef PARALLEL if(ThisTask == 0) printf("Doing Metallicity File %d of %d\n",MetalLoop+1, SSP_NMETALLICITES); #else printf("Doing Metallicity File %d of %d\n",MetalLoop+1, SSP_NMETALLICITES); #endif //READ FULL INPUT SPECTRA into units of erg.s^-1.Hz^-1 read_InputSSP_spectra(LambdaInputSSP, FluxInputSSP, MetalLoop); //2nd Loop on redshift for(snap=0;snap<(LastDarkMatterSnapShot+1);snap++) { redshift=RedshiftTab[(LastDarkMatterSnapShot+1)-snap-1]; //3rd loop on Age for(AgeLoop=0;AgeLoop<SSP_NAGES;AgeLoop++) { //4th loop on Bands //IF FULL_SPECTRA defined a band correspond to a wavelength on the SSP spectra for(band=0;band<NMAG;band++) { #ifndef FULL_SPECTRA //ALLOCATE GRID - size of filter, binning of the spectra int Min_Wave_Grid=0, Max_Wave_Grid=0, Grid_Length=0; double *lgrid=create_grid(LambdaFilter[band][0], LambdaFilter[band][NLambdaFilter[band]-1], AgeLoop, redshift, LambdaInputSSP, &Min_Wave_Grid, &Max_Wave_Grid, &Grid_Length); if(Grid_Length>0) { for(i=0;i<Grid_Length;i++) lgrid[i]=(1+redshift)*LambdaInputSSP[AgeLoop][Min_Wave_Grid+i]; //VEGA - interpolate spectrum on integral grid FluxVegaOnGrid = malloc(sizeof(double) * Grid_Length); interpolate(lgrid, Grid_Length, LambdaVega, NLambdaVega, FluxVega, FluxVegaOnGrid); /*SSP - multiply by (1+z) to go from rest to observed SSP flux*/ FluxInputSSPOnGrid = malloc(sizeof(double) * Grid_Length); for (i=0;i<Grid_Length;i++) FluxInputSSPOnGrid[i]=(1.+redshift)*FluxInputSSP[AgeLoop][Min_Wave_Grid+i]; //FILTERS - interpolate on integral grid for(i=0;i<NLambdaFilter[band];i++) { LambdaFilter_SingleFilter[i]=LambdaFilter[band][i]; FluxFilter_SingleFilter[i]=FluxFilter[band][i]; } FluxFilterOnGrid = malloc(sizeof(double) * Grid_Length); interpolate(lgrid, Grid_Length, LambdaFilter_SingleFilter, NLambdaFilter[band], FluxFilter_SingleFilter, FluxFilterOnGrid) ; /* spectrum and filters are now defined on same grid * CONVOLUTION: direct (configuration) space * simply multiply filter*spectrum it's a convolution in Fourier space */ FluxInputSSPConv = malloc(sizeof(double) * Grid_Length); for(i=0;i<Grid_Length;i++) FluxInputSSPConv[i]=FluxInputSSPOnGrid[i]*FluxFilterOnGrid[i]; FluxVegaConv = malloc(sizeof(double) * Grid_Length); for(i=0;i<Grid_Length;i++) FluxVegaConv[i]=FluxVegaOnGrid[i]*FluxFilterOnGrid[i]; //INTEGRATE FluxFilterInt=integrate(FluxFilterOnGrid, Grid_Length); FluxVegaInt=integrate(FluxVegaConv, Grid_Length); FluxInputSSPInt=integrate(FluxInputSSPConv, Grid_Length); //Absolute Observed Frame Magnitudes if (FluxInputSSPInt == 0. || FluxFilterInt == 0.) AbsMAG=99.; else { #ifdef AB AbsMAG=get_AbsAB_magnitude(FluxInputSSPInt, FluxFilterInt, redshift); #endif #ifdef VEGA AbsMAG=get_AbsAB_magnitude(FluxInputSSPInt, FluxFilterInt, redshift); AbsMAG=AbsMAG+2.5*(log10(FluxVegaInt)-log10(FluxFilterInt))+48.6; //MagABVega[band]=-2.5*(log10(FluxVegaInt) // -log10(FluxFilterInt))-48.6; #endif } free(FluxVegaOnGrid); free(FluxVegaConv); free(FluxInputSSPOnGrid); free(FluxInputSSPConv); free(FluxFilterOnGrid); } else //if Grid_Length=0 (filter outside the spectra, can happen for observed frame) AbsMAG=99.; LumTables[band][MetalLoop][snap][AgeLoop] = pow(10.,-AbsMAG/2.5); free(lgrid); #else //ifdef FULL_SPECTRA //FULL_SPECTRA defined -> a band corresponds to a wavelength on the SSP spectra FilterLambda[band]=(1+redshift)*LambdaInputSSP[AgeLoop][band]; LumTables[band][MetalLoop][snap][AgeLoop] = (1.+redshift)*FluxInputSSP[AgeLoop][band]; #endif } // end age loop }//end snap loop }//end Band loop } //end loop on metallicities printf("\nPhotTables Computed.\n\n"); }
int main(int argc, char *argv[]) { PLFLT *x, *y, *z, *clev; PLFLT *xg, *yg, **zg, **szg; PLFLT zmin, zmax, lzm, lzM; long ct; int i, j, k; PLINT alg; char ylab[40], xlab[40]; char *title[] = {"Cubic Spline Approximation", "Delaunay Linear Interpolation", "Natural Neighbors Interpolation", "KNN Inv. Distance Weighted", "3NN Linear Interpolation", "4NN Around Inv. Dist. Weighted"}; PLFLT opt[] = {0., 0., 0., 0., 0., 0.}; xm = ym = -0.2; xM = yM = 0.8; plMergeOpts(options, "x21c options", NULL); plparseopts(&argc, argv, PL_PARSE_FULL); opt[2] = wmin; opt[3] = (PLFLT) knn_order; opt[4] = threshold; /* Initialize plplot */ plinit(); create_data(&x, &y, &z, pts); /* the sampled data */ zmin = z[0]; zmax = z[0]; for (i=1; i<pts; i++) { if (z[i] > zmax) zmax = z[i]; if (z[i] < zmin) zmin = z[i]; } create_grid(&xg, xp, &yg, yp); /* grid the data at */ plAlloc2dGrid(&zg, xp, yp); /* the output grided data */ clev = (PLFLT *) malloc(nl * sizeof(PLFLT)); sprintf(xlab, "Npts=%d gridx=%d gridy=%d", pts, xp, yp); plcol0(1); plenv(xm, xM, ym, yM, 2, 0); plcol0(15); pllab(xlab, "", "The original data"); plcol0(2); plpoin(pts, x, y, 5); pladv(0); plssub(3,2); for (k=0; k<2; k++) { pladv(0); for (alg=1; alg<7; alg++) { ct = clock(); plgriddata(x, y, z, pts, xg, xp, yg, yp, zg, alg, opt[alg-1]); sprintf(xlab, "time=%d ms", (clock() - ct)/1000); sprintf(ylab, "opt=%.3f", opt[alg-1]); /* - CSA can generate NaNs (only interpolates?!). * - DTLI and NNI can generate NaNs for points outside the convex hull * of the data points. * - NNLI can generate NaNs if a sufficiently thick triangle is not found * * PLplot should be NaN/Inf aware, but changing it now is quite a job... * so, instead of not plotting the NaN regions, a weighted average over * the neighbors is done. */ if (alg == GRID_CSA || alg == GRID_DTLI || alg == GRID_NNLI || alg == GRID_NNI) { int ii, jj; PLFLT dist, d; for (i=0; i<xp; i++) { for (j=0; j<yp; j++) { if (isnan(zg[i][j])) { /* average (IDW) over the 8 neighbors */ zg[i][j] = 0.; dist = 0.; for (ii=i-1; ii<=i+1 && ii<xp; ii++) { for (jj=j-1; jj<=j+1 && jj<yp; jj++) { if (ii >= 0 && jj >= 0 && !isnan(zg[ii][jj])) { d = (abs(ii-i) + abs(jj-j)) == 1 ? 1. : 1.4142; zg[i][j] += zg[ii][jj]/(d*d); dist += d; } } } if (dist != 0.) zg[i][j] /= dist; else zg[i][j] = zmin; } } } } plMinMax2dGrid(zg, xp, yp, &lzM, &lzm); plcol0(1); pladv(alg); if (k == 0) { lzm = MIN(lzm, zmin); lzM = MAX(lzM, zmax); for (i=0; i<nl; i++) clev[i] = lzm + (lzM-lzm)/(nl-1)*i; plenv0(xm, xM, ym, yM, 2, 0); plcol0(15); pllab(xlab, ylab, title[alg-1]); plshades(zg, xp, yp, NULL, xm, xM, ym, yM, clev, nl, 1, 0, 1, plfill, 1, NULL, NULL); plcol0(2); } else { for (i=0; i<nl; i++) clev[i] = lzm + (lzM-lzm)/(nl-1)*i; cmap1_init(); plvpor(0.0, 1.0, 0.0, 0.9); plwind(-1.0, 1.0, -1.0, 1.5); /* * For the comparition to be fair, all plots should have the * same z values, but to get the max/min of the data generated * by all algorithms would imply two passes. Keep it simple. * * plw3d(1., 1., 1., xm, xM, ym, yM, zmin, zmax, 30, -60); */ plw3d(1., 1., 1., xm, xM, ym, yM, lzm, lzM, 30, -60); plbox3("bnstu", ylab, 0.0, 0, "bnstu", xlab, 0.0, 0, "bcdmnstuv", "", 0.0, 4); plcol0(15); pllab("", "", title[alg-1]); plot3dc(xg, yg, zg, xp, yp, DRAW_LINEXY | MAG_COLOR | BASE_CONT, clev, nl); } } } plend(); free_data(x, y, z); free_grid(xg, yg); free((void *)clev); plFree2dGrid(zg, xp, yp); }
int main(int argc, char *argv[]) { char buffer[30]; struct timeval tv; struct tm result; window_t *main_window = window_open(argv[1], true, true," ",0,720); if (!main_window) { printf("Cannot open main window.\n"); return 1; } time_t curtime; gettimeofday(&tv, NULL); curtime=tv.tv_sec; time_utc2tm(curtime,&result); strftime(buffer,30,"%T %m-%d-%Y",&result); pixel_t grd_bg = PIXEL(255, 25, 25, 112); pixel_t lbl_bg = PIXEL(255, 25, 25, 112);//(255, 240, 240, 240); pixel_t lbl_fg = PIXEL(255, 255, 255, 255); my_label_t *stime= create_my_label(NULL,buffer, 16, lbl_bg, lbl_fg); grid_t *grid = create_grid(window_root(main_window),1, 10, grd_bg); grid->add(grid, &stime->label.widget, 0, 7, 1, 2); window_resize(main_window,1024,60); window_exec(main_window); while(1){ gettimeofday(&tv, NULL); curtime=tv.tv_sec; time_utc2tm(curtime,&result); //Converting month to integer char month[5]; strftime(month,5,"%m",&result); char *mon; mon=month; int value=0; value=toInteger1(mon); switch(value){ case 0: strftime(buffer,30,"%T Jan-%d, %Y",&result); break; case 1: strftime(buffer,30,"%T Feb-%d, %Y",&result); break; case 2: strftime(buffer,30,"%T Mar-%d, %Y",&result); break; case 3: strftime(buffer,30,"%T Apr-%d, %Y",&result); break; case 4: strftime(buffer,30,"%T May-%d, %Y",&result); break; case 5: strftime(buffer,30,"%T Jun-%d, %Y",&result); break; case 6: strftime(buffer,30,"%T Jul-%d, %Y",&result); break; case 7: strftime(buffer,30,"%T Aug-%d, %Y",&result); break; case 8: strftime(buffer,30,"%T Sep-%d, %Y",&result); break; case 9: strftime(buffer,30,"%T Oct-%d, %Y",&result); break; case 10: strftime(buffer,30,"%T Nov-%d, %Y",&result); break; case 11: strftime(buffer,30,"%T Dec-%d, %Y",&result); break; } stime->label.rewrite(&stime->label.widget, (void *)buffer); } task_retval(0); async_manager(); return 0; }
void display_boards(void) { int startx, starty, width, height; int stat_width, stat_height; char players_grid[BOARD_SIZE][BOARD_SIZE]; int f, h = 0; char t; int i; stat_height= 5; stat_width=50; keypad(stdscr, TRUE); height = 3+BOARD_SIZE; width = 14+BOARD_SIZE; starty = (LINES - height) / 2; startx = (COLS - width) / 2; clear(); refresh(); player_win = newwin(height, width, starty, startx+20); box(player_win, 0, 0); wrefresh(player_win); opponent_win = newwin(height, width, starty, startx-20); box(opponent_win, 0, 0); wrefresh(opponent_win); status_win = newwin(stat_height, stat_width, starty+13, startx-20); create_grid(players_grid, Shipset); clear(); refresh(); mvprintw(starty-1, startx-15, global_user_name); mvwprintw(opponent_win, 1,1," A B C D E F G H I J"); wattron(opponent_win,COLOR_PAIR(2)); mvwprintw(opponent_win, 1, 1, " "); wattroff(opponent_win,COLOR_PAIR(2)); for (h = 0; h<BOARD_SIZE; h++) { mvwprintw(opponent_win, 2+h, 1,"%d|", h); for (f =0; f<BOARD_SIZE; f++) { t = players_grid[h][f]; if (t == '*') { wattron(opponent_win,COLOR_PAIR(2)); mvwprintw(opponent_win, 2+h,3+f*2, "%c", t); wattroff(opponent_win,COLOR_PAIR(2)); } else { mvwprintw(opponent_win, 2+h,3+f*2, "%c", t); } mvwprintw(opponent_win, 2+h,4+f*2, "|"); } } wrefresh(opponent_win); mvprintw(starty-1, startx+21, peer_user_name); mvwprintw(player_win,1,1," A B C D E F G H I J"); for (i=0;i<BOARD_SIZE;i++) { mvwprintw(player_win,i+2,1,"%d|_|_|_|_|_|_|_|_|_|_|",i+0); } refresh(); wrefresh(player_win); wrefresh(status_win); attroff(A_UNDERLINE); }
void Engine::init_scene() { Node* scene = nodes["scene"] = new Node(NULL); // shaders // // "simple_shader" shaders["simple_shader"] = make_shader("shaders/p_v.glsl", "shaders/unicolor_f.glsl"); // "light1" { Shader* shader = shaders["light1"] = make_shader("shaders/pn_v.glsl", "shaders/light1_f.glsl"); // TODO put uniforms in "material"-class or something? set_uniform(shader, "mycolor", glm::vec4(1.f)); set_uniform(shader, "ambient_intensity", glm::vec4(.1f,.1f,.1f,1.f)); set_uniform(shader, "diffuse_color", glm::vec4(.5f,.5f,.5f,1.f)); set_uniform(shader, "specular_color", glm::vec4(1.f,1.f,1.f,1.f)); set_uniform(shader, "atten_k", .04f); set_uniform(shader, "gauss_k", .1f); } // objects // // grid { Shader* shader = shaders["simple_shader"]; Node* node = nodes["grid"] = new Node(scene); int no = 5; glm::vec3 scale = glm::vec3(20.f); VAO* vao = create_grid(no, scale); std::vector<Uniform*> material; glm::vec4 white = glm::vec4(1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", white); material.push_back(mycolor); renderables.push_back( new BasicRenderObject(shader, node, vao, material)); // mem vaos.push_back(vao); uniforms.push_back(mycolor); } // redcube { Shader* shader = shaders["light1"]; Node* node = nodes["redcube"] = new Node(scene); node->position = glm::vec3(.5f,.5f,-1.7f); glm::vec3 scale = glm::vec3(.05f); VAO* vao = create_cube_with_normals(scale); std::vector<Uniform*> material; glm::vec4 red = glm::vec4(1.f,0.f,.5f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", red); material.push_back(mycolor); renderables.push_back( new LitRenderObject(shader, node, vao, material)); // physics btCollisionShape* cube_shape = new btBoxShape(from_vec3(scale/2.f)); float mass = 0.f; redcube_rb = create_rigid_body(mass, node, cube_shape); physics->add_rigid_body(redcube_rb); // mem vaos.push_back(vao); uniforms.push_back(mycolor); collision_shapes.push_back(cube_shape); } make_litcube("cyancube", glm::vec4(0.f, 1.f, 1.f, 1.f), glm::vec3(0.05f)); nodes["cyancube"]->orientation = glm::angleAxis(glm::radians(45.f), glm::normalize(glm::vec3(-1.f, 1.f, 1.f))); make_litcube("yellowcube", glm::vec4(1.f, 1.f, 0.f, 1.f), glm::vec3(0.05f)); nodes["yellowcube"]->orientation = nodes["cyancube"]->orientation; make_litcube("bluecube", glm::vec4(0.f, 0.f, 1.f, 1.f), glm::vec3(1.f), 30.f, glm::vec3(0.f, 1.5f, -5.f)); // lightcube { Shader* shader = shaders["simple_shader"]; Node* node = nodes["lightcube"] = new Node(scene); node->position = glm::vec3(0.f, 1.f, 0.f); glm::vec3 scale = glm::vec3(.3f,.3f,.3f); VAO* vao = create_cube(scale); std::vector<Uniform*> material; glm::vec4 white = glm::vec4(1.f,1.f,1.f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", white); material.push_back(mycolor); renderables.push_back( new BasicRenderObject(shader, node, vao, material)); // sync point light with position PointLight light0(node, glm::vec4(.7f,.7f,.7f,1.f)); set_uniform(shaders["light1"], "light.position", glm::vec3(light0.get_position())); set_uniform(shaders["light1"], "light.intensity", light0.get_intensity()); // mem vaos.push_back(vao); uniforms.push_back(mycolor); } // plane { Shader* shader = shaders["light1"]; Node* node = nodes["plane"] = new Node(scene); node->position = glm::vec3(0.f, -.5f, 0.f); glm::vec3 scale = glm::vec3(20.f, 1.f, 20.f); VAO* vao = create_cube_with_normals(scale); std::vector<Uniform*> material; glm::vec4 goldish = glm::vec4(1.f,1.f,0.f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", goldish); material.push_back(mycolor); renderables.push_back( new LitRenderObject(shader, node, vao, material)); // physics btCollisionShape* shape = new btBoxShape(from_vec3(scale/2.f)); float mass = 0.f; btRigidBody* rigid_body = create_rigid_body(mass, node, shape); physics->add_rigid_body(rigid_body); // mem uniforms.push_back(mycolor); vaos.push_back(vao); collision_shapes.push_back(shape); } // bound { Shader* shader = shaders["light1"]; Node* node = nodes["bound"] = new Node(scene); glm::vec3 scale = glm::vec3(20.f); bool face_inward = true; VAO* vao = create_cube_with_normals(scale, face_inward); std::vector<Uniform*> material; glm::vec4 greenblueish = glm::vec4(0.f,1.f,1.f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", greenblueish); material.push_back(mycolor); renderables.push_back( new LitRenderObject(shader, node, vao, material)); // mem vaos.push_back(vao); uniforms.push_back(mycolor); } // roboarm { nodes["roboarm0"] = new Node(scene); nodes["roboarm1"] = new Node(scene); nodes["roboarm2"] = new Node(scene); nodes["roboarm3"] = new Node(scene); glm::vec3 scale = glm::vec3(0.1f, 0.4f, 0.1f); nodes["roboarm0"]->position = glm::vec3(0.f, 1.f, -2.f); //nodes["roboarm0"]->orientation = // glm::angleAxis(glm::radians(180.f), glm::vec3(1.f, 0.f, 0.f)); nodes["roboarm1"]->position = nodes["roboarm0"]->position + nodes["roboarm0"]->orientation * glm::vec3(0.f, scale.y, 0.f); nodes["roboarm1"]->orientation = nodes["roboarm0"]->orientation; nodes["roboarm2"]->position = nodes["roboarm1"]->position + nodes["roboarm1"]->orientation * glm::vec3(0.f, scale.y, 0.f); nodes["roboarm2"]->orientation = nodes["roboarm1"]->orientation; nodes["roboarm3"]->position = nodes["roboarm2"]->position + nodes["roboarm2"]->orientation * glm::vec3(0.f, scale.y, 0.f); nodes["roboarm3"]->orientation = nodes["roboarm2"]->orientation; // render { Shader* shader = shaders["light1"]; glm::vec4 black = glm::vec4(0.f,0.f,0.f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", black); std::vector<Uniform*> material; material.push_back(mycolor); // TODO use rounder shapes... VAO* vao = create_cube_with_normals(scale); auto make_renderable = [&shader, &material, &vao] (Node* node) { return new LitRenderObject(shader, node, vao, material); }; renderables.insert(renderables.end(), { make_renderable(nodes["roboarm0"]), make_renderable(nodes["roboarm1"]), make_renderable(nodes["roboarm2"]), make_renderable(nodes["roboarm3"]), } ); // mem uniforms.push_back(mycolor); vaos.push_back(vao); } btCollisionShape *shape = new btBoxShape(from_vec3(scale/2.f)); float density = 1000.f, volume = scale.x * scale.y * scale.z, mass = density * volume; // mem collision_shapes.push_back(shape); btRigidBody *rb0 = create_rigid_body(0.f, nodes["roboarm0"], shape), *rb1 = create_rigid_body(mass, nodes["roboarm1"], shape), *rb2 = create_rigid_body(mass, nodes["roboarm2"], shape), *rb3 = create_rigid_body(mass, nodes["roboarm3"], shape); rb1->setActivationState(DISABLE_DEACTIVATION); rb2->setActivationState(DISABLE_DEACTIVATION); rb3->setActivationState(DISABLE_DEACTIVATION); physics->add_rigid_body(rb0); physics->add_rigid_body(rb1); physics->add_rigid_body(rb2); physics->add_rigid_body(rb3); btMatrix3x3 rot; rot.setIdentity(); btTransform trans_up(rot, btVector3(0.f, scale.y/2, 0.f)), trans_down(rot, btVector3(0.f, -scale.y/2, 0.f)); rc1 = new btHingeConstraint(*rb0, *rb1, trans_up, trans_down); rc2 = new btHingeConstraint(*rb1, *rb2, trans_up, trans_down); rc3 = new btHingeConstraint(*rb2, *rb3, trans_up, trans_down); float pi = glm::pi<float>(); rc1->setLimit(-pi/2, pi/2); rc2->setLimit(-pi/2, pi/2); rc3->setLimit(-pi/2, pi/2); bool intercollision = false; physics->add_constraint(rc1, intercollision); physics->add_constraint(rc2, intercollision); physics->add_constraint(rc3, intercollision); roboarm0 = new KinematicChain(nullptr, rb0, nullptr); roboarm1 = new KinematicChain(roboarm0, rb1, rc1); roboarm2 = new KinematicChain(roboarm1, rb2, rc2); roboarm3 = new KinematicChain(roboarm2, rb3, rc3); } }
maze(std::size_t x, std::size_t y):m_grid(create_grid(x, y)), m_barrier_grid(create_barrier_grid()) {};
void modify_grid(grid *gridp) { create_grid(gridp, &gridp->gmatrix.v.fvec, &gridp->gmatrix.v.rvec, &gridp->center, gridp->nrows, gridp->ncols, gridp->square_size); }
int main(int argc, char** argv) { char c; unsigned width_override = 0; unsigned height_override = 0; unsigned window_width = 512; unsigned window_height = 512; unsigned long time_generations = 0; view.fullscreen = true; DEBUG("Initializing GLUT\n"); glutInit (&argc, argv); glutInitDisplayMode (GLUT_RGBA); while ((c = getopt_long(argc, argv, "w:s:hft:", longopts, NULL)) != -1) { switch (c) { case 's': sscanf(optarg, "%ux%u\n", &width_override, &height_override); break; case 'w': sscanf(optarg, "%ux%u\n", &window_width, &window_height); break; case 'f': view.fullscreen = true; break; case 't': time_generations = strtoul(optarg, NULL, 10); break; case 'h': default: usage(argv[0]); } } argc -= optind; argv += optind; atexit(cleanup); init_parallel_component(); compute_params.generations_per_redraw = 0.05; create_window(window_width, window_height); uint8_t* data = NULL; unsigned width = width_override ? width_override : 128; unsigned height = height_override ? height_override : 128; if (argc >= 1) { const char* filename = argv[0]; DEBUG("Filename argument \"%s\" given\n", filename); unsigned __width, __height; data = read_file(filename, &__width, &__height, width_override, height_override); if (data != NULL) { width = __width; height = __height; } } create_grid(width, height, data); if (time_generations) { struct timeval t1, t2; gettimeofday(&t1, NULL); DEBUG("Timing how long it takes to advance %lu generations\n", time_generations); advance_generations(time_generations); gettimeofday(&t2, NULL); unsigned long us_elapsed = (t2.tv_sec * 1000000 + t2.tv_usec) - (t1.tv_sec * 1000000 + t1.tv_usec); printf("%lu milliseconds elapsed\n", us_elapsed / 1000); } else { reset_view(); glutMainLoop(); } return 0; }