#[path = "util/setup_context.rs"]
mod util;
use piet::kurbo::{Circle, Rect};
use piet::{Color, FixedLinearGradient, GradientStop, RenderContext as _};
const RAINBOW: &[Color] = &[
Color::rgb8(0xff, 0x00, 0x00),
Color::rgb8(0xff, 0x7f, 0x00),
Color::rgb8(0xff, 0xff, 0x00),
Color::rgb8(0x00, 0xff, 0x00),
Color::rgb8(0x00, 0x00, 0xff),
Color::rgb8(0x4b, 0x00, 0x82),
Color::rgb8(0x94, 0x00, 0xd3),
];
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut brush = None;
util::run(move |render_context, width, height| {
let brush = brush.get_or_insert_with(|| {
render_context
.gradient(FixedLinearGradient {
start: (0.0, 0.0).into(),
end: (1000.0, 1000.0).into(),
stops: RAINBOW
.iter()
.enumerate()
.map(|(i, color)| GradientStop {
pos: i as f32 / (RAINBOW.len() - 1) as f32,
color: *color,
})
.collect::<Vec<_>>(),
})
.unwrap()
});
render_context.clear(None, piet::Color::WHITE);
render_context.clip(Circle::new(
(width as f64 / 2.0, height as f64 / 2.0),
100.0,
));
let rect = Rect::from_center_size(
(width as f64 / 2.0, height as f64 / 2.0),
(width as f64, 100.0),
);
render_context.fill(rect, brush);
render_context.finish().unwrap();
render_context.status().unwrap();
})
}