Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************al_draw_star.h*********************************/
- #include <allegro5/allegro_primitives.h>
- #include <math.h>
- #define PI 3.14159265358979323846264338327950288419716939937510582
- int al_draw_star(float x, float y, float r, int s, ALLEGRO_COLOR color, float thickness);
- /*********************************al_draw_star.c*********************************/
- #include "al_draw_star.h"
- int al_draw_star(float x, float y, float r, int s, ALLEGRO_COLOR color, float thickness)
- {
- int i = 0;
- do
- {
- float y1=y-(r*cos(i*(PI/180)));
- float x1=x+(r*sin(i*(PI/180)));
- float y2=y-((r/2)*cos((i+360/s/2)*(PI/180)));
- float x2=x+((r/2)*sin((i+360/s/2)*(PI/180)));
- al_draw_line(x1, y1, x2, y2, color, thickness);
- y1=y-((r/2)*cos((i+360/s/2)*(PI/180)));
- x1=x+((r/2)*sin((i+360/s/2)*(PI/180)));
- y2=y-(r*cos((i+360/s)*(PI/180)));
- x2=x+(r*sin((i+360/s)*(PI/180)));
- al_draw_line(x1, y1, x2, y2, color, thickness);
- i+=360/s;
- } while(i<360);
- }
- /*********************************example.c*********************************/
- #include <stdio.h>
- #include <allegro5/allegro.h>
- #include <stdlib.h>
- #include "al_draw_star.h"
- const float FPS = 60;
- const int SCREEN_W = 640;
- const int SCREEN_H = 480;
- int main()
- {
- ALLEGRO_DISPLAY *display = NULL;
- ALLEGRO_EVENT_QUEUE *event_queue = NULL;
- ALLEGRO_TIMER *timer = NULL;
- bool redraw = true;
- al_init();
- al_init_primitives_addon();
- al_install_mouse();
- timer = al_create_timer(1.0 / FPS);
- display = al_create_display(SCREEN_W, SCREEN_H);
- al_clear_to_color(al_map_rgb(255, 0, 255));
- al_set_target_bitmap(al_get_backbuffer(display));
- event_queue = al_create_event_queue();
- al_register_event_source(event_queue, al_get_display_event_source(display));
- al_register_event_source(event_queue, al_get_timer_event_source(timer));
- al_register_event_source(event_queue, al_get_mouse_event_source());
- al_clear_to_color(al_map_rgb(0,0,0));
- al_flip_display();
- al_start_timer(timer);
- while(1)
- {
- ALLEGRO_EVENT ev;
- al_wait_for_event(event_queue, &ev);
- if(ev.type == ALLEGRO_EVENT_TIMER)
- {
- redraw = true;
- }
- else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
- {
- break;
- }
- if(redraw && al_is_event_queue_empty(event_queue))
- {
- redraw = false;
- al_clear_to_color(al_map_rgb(0,0,0));
- al_draw_star(300, 300, 100, 5,al_map_rgb(255,255,255),3);
- al_flip_display();
- }
- }
- al_destroy_timer(timer);
- al_destroy_display(display);
- al_destroy_event_queue(event_queue);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement