void bg_clear() { stack.clear(); for (int i = 0; i < MAP_SIZE; ++i) { for (int j = 0; j < MAP_SIZE; ++j) tab[i][j] = 0; } for (int i = 0; i < 20; ++i) stack.push_back(std::make_pair(rand() % MAP_SIZE, rand() % MAP_SIZE)); float r, g, b; al_color_hsv_to_rgb((rand()%6)*60, 1.0, 0.23 , &r, &g, &b); al_clear_to_color(al_map_rgb_f(r,g,b)); v = 1.0; }
void bg_draw() { al_set_target_bitmap(bg); std::vector<std::pair<int, int>> newstack; h = h+2.5; if (h > 360) h = 0; v = v - 1.0 / 144.9; if (v <= 0) bg_clear(); for (unsigned int i = 0; i < stack.size(); ++i) { int x = stack[i].first; int y = stack[i].second; float r, g, b; al_color_hsv_to_rgb(h, s, v, &r, &g, &b); al_draw_pixel(x, y, al_map_rgb_f(r,g,b)); if (x != 0 && tab[x - 1][y] != 1) { float prob = 0.001*(rand() % 1000); if (prob > p) { newstack.push_back(std::make_pair(x - 1, y)); } tab[x - 1][y] = 1; } if (x != MAP_SIZE-1 && tab[x + 1][y] != 1) { float prob = 0.001*(rand() % 1000); if (prob > p) { newstack.push_back(std::make_pair(x + 1, y)); } tab[x + 1][y] = 1; } if (y != 0 && tab[x][y-1] != 1) { float prob = 0.001*(rand() % 1000); if (prob > p) { newstack.push_back(std::make_pair(x, y-1)); } tab[x][y-1] = 1; } if (y != MAP_SIZE-1 && tab[x][y+1] != 1) { float prob = 0.001*(rand() % 1000); if (prob > p) { newstack.push_back(std::make_pair(x, y+1)); } tab[x][y+1] = 1; } } stack = newstack; al_set_target_backbuffer(okno); }
void Prog::run() { d.prepare(); while (!d.is_quit_requested()) { if (d.is_draw_requested()) { al_clear_to_color(al_map_rgb(128, 128, 128)); float v[SLIDERS_COUNT]; int keep = -1; for (int i = 0; i < SLIDERS_COUNT; i++) { int x = sliders[i].get_cur_value(); v[i] = x / 1000.0; if (previous[i] != x) { keep = i; } } if (keep != -1) { int space = keep < 12 ? keep / 3 : 4; switch (space) { case 0: al_color_rgb_to_hsv(v[0], v[1], v[2], v + 3, v + 4, v + 5); al_color_rgb_to_hsl(v[0], v[1], v[2], v + 6, v + 7, v + 8); al_color_rgb_to_cmyk(v[0], v[1], v[2], v + 12, v + 13, v + 14, v + 15); al_color_rgb_to_yuv(v[0], v[1], v[2], v + 9, v + 10, v + 11); v[3] /= 360; v[6] /= 360; break; case 1: al_color_hsv_to_rgb(v[3] * 360, v[4], v[5], v + 0, v + 1, v + 2); al_color_rgb_to_hsl(v[0], v[1], v[2], v + 6, v + 7, v + 8); al_color_rgb_to_cmyk(v[0], v[1], v[2], v + 12, v + 13, v + 14, v + 15); al_color_rgb_to_yuv(v[0], v[1], v[2], v + 9, v + 10, v + 11); v[6] /= 360; break; case 2: al_color_hsl_to_rgb(v[6] * 360, v[7], v[8], v + 0, v + 1, v + 2); al_color_rgb_to_hsv(v[0], v[1], v[2], v + 3, v + 4, v + 5); al_color_rgb_to_cmyk(v[0], v[1], v[2], v + 12, v + 13, v + 14, v + 15); al_color_rgb_to_yuv(v[0], v[1], v[2], v + 9, v + 10, v + 11); v[3] /= 360; break; case 3: al_color_yuv_to_rgb(v[9], v[10], v[11], v + 0, v + 1, v + 2); v[0] = clamp(v[0]); v[1] = clamp(v[1]); v[2] = clamp(v[2]); al_color_rgb_to_yuv(v[0], v[1], v[2], v + 9, v + 10, v + 11); al_color_rgb_to_hsv(v[0], v[1], v[2], v + 3, v + 4, v + 5); al_color_rgb_to_hsl(v[0], v[1], v[2], v + 6, v + 7, v + 8); al_color_rgb_to_cmyk(v[0], v[1], v[2], v + 12, v + 13, v + 14, v + 15); v[3] /= 360; v[6] /= 360; break; case 4: al_color_cmyk_to_rgb(v[12], v[13], v[14], v[15], v + 0, v + 1, v + 2); al_color_rgb_to_hsv(v[0], v[1], v[2], v + 3, v + 4, v + 5); al_color_rgb_to_hsl(v[0], v[1], v[2], v + 6, v + 7, v + 8); al_color_rgb_to_yuv(v[0], v[1], v[2], v + 9, v + 10, v + 11); v[3] /= 360; v[6] /= 360; break; } } for (int i = 0; i < SLIDERS_COUNT; i++) { sliders[i].set_cur_value((int)(v[i] * 1000)); previous[i] = sliders[i].get_cur_value(); char c[100]; sprintf(c, "%d", (int)(v[i] * 100)); labels2[i].set_text(c); } d.draw(); al_draw_filled_rectangle(0, 400, 640, 480, al_map_rgb_f(v[0], v[1], v[2])); char const *name = al_color_rgb_to_name(v[0], v[1], v[2]); char html[8]; al_color_rgb_to_html(v[0], v[1], v[2], html); al_draw_text(d.get_theme().font, al_map_rgb(0, 0, 0), 0, 380, 0, name); al_draw_text(d.get_theme().font, al_map_rgb(0, 0, 0), 0, 360, 0, html); al_flip_display(); } d.run_step(true); } }