use quicksilver::{
geom::{Circle, Rectangle, Vector},
graphics::{Color, Image, PixelFormat, Surface},
run, Graphics, Input, Result, Settings, Window,
};
fn main() {
run(
Settings {
title: "Square Example",
..Settings::default()
},
app,
);
}
async fn app(window: Window, mut gfx: Graphics, mut input: Input) -> Result<()> {
gfx.clear(Color::WHITE);
let mut surface = Surface::new(
&gfx,
Image::from_raw(&gfx, None, 512, 512, PixelFormat::RGBA)?,
)?;
gfx.fill_rect(
&Rectangle::new(Vector::new(0.0, 0.0), Vector::new(100.0, 100.0)),
Color::RED,
);
gfx.fill_circle(&Circle::new(Vector::new(400.0, 150.0), 50.0), Color::BLACK);
gfx.flush_surface(&surface)?;
gfx.clear(Color::BLACK);
let image = surface.detach().expect("The image failed to detach");
gfx.draw_image(&image, Rectangle::new_sized(Vector::new(400.0, 300.0)));
gfx.draw_image(
&image,
Rectangle::new(Vector::new(400.0, 300.0), Vector::new(400.0, 300.0)),
);
gfx.present(&window)?;
loop {
while let Some(_) = input.next_event().await {}
}
}