Esempio n. 1
0
void ColorWheel::on_render(clan::Canvas &canvas, const clan::Rect &update_rect)
{
    get_options();

    clan::Pointf center( (float) canvas.get_width()/2.0f, (float) canvas.get_height()/2.0f);
    float radius = 200.0f;
    create_colorwheel(center, radius);

    canvas.fill_triangles(colorwheel_positions, colorwheel_colors, colorwheel_segments * 3);

    draw_labels(canvas);
}
Esempio n. 2
0
void ColorWheel::draw(clan::Canvas &canvas, const clan::Pointf &center, float radius)
{
	const int colorwheel_segments = 360 / 2;
	clan::Vec2f colorwheel_positions[colorwheel_segments * 3];
	clan::Colorf colorwheel_colors[colorwheel_segments * 3];

	for (int segment = 0; segment < colorwheel_segments; segment++)
	{
		int source_segment = segment;
		int next_segment = segment + 1;

		float src_angle = (source_segment * clan::PI*2.0f) / colorwheel_segments;
		float dest_angle = (next_segment * clan::PI*2.0f) / colorwheel_segments;
		src_angle -= clan::PI / 2.0f;	// So red is at the top
		dest_angle -= clan::PI / 2.0f;
		float src_x = cos(src_angle);
		float src_y = sin(src_angle);
		float dest_x = cos(dest_angle);
		float dest_y = sin(dest_angle);

		int triangle_offset = segment * 3;
		colorwheel_positions[triangle_offset + 0].x = center.x;
		colorwheel_positions[triangle_offset + 0].y = center.y;

		colorwheel_positions[triangle_offset + 1].x = (src_x * radius) + center.x;
		colorwheel_positions[triangle_offset + 1].y = (src_y * radius) + center.y;

		colorwheel_positions[triangle_offset + 2].x = (dest_x * radius) + center.x;
		colorwheel_positions[triangle_offset + 2].y = (dest_y * radius) + center.y;

		clan::Colorf work_color_src;
		clan::Colorf work_color_dest;
		clan::Colorf work_color_center;

		if (is_hsl)
		{
			clan::ColorHSLf color_src_hsv(source_segment * 360.0f / colorwheel_segments, saturation_outer, value_outer, 1.0f);
			work_color_src = clan::Colorf(color_src_hsv);

			clan::ColorHSLf color_dest_hsv(next_segment * 360.0f / colorwheel_segments, saturation_outer, value_outer, 1.0f);
			work_color_dest = clan::Colorf(color_dest_hsv);

			clan::ColorHSLf color_center_hsv(((source_segment + next_segment) / 2.0f) * 360.0f / colorwheel_segments, saturation_inner, value_inner, 1.0f);
			work_color_center = clan::Colorf(color_center_hsv);
		}
		else
		{
			clan::ColorHSVf color_src_hsv(source_segment * 360.0f / colorwheel_segments, saturation_outer, value_outer, 1.0f);
			work_color_src = clan::Colorf(color_src_hsv);

			clan::ColorHSVf color_dest_hsv(next_segment * 360.0f / colorwheel_segments, saturation_outer, value_outer, 1.0f);
			work_color_dest = clan::Colorf(color_dest_hsv);

			clan::ColorHSVf color_center_hsv(((source_segment + next_segment) / 2.0f) * 360.0f / colorwheel_segments, saturation_inner, value_inner, 1.0f);
			work_color_center = clan::Colorf(color_center_hsv);
		}

		colorwheel_colors[triangle_offset + 0] = work_color_center;
		colorwheel_colors[triangle_offset + 1] = work_color_src;
		colorwheel_colors[triangle_offset + 2] = work_color_dest;

	}

	canvas.fill_triangles(colorwheel_positions, colorwheel_colors, colorwheel_segments * 3);
}