Advertisement
Guest User

Untitled

a guest
Mar 8th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. /*********************************al_draw_star.h*********************************/
  2. #include <allegro5/allegro_primitives.h>
  3. #include <math.h>
  4. #define PI 3.14159265358979323846264338327950288419716939937510582
  5. int al_draw_star(float x, float y, float r, int s, ALLEGRO_COLOR color, float thickness);
  6.  
  7. /*********************************al_draw_star.c*********************************/
  8.  
  9. #include "al_draw_star.h"
  10.  
  11. int al_draw_star(float x, float y, float r, int s, ALLEGRO_COLOR color, float thickness)
  12. {
  13.     int i = -90;
  14.     do
  15.     {
  16.         float x1=x+(r*cos(i*(PI/180)));
  17.         float y1=y+(r*sin(i*(PI/180)));
  18.         float x2=x+((r/2)*cos((i+360/s/2)*(PI/180)));
  19.         float y2=y+((r/2)*sin((i+360/s/2)*(PI/180)));
  20.         al_draw_line(x1, y1, x2, y2, color, thickness);
  21.         x1=x+((r/2)*cos((i+360/s/2)*(PI/180)));
  22.         y1=y+((r/2)*sin((i+360/s/2)*(PI/180)));
  23.         x2=x+(r*cos((i+360/s)*(PI/180)));
  24.         y2=y+(r*sin((i+360/s)*(PI/180)));
  25.         al_draw_line(x1, y1, x2, y2, color, thickness);
  26.         i+=360/s;
  27.     } while(i<270);
  28. }
  29.  
  30. /*********************************example.c*********************************/
  31.  
  32. #include <stdio.h>
  33. #include <allegro5/allegro.h>
  34. #include <stdlib.h>
  35. #include "al_draw_star.h"
  36. const float FPS = 60;
  37. const int SCREEN_W = 640;
  38. const int SCREEN_H = 480;
  39. int main()
  40. {
  41.     ALLEGRO_DISPLAY *display = NULL;
  42.     ALLEGRO_EVENT_QUEUE *event_queue = NULL;
  43.     ALLEGRO_TIMER *timer = NULL;
  44.     bool redraw = true;
  45.     al_init();
  46.     al_init_primitives_addon();
  47.     al_install_mouse();
  48.     timer = al_create_timer(1.0 / FPS);
  49.     display = al_create_display(SCREEN_W, SCREEN_H);
  50.     al_clear_to_color(al_map_rgb(255, 0, 255));
  51.     al_set_target_bitmap(al_get_backbuffer(display));
  52.     event_queue = al_create_event_queue();
  53.     al_register_event_source(event_queue, al_get_display_event_source(display));
  54.     al_register_event_source(event_queue, al_get_timer_event_source(timer));
  55.     al_register_event_source(event_queue, al_get_mouse_event_source());
  56.     al_clear_to_color(al_map_rgb(0,0,0));
  57.     al_flip_display();
  58.     al_start_timer(timer);
  59.     while(1)
  60.     {
  61.         ALLEGRO_EVENT ev;
  62.         al_wait_for_event(event_queue, &ev);
  63.         if(ev.type == ALLEGRO_EVENT_TIMER)
  64.         {
  65.             redraw = true;
  66.         }
  67.         else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
  68.         {
  69.             break;
  70.         }
  71.         if(redraw && al_is_event_queue_empty(event_queue))
  72.         {
  73.             redraw = false;
  74.             al_clear_to_color(al_map_rgb(0,0,0));
  75.             al_draw_star(300, 300, 100, 5,al_map_rgb(255,255,255),3);
  76.             al_flip_display();
  77.         }
  78.     }
  79.     al_destroy_timer(timer);
  80.     al_destroy_display(display);
  81.     al_destroy_event_queue(event_queue);
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement