BeepSortRust/src/main.rs

69 lines
2 KiB
Rust
Raw Normal View History

2023-01-24 15:25:03 +00:00
2022-11-06 21:44:59 +00:00
mod BarPlugin;
mod GuiHookVec;
mod Algorithm;
use macroquad::prelude::*;
use macroquad::prelude::scene::clear;
use crate::BarPlugin::Bar;
use crate::GuiHookVec::GuiVec;
2022-11-08 15:31:16 +00:00
use macroquad::hash;
2022-11-07 02:36:26 +00:00
use macroquad::ui::root_ui;
2022-11-06 21:44:59 +00:00
#[macroquad::main("BeepSort")]
async fn main() {
let mut length = 1;
let mut lengthString = "100".to_owned();
let mut delay = 0.;
2023-02-26 02:16:09 +00:00
let mut delayText = "1".to_owned();
loop{
clear_background(WHITE);
2022-11-08 15:31:16 +00:00
delay = match delayText.parse::<f64>(){
Ok(a) => a/1000.,
Err(error)=> {0.1}
};
length = match lengthString.parse::<i32>(){
Ok(a) => a,
Err(error)=> {100}
};
2023-02-26 16:09:37 +00:00
draw_text("Sorting!", screen_width()*0.3, screen_height()*0.1, 100.0, GREEN);
2022-11-07 23:56:06 +00:00
draw_text(format!("Length: {}", length.to_string()).as_str(), screen_width()*0.83, 30., 20.0, BLACK);
draw_text(&get_fps().to_string(), screen_width()*0.7, 30.0, 20.0, BLACK);
root_ui().window(hash!(), Vec2::new(screen_width()*0.01, 45.), Vec2::new(250., 50.), |ui|{
2022-11-08 15:31:16 +00:00
ui.input_text(hash!(), "Delay (ms)", &mut delayText);
ui.input_text(hash!(), "Length Of Array!", &mut lengthString);
2022-11-08 15:31:16 +00:00
});
let mut algo = "";
2023-02-26 02:16:09 +00:00
if root_ui().button(Vec2::new(screen_width()*0.01, 100.), "Run InsertSort!"){
algo = "insertSort";
}
2023-02-26 02:16:09 +00:00
if root_ui().button(Vec2::new(screen_width()*0.01, 130.), "Run BubbleSort!"){
algo = "bubbleSort";
2023-02-26 02:16:09 +00:00
}
if root_ui().button(Vec2::new(screen_width()*0.01, 160.), "Run BinaryHeapSort!"){
algo = "binaryHeap";
2023-02-26 02:16:09 +00:00
}
if root_ui().button(Vec2::new(screen_width()*0.01, 190.), "Run CoctailShakerSort!"){
algo = "cocktailShaker";
2023-02-26 02:16:09 +00:00
}
if root_ui().button(Vec2::new(screen_width()*0.01, 220.), "Run BogoSort!"){
algo = "bogoSort";
}
if algo != ""{
Algorithm::Algorithm::run(length, 1.0, algo.to_string()).await;
2023-02-26 02:16:09 +00:00
}
next_frame().await
2022-11-06 21:44:59 +00:00
}
2022-11-06 21:44:59 +00:00
}