finished, needs full redesign to become more optimized

This commit is contained in:
Rolf Martin Glomsrud 2022-11-08 17:26:02 +01:00
parent c70ebbe4bd
commit 7a48d0debb
3 changed files with 26 additions and 29 deletions

View file

@ -10,3 +10,5 @@ macroquad = "0.3.25"
[toolchain]
channel = "nightly"
[profile.release]
opt-level=3

View file

@ -48,7 +48,7 @@ impl State{
draw_text(format!("Write: {}", holder.writes).as_str(), screen_width()*0.01, 40.0, 20.0, BLACK);
draw_text(format!("Comparisons: {}", holder.comps).as_str(), screen_width()*0.01, 60.0, 20.0, BLACK);
draw_text(format!("FPS: {}", get_fps()).as_str(), screen_width()*0.01, 80., 20.0, BLACK);
root_ui().window(hash!(), Vec2::new(screen_width()*0.1, 10.), Vec2::new(200., 25.), |ui|{
root_ui().window(hash!(), Vec2::new(screen_width()*0.2, 5.), Vec2::new(200., 25.), |ui|{
ui.input_text(hash!(), "Speed", &mut speedText);
});
@ -59,7 +59,7 @@ impl State{
paused = true;
}
}
if root_ui().button(Vec2::new(screen_width()*0.01, 110.), "Return"){
if root_ui().button(Vec2::new(screen_width()*0.01, 120.), "Return"){
ret = true;
}
if ret{

View file

@ -20,10 +20,10 @@ use crate::Algorithm::AlgoEnum;
#[macroquad::main("BeepSort")]
async fn main() {
let mut length = 500;
let mut length = 1;
let mut lengthString = "100".to_owned();
let mut delay = 0.;
let mut delayText = "0.1".to_owned();
let mut delayText = "0.0".to_owned();
loop{
clear_background(WHITE);
@ -31,41 +31,36 @@ async fn main() {
Ok(a) => a/1000.,
Err(error)=> {0.1}
};
length = match lengthString.parse::<i32>(){
Ok(a) => a,
Err(error)=> {100}
};
draw_text("Sorting!", screen_width()*0.3, screen_height()*0.5, 100.0, GREEN);
draw_text(format!("Length: {}", length.to_string()).as_str(), screen_width()*0.83, 30., 20.0, BLACK);
if root_ui().button(Vec2::new(screen_width()*0.9, 50.), "+10"){
length += 10;
}
if root_ui().button(Vec2::new(screen_width()*0.87, 50.), "+1"){
length += 1;
}
if root_ui().button(Vec2::new(screen_width()*0.8, 50.), "-10"){
length -= 10;
}
if root_ui().button(Vec2::new(screen_width()*0.84, 50.), "-1"){
length -= 1;
}
root_ui().window(hash!(), Vec2::new(screen_width()*0.1, 10.), Vec2::new(200., 25.), |ui|{
root_ui().window(hash!(), Vec2::new(screen_width()*0.01, 45.), Vec2::new(250., 50.), |ui|{
ui.input_text(hash!(), "Delay (ms)", &mut delayText);
ui.input_text(hash!(), "Length Of Array!", &mut lengthString);
});
if root_ui().button(Vec2::new(screen_width()*0.01, 70.), "InsertSort"){
if root_ui().button(Vec2::new(screen_width()*0.01, 100.), "InsertSort"){
State::State::runInsertSort(delay,length, Algorithm::Algorithm::insertSort(length)).await;
}
if root_ui().button(Vec2::new(screen_width()*0.01, 100.), "BogoSort"){
//State::State::runInsertSort(delay,length, Algorithm::Algorithm::bogoSort(length)).await;
if root_ui().button(Vec2::new(screen_width()*0.01, 130.), "BogoSort"){
State::State::runInsertSort(delay,length, Algorithm::Algorithm::bogoSort(length)).await;
}
if root_ui().button(Vec2::new(screen_width()*0.01, 130.), "BubbleSort"){
//State::State::runInsertSort(delay, length, Algorithm::Algorithm::bubbleSort(length)).await;
if root_ui().button(Vec2::new(screen_width()*0.01, 160.), "BubbleSort"){
State::State::runInsertSort(delay, length, Algorithm::Algorithm::bubbleSort(length)).await;
}
if root_ui().button(Vec2::new(screen_width()*0.01, 160.), "StalinSort"){
//State::State::runInsertSort(delay, length, Algorithm::Algorithm::stalinSort(length)).await;
if root_ui().button(Vec2::new(screen_width()*0.01, 190.), "StalinSort"){
State::State::runInsertSort(delay, length, Algorithm::Algorithm::stalinSort(length)).await;
}
if root_ui().button(Vec2::new(screen_width()*0.01, 190.), "CoctailShaker"){
//State::State::runInsertSort(delay, length, Algorithm::Algorithm::cocktailShaker(length)).await;
if root_ui().button(Vec2::new(screen_width()*0.01, 220.), "CoctailShaker"){
State::State::runInsertSort(delay, length, Algorithm::Algorithm::cocktailShaker(length)).await;
}
if root_ui().button(Vec2::new(screen_width()*0.01, 220.), "HeapSort!"){
//State::State::runInsertSort(delay, length, Algorithm::Algorithm::binaryHeap(length)).await;
if root_ui().button(Vec2::new(screen_width()*0.01, 250.), "HeapSort!"){
State::State::runInsertSort(delay, length, Algorithm::Algorithm::binaryHeap(length)).await;
}
next_frame().await