Ejemplo n.º 1
0
ALLEGRO_BITMAP *generate_triangle_bitmap(float x1, float y1, float x2, float y2, float x3, float y3, ALLEGRO_COLOR col)
{
   // find the width and height of the bitmap (this could be more comprehensive? What about -negative points?)
   float max_x = std::max(std::max(x1, x2), x2);
   float max_y = std::max(std::max(y1, y2), y3);

   // start drawing
   ALLEGRO_BITMAP *surface = al_create_bitmap(max_x, max_y);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_clear_to_color(color::transparent);
   al_set_target_bitmap(surface);

   // build our triangle
   ALLEGRO_VERTEX v[3];
   v[0] = build_vertex(x1, y1, 0, col, 0, 0);
   v[1] = build_vertex(x2, y2, 0, col, 0, 0);
   v[2] = build_vertex(x3, y3, 0, col, 0, 0);

   // draw the triangle
   al_draw_prim(v, NULL, NULL, 0, 3, ALLEGRO_PRIM_TRIANGLE_LIST);

   // restore drawing state
   al_restore_state(&state);
   return surface;
}
Ejemplo n.º 2
0
ALLEGRO_BITMAP *generate_gradient_bitmap(float size, ALLEGRO_COLOR top_color, ALLEGRO_COLOR bottom_color, int padding)
{
   // set everything up for rendering
   int w = size;
   int h = size;
   ALLEGRO_BITMAP *surface = al_create_bitmap(w, h);
   ALLEGRO_STATE previous_state;
   al_store_state(&previous_state, ALLEGRO_STATE_TARGET_BITMAP);

   // start drawing on the bitmap
   al_set_target_bitmap(surface);
   al_clear_to_color(color::transparent);

   // build the gradient as a primitive
   ALLEGRO_VERTEX v[4];
   v[0] = build_vertex(0+padding, 0+padding, 0, top_color, 0, 0);
   v[1] = build_vertex(w-padding, 0+padding, 0, top_color, 0, 0);
   v[2] = build_vertex(w-padding, h-padding, 0, bottom_color, 0, 0);
   v[3] = build_vertex(0+padding, h-padding, 0, bottom_color, 0, 0);

   // draw it to the surface
   al_draw_prim(v, NULL, NULL, 0, 4, ALLEGRO_PRIM_TRIANGLE_FAN);

   // restore everything back to where it was
   al_restore_state(&previous_state);

   // return the generated image
   return surface; 
}
int graph_build_vertices_edges (struct graph_list** my_graph, char* filename) {
    FILE* fp;
    fp = fopen(filename, "r");
    if (fp != NULL) {
        printf("the transit file has been opened, oh yeah...\n");
    } else {
        printf("nope, can't open file.  Nice try though");
    }
    int trip_id = 0;
    char arrival_time[30];
    char departure_time[30];
    int stop_id = 0;
    int stop_seq = 0;
    float shape_dist_traveled = 0;
    int got = 0;
    long file_pos = 0;
    char first_letter;
    struct vertex_storage* vertices = build_vertex_storage();
    if (vertices == NULL) {
        printf("storage couldn't be built");
        fclose(fp);
        return 0;
    } else {
        
        while((first_letter = getc(fp)) != '\n') {
        }; //advances the pointer to the first character of the second line
        unsigned long line_number = 1;
        
        struct vertex* previous_vertex = NULL;
        float previous_dist_traveled = 0;
        struct vertex* current_vertex = NULL;
        float current_dist_traveled = 0;
        
        for (unsigned long i = 0; i < 1476913; i++) { //this is the last line of the san antonio bus file, need to fix to stop at EOF
            line_number++;
            got = fscanf(fp, "%d,%[^,],%[^,],%d,%d,,,,", &trip_id, arrival_time, departure_time, &stop_id, &stop_seq);
            if (got != 5) {
                printf("error reading file at line %lu", i);
                return 0;
                //now we need to back up
            } else {
                file_pos = ftell(fp);
                if ((first_letter = getc(fp)) == '\r') {
                    shape_dist_traveled = 0.000;
                } else {
                    fseek(fp, file_pos, SEEK_SET);
                    got = fscanf(fp, "%f\n", &shape_dist_traveled);
                    if (got != 1) {
                        //printf("error reading distance traveled at line &d\n", i);
                        return 0;
                    }
                }
            }
            
            if ((i == 0) || (stop_seq == 1)) { //this is the first line of the document and there is no previous vertex, and perhaps I need to check if the sequence is 1
                previous_vertex = build_vertex(stop_id, 0, 0, 0);
                previous_dist_traveled = shape_dist_traveled;
            } else {
                current_vertex = build_vertex(stop_id, 0, 0, 0); //build the vertex from the line, and store it in current
                current_dist_traveled = shape_dist_traveled;
                //now we need to try to add the edge made up of previous_vertex and current_vertex
                struct edge* new_edge = build_edge(previous_vertex, current_vertex, current_dist_traveled - previous_dist_traveled, trip_id); //the edge has been successfully created
                if (new_edge != NULL) {
                    if(graph_add_edge(new_edge, my_graph) == 1) {
                        previous_vertex = current_vertex;
                        previous_dist_traveled = current_dist_traveled;
                    } else {
                        printf("failed to add to graph\n");
                    }
                } else {
                    printf("new edge not created\n");
                }
            }
            
        }
    }
    fclose(fp);
    return 1;
}