2022-11-07 21:38:37 +00:00
|
|
|
#![feature(generators, generator_trait, type_alias_impl_trait)]
|
2022-11-06 21:44:59 +00:00
|
|
|
mod BarPlugin;
|
|
|
|
mod GuiHookVec;
|
|
|
|
mod Algorithm;
|
2022-11-07 21:38:37 +00:00
|
|
|
mod State;
|
2022-11-06 21:44:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
use std::pin::Pin;
|
|
|
|
use macroquad::prelude::*;
|
|
|
|
use macroquad::prelude::scene::clear;
|
|
|
|
use crate::BarPlugin::Bar;
|
|
|
|
use crate::GuiHookVec::GuiVec;
|
2022-11-07 00:21:18 +00:00
|
|
|
|
2022-11-07 21:38:37 +00:00
|
|
|
use std::ops::{Deref, Generator, GeneratorState};
|
2022-11-07 23:56:06 +00:00
|
|
|
use std::process::id;
|
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-07 22:21:10 +00:00
|
|
|
use crate::Algorithm::AlgoEnum;
|
|
|
|
|
2022-11-06 21:44:59 +00:00
|
|
|
|
|
|
|
#[macroquad::main("BeepSort")]
|
|
|
|
async fn main() {
|
2022-11-08 16:26:02 +00:00
|
|
|
let mut length = 1;
|
|
|
|
let mut lengthString = "100".to_owned();
|
2022-11-08 05:32:39 +00:00
|
|
|
let mut delay = 0.;
|
2022-11-08 16:26:02 +00:00
|
|
|
let mut delayText = "0.0".to_owned();
|
2022-11-07 21:38:37 +00:00
|
|
|
loop{
|
2022-11-07 22:21:10 +00:00
|
|
|
clear_background(WHITE);
|
2022-11-08 15:31:16 +00:00
|
|
|
|
|
|
|
delay = match delayText.parse::<f64>(){
|
|
|
|
Ok(a) => a/1000.,
|
|
|
|
Err(error)=> {0.1}
|
|
|
|
};
|
2022-11-08 16:26:02 +00:00
|
|
|
length = match lengthString.parse::<i32>(){
|
|
|
|
Ok(a) => a,
|
|
|
|
Err(error)=> {100}
|
|
|
|
};
|
|
|
|
|
2022-11-08 00:54:21 +00:00
|
|
|
draw_text("Sorting!", screen_width()*0.3, screen_height()*0.5, 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);
|
2022-11-08 16:26:02 +00:00
|
|
|
|
|
|
|
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);
|
2022-11-08 16:26:02 +00:00
|
|
|
ui.input_text(hash!(), "Length Of Array!", &mut lengthString);
|
2022-11-08 15:31:16 +00:00
|
|
|
});
|
2022-11-07 23:56:06 +00:00
|
|
|
|
2022-11-08 16:26:02 +00:00
|
|
|
if root_ui().button(Vec2::new(screen_width()*0.01, 100.), "InsertSort"){
|
2022-11-07 23:56:06 +00:00
|
|
|
State::State::runInsertSort(delay,length, Algorithm::Algorithm::insertSort(length)).await;
|
2022-11-07 22:21:10 +00:00
|
|
|
}
|
2022-11-08 16:26:02 +00:00
|
|
|
if root_ui().button(Vec2::new(screen_width()*0.01, 130.), "BogoSort"){
|
|
|
|
State::State::runInsertSort(delay,length, Algorithm::Algorithm::bogoSort(length)).await;
|
2022-11-07 22:21:10 +00:00
|
|
|
}
|
2022-11-08 16:26:02 +00:00
|
|
|
if root_ui().button(Vec2::new(screen_width()*0.01, 160.), "BubbleSort"){
|
|
|
|
State::State::runInsertSort(delay, length, Algorithm::Algorithm::bubbleSort(length)).await;
|
2022-11-07 22:21:10 +00:00
|
|
|
}
|
2022-11-08 16:26:02 +00:00
|
|
|
if root_ui().button(Vec2::new(screen_width()*0.01, 190.), "StalinSort"){
|
|
|
|
State::State::runInsertSort(delay, length, Algorithm::Algorithm::stalinSort(length)).await;
|
2022-11-07 23:56:06 +00:00
|
|
|
}
|
2022-11-08 16:26:02 +00:00
|
|
|
if root_ui().button(Vec2::new(screen_width()*0.01, 220.), "CoctailShaker"){
|
|
|
|
State::State::runInsertSort(delay, length, Algorithm::Algorithm::cocktailShaker(length)).await;
|
2022-11-08 15:31:16 +00:00
|
|
|
}
|
2022-11-08 16:26:02 +00:00
|
|
|
if root_ui().button(Vec2::new(screen_width()*0.01, 250.), "HeapSort!"){
|
|
|
|
State::State::runInsertSort(delay, length, Algorithm::Algorithm::binaryHeap(length)).await;
|
2022-11-07 02:36:26 +00:00
|
|
|
}
|
2022-11-07 23:56:06 +00:00
|
|
|
|
2022-11-07 22:21:10 +00:00
|
|
|
next_frame().await
|
2022-11-06 21:44:59 +00:00
|
|
|
}
|
2022-11-07 21:38:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-06 21:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|