void update_shapes(void){ /* Select the random shape */ int r = rand()%4; /* Get random values */ vec2 randoms = random_ints(); GLfloat x_r = randoms.x; GLfloat y_r = randoms.y; /* Update coordinates holded shape */ hold_shape->x_origin = ROBOT_X_ORIGIN + x_r; hold_shape->y_origin = ROBOT_Y_ORIGIN + y_r; hold_shape->update = update_shape; /* Get new random values */ randoms = random_ints(); x_r = randoms.x; y_r = randoms.y; /* Update hold shape */ hold_shape = shapes[r][0].model; hold_shape->update = update_holded; /* Update true shape */ true_shape = shapes[r][1].model; true_shape->x_origin = ROBOT_X_ORIGIN + x_r; true_shape->y_origin = ROBOT_Y_ORIGIN + y_r; /* Update colors */ update_colors(); }
void handle_init(void) { load_config(); srand((uint32_t) time(NULL)); window = window_create(); window_stack_push(window, true); Layer *window_layer = window_get_root_layer(window); text_layer = text_layer_create(GRect(0, -2, 144, 168)); text_layer_set_background_color(text_layer, GColorClear); text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_layer, text_layer_get_layer(text_layer)); update_colors(); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); handle_minute_tick(NULL, MINUTE_UNIT); app_message_register_inbox_received(in_received_handler); const uint32_t inbound_size = 64; const uint32_t outbound_size = 64; app_message_open(inbound_size, outbound_size); }
void handle_set_settings(DictionaryIterator *received) { Tuple *color_tuple = dict_find(received, KEY_COLOR); if (color_tuple) { config_color = color_tuple->value->uint8; update_colors(); } }
/** Initializes the time object. This should happen when the MUD boots. * Since the time object is used to keep track of uptime, updating * it and reloading it will have a similar effect to resetting the uptime. */ void create() { debug("loading time daemon..."); update_colors(); boot_time = "/secure/master"->query_hold_var(); if( !boot_time ) boot_time = time(); debug(" boot_time = "+boot_time); call_out("update_colors", query_time_until_hour() ); load_object("/daemon/playerwipe"); load_object("/daemon/escheat"); set_heart_beat( 1 ); }
void ColorMapEditor::paintGL () { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (colors_need_update) { update_colors(); colors_need_update = false; } //draw scale int scale_delta = 8; //while( scale_delta / 255.0 * height() * zoom < 20 ) scale_delta++; glColor4f(0,0,0,0.5); for(size_t i = 0; i < resolution; i += scale_delta) { glBegin(GL_LINES); glVertex2f( i/(float)resolution , 0); glVertex2f( i/(float)resolution , 1); glEnd(); } glEnable(GL_LINE_SMOOTH); //draw function double res = resolution; glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D,color_tex); glBegin(GL_QUADS); glTexCoord1d( 0.5 / (res-1.0) ); glVertex2d ( 0, 0 ); glVertex2d ( 0, 1 ); glTexCoord1d( 0.5 / (res-1.0) + (res-1.0)/res ); glVertex2d ( 1, 1 ); glVertex2d ( 1, 0 ); glEnd(); glDisable(GL_TEXTURE_1D); glColor3f(0,0,0); glLineWidth(2); draw_channel(channel); }
/** * This function minimizes the given automaton. Note * that it must be deterministic. For more information, * see comments in this library's .h file. */ void elag_minimize(SingleGraph automaton,int level) { struct list_int* initials=get_initial_states(automaton); if (initials==NULL) { /* No initial state should mean 'empty automaton' */ if (automaton->number_of_states!=0) { /* If not, we fail */ fatal_error("No initial state in non empty automaton in elag_minimize\n"); } return; } if (initials->next!=NULL) { fatal_error("Non-deterministic automaton in elag_minimize\n"); } free_list_int(initials); if (level>0) { /* If necessary, we remove transitions that are included in the * default ones */ compact_default_transitions(automaton); } SymbolAlphabet* alph=build_symbol_alphabet(automaton); TransitionCollection** transitions=build_transition_collections(automaton,alph); /* Now that we have numbered transitions, we don't need the symbol * alphabet anymore */ free_SymbolAlphabet(alph); int nbColors; int nbShades; int* color=(int*)calloc(automaton->number_of_states,sizeof(int)); if (color==NULL) { fatal_alloc_error("elag_minimize"); } int* shade=init_colors(automaton,&nbShades); do { int s; /* We copy the shades into the color array */ for (s=0;s<automaton->number_of_states;s++) { color[s]=shade[s]; } nbColors=nbShades; nbShades=0; /* We update the colors of the transitions' destination states */ update_colors(transitions,color,automaton->number_of_states); /* Now, for each state #s, we look for its shade, comparing it with * all the states #i so that i<s */ for (s=0;s<automaton->number_of_states;s++) { shade[s]=get_shade(s,transitions,color,shade,&nbShades); } /* We stop when no more shades have been introduced */ } while (nbColors!=nbShades); int* chosen=choose_states(color,nbColors,automaton->number_of_states); for (int i=0;i<automaton->number_of_states;i++) { free_TransitionCollection(transitions[i]); } free(transitions); free(shade); /* We allocate the resulting automaton */ SingleGraph result=new_SingleGraph(nbColors,PTR_TAGS); for (int c=0;c<nbColors;c++) { SingleGraphState state=add_state(result); SingleGraphState original=automaton->states[chosen[c]]; /* We set the initiality and finality of the state */ state->control=original->control; state->outgoing_transitions=original->outgoing_transitions; original->outgoing_transitions=NULL; /* We renumber the transitions' destination states */ for (Transition* t1=state->outgoing_transitions;t1!=NULL;t1=t1->next) { t1->state_number=color[t1->state_number]; } state->default_state=original->default_state; } /* Now we have to replace the old automaton by the new one */ move_SingleGraph(automaton,&result,free_symbol); /* And we don't need these arrays anymore */ free(color); free(chosen); }
void init_mandelbrot(struct mandelbrot_param *param) { // Initialize the picture container, but not its buffer param->picture = ppm_alloc(0, 0); param->picture->height = param->height; param->picture->width = param->width; #if GLUT != 1 // GLUT will do it when creating or resizing its window init_ppm(param); #endif // initialize the color vector update_colors(param); #if NB_THREADS > 0 // Thread-based variant pthread_attr_t thread_attr; int i; // Initialise thread poll / master thread synchronisation pthread_barrier_init(&thread_pool_barrier, NULL, NB_THREADS + 1); pthread_barrier_init(&thread_para_barrier, NULL, NB_THREADS); // Initialize attributes pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); // Enables thread running thread_stop = 0; #ifdef MEASURE // Measuring record structures timing = malloc(sizeof(struct timing*) * NB_THREADS); #endif // Create a thread pool for (i = 0; i < NB_THREADS; i++) { thread_data[i].id = i; #ifdef MEASURE timing[i] = &thread_data[i].timing; #endif // Check the good behavior or pthread_create; must be disabled while measuring for performance reasons #ifdef DEBUG assert(pthread_create(&thread[i], &thread_attr, &run_thread, &thread_data[i]) == 0); #else pthread_create(&thread[i], &thread_attr, &run_thread, &thread_data[i]); #endif } // Wait for the thread to be fully spawned before returning pthread_barrier_wait(&thread_pool_barrier); #else #ifdef MEASURE // Measuring record structures timing = malloc(sizeof(struct timing*)); timing[0] = &sequential; #endif #endif }
int vect_to_rast(const char *vector_map, const char *raster_map, const char *field_name, const char *column, int cache_mb, int use, double value, int value_type, const char *rgbcolumn, const char *labelcolumn, int ftype, char *where, char *cats, int dense) { struct Map_info Map; struct line_pnts *Points; int i, field; struct cat_list *cat_list = NULL; int fd; /* for raster map */ int nareas, nlines; /* number of converted features */ int nareas_all, nplines_all; /* number of all areas, points/lines */ int stat; int format; int pass, npasses; /* Attributes */ int nrec; int ctype = 0; struct field_info *Fi; dbDriver *Driver; dbCatValArray cvarr; int is_fp = 0; nareas = 0; G_verbose_message(_("Loading data...")); Vect_set_open_level(2); if (Vect_open_old2(&Map, vector_map, "", field_name) < 0) G_fatal_error(_("Unable to open vector map <%s>"), vector_map); field = Vect_get_field_number(&Map, field_name); if (field > 0) cat_list = Vect_cats_set_constraint(&Map, field, where, cats); if ((use == USE_Z) && !(Vect_is_3d(&Map))) G_fatal_error(_("Vector map <%s> is not 3D"), Vect_get_full_name(&Map)); switch (use) { case USE_ATTR: db_CatValArray_init(&cvarr); if (!(Fi = Vect_get_field(&Map, field))) G_fatal_error(_("Database connection not defined for layer <%s>"), field_name); if ((Driver = db_start_driver_open_database(Fi->driver, Fi->database)) == NULL) G_fatal_error(_("Unable to open database <%s> by driver <%s>"), Fi->database, Fi->driver); db_set_error_handler_driver(Driver); /* Note do not check if the column exists in the table because it may be expression */ if ((nrec = db_select_CatValArray(Driver, Fi->table, Fi->key, column, NULL, &cvarr)) == -1) G_fatal_error(_("Column <%s> not found"), column); G_debug(3, "nrec = %d", nrec); ctype = cvarr.ctype; if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE) G_fatal_error(_("Column type (%s) not supported (did you mean 'labelcolumn'?)"), db_sqltype_name(ctype)); if (nrec < 0) G_fatal_error(_("No records selected from table <%s>"), Fi->table); G_debug(1, "%d records selected from table", nrec); db_close_database_shutdown_driver(Driver); for (i = 0; i < cvarr.n_values; i++) { if (ctype == DB_C_TYPE_INT) { G_debug(3, "cat = %d val = %d", cvarr.value[i].cat, cvarr.value[i].val.i); } else if (ctype == DB_C_TYPE_DOUBLE) { G_debug(3, "cat = %d val = %f", cvarr.value[i].cat, cvarr.value[i].val.d); } } switch (ctype) { case DB_C_TYPE_INT: format = CELL_TYPE; break; case DB_C_TYPE_DOUBLE: format = DCELL_TYPE; break; default: G_fatal_error(_("Unable to use column <%s>"), column); break; } break; case USE_CAT: format = CELL_TYPE; break; case USE_VAL: format = value_type; break; case USE_Z: format = DCELL_TYPE; is_fp = 1; break; case USE_D: format = DCELL_TYPE; break; default: G_fatal_error(_("Unknown use type: %d"), use); } fd = Rast_open_new(raster_map, format); Points = Vect_new_line_struct(); if (use != USE_Z && use != USE_D && (ftype & GV_AREA)) { if ((nareas = sort_areas(&Map, Points, field, cat_list)) == 0) G_warning(_("No areas selected from vector map <%s>"), vector_map); G_debug(1, "%d areas sorted", nareas); } if (nareas > 0 && dense) { G_warning(_("Area conversion and line densification are mutually exclusive, disabling line densification.")); dense = 0; } nlines = Vect_get_num_primitives(&Map, ftype); nplines_all = nlines; npasses = begin_rasterization(cache_mb, format, dense); pass = 0; nareas_all = Vect_get_num_areas(&Map); do { pass++; if (npasses > 1) G_message(_("Pass %d of %d:"), pass, npasses); stat = 0; if ((use != USE_Z && use != USE_D) && nareas) { if (do_areas (&Map, Points, &cvarr, ctype, use, value, value_type) < 0) { G_warning(_("Problem processing areas from vector map <%s>, continuing..."), vector_map); stat = -1; break; } } if (nlines) { if ((nlines = do_lines(&Map, Points, &cvarr, ctype, field, cat_list, use, value, value_type, ftype, &nplines_all, dense)) < 0) { G_warning(_("Problem processing lines from vector map <%s>, continuing..."), vector_map); stat = -1; break; } } G_important_message(_("Writing raster map...")); stat = output_raster(fd); } while (stat == 0); G_suppress_warnings(0); /* stat: 0 == repeat; 1 == done; -1 == error; */ Vect_destroy_line_struct(Points); if (stat < 0) { Rast_unopen(fd); return 1; } Vect_close(&Map); G_verbose_message(_("Creating support files for raster map...")); Rast_close(fd); update_hist(raster_map, vector_map, Map.head.orig_scale); /* colors */ if (rgbcolumn) { if (use != USE_ATTR && use != USE_CAT) { G_warning(_("Color can be updated from database only if use=attr")); update_colors(raster_map); } else { update_dbcolors(raster_map, vector_map, field, rgbcolumn, is_fp, column); } } else if (use == USE_D) update_fcolors(raster_map); else update_colors(raster_map); update_cats(raster_map); /* labels */ update_labels(raster_map, vector_map, field, labelcolumn, use, value, column); #if 0 /* maximum possible numer of areas: number of centroids * actual number of areas, currently unknown: * number of areas with centroid that are within cat constraint * and overlap with current region */ if (nareas_all > 0) G_message(_("Converted areas: %d of %d"), nareas, Vect_get_num_primitives(&Map, GV_CENTROID)); /* maximum possible numer of lines: number of GV_LINE + GV_POINT * actual number of lines, currently unknown: * number of lines are within cat constraint * and overlap with current region */ if (nlines > 0 && nplines_all > 0) G_message(_("Converted points/lines: %d of %d"), nlines, nplines_all); #endif return 0; }
bool cursor_t::cursorFromFile(image_t const &image) { unsigned short cc_size = 4; unsigned short c_idx = 0; unsigned short *colors_count = (unsigned short *) calloc (cc_size, sizeof(unsigned short)); unsigned short row = 0; unsigned short column = 0; unsigned short const *pm; unsigned char const *alp; unsigned short col_bytes; colors = (unsigned short *) calloc (cc_size, sizeof(unsigned short)); if(height > image.height_) height = image.height_; if(width > image.width_) width = image.width_; cursor_size = (height * width * modes[mode].bpp)/8; cursor_data = (unsigned char *) calloc(cursor_size, sizeof(unsigned short)); pm = (unsigned short *) image.pixData_; alp = (unsigned char *) image.alpha_; col_bytes = (width * modes[mode].bpp)/8; /* * use alpha only if mode supports transparency and calculate * color occurance. */ for(row = 0; row < height; row++) { unsigned char *row_data = cursor_data + (row * col_bytes); for(column = 0; column < width; column++) { if(alp && alp[row * height + column] <= 128 && modes[mode].transparency != -1) SET_COLOR(row_data,column,modes[mode].bpp,modes[mode].transparency); else update_colors(colors_count, c_idx, cc_size, pm[row*height+column]); } } find_4colors(colors_count, c_idx); free(colors_count); for(row = 0; row < height; row++) { unsigned char *row_data = cursor_data + (row * col_bytes); for(column = 0; column < width; column++) { unsigned short idx = 0; unsigned short chosen = 0; unsigned short min = 65535; for(idx = 0; idx < modes[mode].color_count; idx++) { unsigned short diff = (unsigned short) abs(pm[row*height+column] - colors[idx]); if(min > diff) { min = diff; chosen = idx; } } if(!alp || alp[row * height + column] > 128) SET_COLOR(row_data,column,modes[mode].bpp,chosen); } } return true; }
/* Init the models */ void init(void){ /* Create the robot base */ Model* base = new_cube(ROBOT_X_ORIGIN, ROBOT_Y_ORIGIN, ROBOT_Z_ORIGIN, update_base); models.push_back(base); /* Create the lower arm */ Model* lower_arm = new_cube(ROBOT_X_ORIGIN, ROBOT_Y_ORIGIN, ROBOT_Z_ORIGIN, update_lower_arm); models.push_back(lower_arm); /* Create the upper arm */ Model* upper_arm = new_cube(ROBOT_X_ORIGIN, ROBOT_Y_ORIGIN, ROBOT_Z_ORIGIN, update_upper_arm); models.push_back(upper_arm); /* Create the first shapes */ for(int i=0;i<SHAPE_SIZE;i++){ Model* m = new_shape(i); models.push_back(m); shape_t s; s.model = m; shapes[i].push_back(s); } /* Create the second shapes */ for(int i=0;i<SHAPE_SIZE;i++){ Model* m = new_shape(i); models.push_back(m); shape_t s; s.model = m; shapes[i].push_back(s); } /* Update colors as random */ update_colors(); /* Select the hold and true shape */ hold_shape = shapes[0][0].model; hold_shape->update = update_holded; true_shape = shapes[0][1].model; /* Init the all models */ for(list<Model*>::iterator i = models.begin();i != models.end();i++){ (*i)->point_init(); (*i)->apply_material(diffuse, ambient, specular, shininess); (*i)->lightp = light_p; } /* Init the view matrix */ view = LookAt(eye_point, look_at_point, vec3(0.0,1.0,0.0)); view *= RotateX(ROTATE_X); view *= RotateY(ROTATE_Y); projection = Perspective(fovy, aspect, z_near, z_far); /* Enable some features */ glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glClearDepth(1.0); glEnable(GL_MULTISAMPLE); glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0, 0, 0, 0); /* Init the clock */ past = clock(); }