Исходный код (линии):
#include <allegro5\allegro.h> #include <allegro5/allegro_primitives.h> int main(void) { int width = 640; int height = 480; ALLEGRO_DISPLAY *display = NULL; if(!al_init()) return -1; display = al_create_display(width, height); if(!display) return -1; al_init_primitives_addon(); al_draw_line(100, 100, width - 100, 100, al_map_rgb(255, 0, 0), 1); al_draw_line(50, 200, width - 50, 200, al_map_rgb(0, 0, 255), 5); al_draw_line(0, 300, width, 300, al_map_rgb(255, 0, 255), 10); al_draw_line(50, 50, 50, 400, al_map_rgb(0, 255, 0), 3); al_draw_line(50, 200, width - 50, 400, al_map_rgb(0, 0, 255), 5); al_flip_display(); al_rest(4.0); al_destroy_display(display); return 0; }
Исходный код (Треугольники):
#include <allegro5\allegro.h> #include <allegro5\allegro_primitives.h> int main(void) { int width = 640; int height = 480; ALLEGRO_DISPLAY *display = NULL; if(!al_init()) return -1; display = al_create_display(width, height); if(!display) return -1; al_init_primitives_addon(); al_draw_triangle(10, 200, 100, 10, 190, 200, al_map_rgb(255, 0, 255), 5); al_draw_filled_triangle(300, 400, 400, 200, 500, 400, al_map_rgb(0, 0, 255)); al_flip_display(); al_rest(4.0); al_destroy_display(display); return 0; }Исходный код (Прямоугольники, квадраты):#include <allegro5\allegro.h> #include <allegro5\allegro_primitives.h> int main(void) { int width = 640; int height = 480; ALLEGRO_DISPLAY *display = NULL; if(!al_init()) return -1; display = al_create_display(width, height); if(!display) return -1; al_init_primitives_addon(); al_draw_rectangle(10, 10, 250, 250, al_map_rgb(255, 0, 255), 5); al_draw_rounded_rectangle(width - 200, 10, width - 10, 50, 5, 5, al_map_rgb(0, 0, 255), 15); al_draw_filled_rectangle(10, 280, 250, height - 10, al_map_rgb(255, 255, 255)); al_draw_filled_rounded_rectangle(width - 200, 180, width - 10, height - 10, 10, 10, al_map_rgb(0, 255, 0)); al_flip_display(); al_rest(4.0); al_destroy_display(display); return 0; }Исходный код (круги):#include <allegro5\allegro.h> #include <allegro5\allegro_primitives.h> int main(void) { int width = 640; int height = 480; ALLEGRO_DISPLAY *display = NULL; if(!al_init()) return -1; display = al_create_display(width, height); if(!display) return -1; al_init_primitives_addon(); al_draw_circle(100, 100, 50, al_map_rgb(255, 255, 0), 7); al_draw_filled_circle(400, 400, 70, al_map_rgb(255, 255, 255)); al_flip_display(); al_rest(4.0); al_destroy_display(display); return 0; }Исходный код (эллипс):#include <allegro5\allegro.h> #include <allegro5\allegro_primitives.h> int main(void) { int width = 640; int height = 480; ALLEGRO_DISPLAY *display = NULL; if(!al_init()) return -1; display = al_create_display(width, height); if(!display) return -1; al_init_primitives_addon(); al_draw_ellipse(150, 100, 100, 50, al_map_rgb(127, 3, 34), 7); al_draw_filled_ellipse(400, 250, 100, 200, al_map_rgb(0, 255, 255)); al_flip_display(); al_rest(4.0); al_destroy_display(display); return 0; }Исходный код (сплайн):#include <allegro5\allegro.h> #include <allegro5\allegro_primitives.h> int main(void) { int width = 640; int height = 480; ALLEGRO_DISPLAY *display = NULL; if(!al_init()) return -1; display = al_create_display(width, height); if(!display) return -1; al_init_primitives_addon(); float points[] = {0, 0, 400, 100, 50, 200, width, height}; al_draw_spline(points, al_map_rgb(255, 0, 255), 0); float points2[] = {0, height, 200, 100, 400, 200, width, height}; al_draw_spline(points2, al_map_rgb(0, 0, 255), 3); al_flip_display(); al_rest(4.0); al_destroy_display(display); return 0; }
Если копипастишь, полезно указывать ссылку.
ОтветитьУдалитьhttp://fixbyproximity.com/2011/07/2d-game-dev-part-2-4-graphical-primitives/
Согласен
ОтветитьУдалить