static ALLEGRO_BITMAP *example_bitmap(int w, int h) { int i, j; float mx = w * 0.5; float my = h * 0.5; ALLEGRO_STATE state; ALLEGRO_BITMAP *pattern = al_create_bitmap(w, h); al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP); al_set_target_bitmap(pattern); al_lock_bitmap(pattern, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); for (i = 0; i < w; i++) { for (j = 0; j < h; j++) { float a = atan2(i - mx, j - my); float d = sqrt(pow(i - mx, 2) + pow(j - my, 2)); float sat = pow(1.0 - 1 / (1 + d * 0.1), 5); float hue = 3 * a * 180 / ALLEGRO_PI; hue = (hue / 360 - floorf(hue / 360)) * 360; al_put_pixel(i, j, al_color_hsv(hue, sat, 1)); } } al_put_pixel(0, 0, al_map_rgb(0, 0, 0)); al_unlock_bitmap(pattern); al_restore_state(&state); return pattern; }
static void draw(ALLEGRO_BITMAP *bitmap, int y, char const *text) { int i; al_draw_text(font_ms, al_map_rgb(0, 0, 0), 0, y, 0, text); for (i = 0; i < 16; i++) { float a = 2 * ALLEGRO_PI * i / 16; ALLEGRO_COLOR c = al_color_hsv(i * 360 / 16, 1, 1); al_draw_line(150 + cos(a) * 10, y + 100 + sin(a) * 10, 150 + cos(a) * 90, y + 100 + sin(a) * 90, c, 3); } for (i = 0; i < 8; i++) { float a = 2 * ALLEGRO_PI * i / 16; int s = al_get_bitmap_width(bitmap); al_draw_rotated_bitmap(bitmap, s / 2, s / 2, 50 + bitmap_x[i], y + bitmap_y[i], a, 0); } }
void Color::from_hsv(float h, float s, float v) { RAGE_CHECK_DISPOSED(disposed); color = al_color_hsv(h, s, v); }
void al_color_hsv_w(float h, float s, float v, ALLEGRO_COLOR *color) { *color = al_color_hsv(h, s, v); }