sound fixed!
This commit is contained in:
parent
b39a778b2d
commit
c3ef0c4b7b
12 changed files with 27 additions and 23 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -87,9 +87,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
|||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
|
|
|
@ -13,21 +13,16 @@ use crate::soundGenerator;
|
|||
pub struct Bar {
|
||||
pub position:usize,
|
||||
pub color:color::Color,
|
||||
sound:Sound,
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Bar{
|
||||
pub async fn new(position:usize, hsl_color:f32, frequency:f32) -> Self{
|
||||
pub fn new(position:usize, hsl_color:f32) -> Self{
|
||||
Bar{
|
||||
position,
|
||||
color: color::hsl_to_rgb((hsl_color as f32) , 1.0, 0.5),
|
||||
sound:soundGenerator::generateTone(frequency, 0.1).await
|
||||
}
|
||||
}
|
||||
|
||||
pub fn playSound(&self ){
|
||||
play_sound(self.sound, PlaySoundParams::default());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
|
||||
use async_trait::async_trait;
|
||||
use macroquad::audio::{play_sound_once, Sound};
|
||||
use macroquad::color::{BROWN, WHITE};
|
||||
use macroquad::{hash, time};
|
||||
use macroquad::prelude::{clear_background, Vec2, BLACK};
|
||||
|
@ -11,6 +12,7 @@ use macroquad::time::{get_frame_time, get_fps};
|
|||
use macroquad::ui::root_ui;
|
||||
use macroquad::window::{next_frame, screen_height, screen_width};
|
||||
use crate::BarPlugin::Bar;
|
||||
use crate::soundGenerator;
|
||||
|
||||
|
||||
|
||||
|
@ -29,7 +31,8 @@ pub struct GuiVec{
|
|||
renderSkip:i32,
|
||||
skipped:i32,
|
||||
lastTouched:Vec<usize>,
|
||||
lastPlayed:f64
|
||||
lastPlayed:f64,
|
||||
sounds:Vec<Sound>
|
||||
}
|
||||
#[async_trait]
|
||||
pub trait SortingList{
|
||||
|
@ -71,8 +74,15 @@ impl SortingList for GuiVec{
|
|||
|
||||
for i in 1..length+1 {
|
||||
let frequency = i as f32 * freqStep;
|
||||
list.push(Bar::new(i, (colorStep*i as f32)/360., frequency).await);
|
||||
list.push(Bar::new(i, (colorStep*i as f32)/360.));
|
||||
}
|
||||
|
||||
//Generate sounds
|
||||
let mut sounds = Vec::with_capacity(1000);
|
||||
for i in (50..2100).step_by(2){
|
||||
sounds.push(soundGenerator::generateTone(i as f32, 0.1).await);
|
||||
}
|
||||
|
||||
GuiVec{
|
||||
list,
|
||||
initialSize:length as usize,
|
||||
|
@ -87,6 +97,7 @@ impl SortingList for GuiVec{
|
|||
skipped:0,
|
||||
lastTouched:Vec::with_capacity(2),
|
||||
lastPlayed:0.,
|
||||
sounds,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +179,7 @@ impl SortingList for GuiVec{
|
|||
|
||||
|
||||
if time::get_time() + 0.5 >= self.lastPlayed{
|
||||
self.list[index1].playSound();
|
||||
play_sound_once(self.sounds[ (self.list[index1].position * 1000 / self.list.len()) ]);
|
||||
self.lastPlayed = time::get_time()+0.5;
|
||||
}
|
||||
|
||||
|
@ -251,7 +262,7 @@ impl SortingList for NonGuiVec{
|
|||
async fn new(length:usize, delay:f32) -> Self{
|
||||
let mut list = Vec::new();
|
||||
for i in 0..(length as usize){
|
||||
list.push(Bar::new(i, i as f32, 0.0).await)
|
||||
list.push(Bar::new(i, i as f32))
|
||||
}
|
||||
NonGuiVec { list: list }
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ use super::*;
|
|||
|
||||
#[test]
|
||||
fn binartHeap_correct() {
|
||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
||||
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||
aw!(binaryHeap(&mut list));
|
||||
assert_eq!( list.isSorted(), true);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ use super::*;
|
|||
|
||||
#[test]
|
||||
fn bogoSort_correct_this_is_a_meme() {
|
||||
let mut list:NonGuiVec = SortingList::new(5,0.0);
|
||||
let mut list:NonGuiVec = aw!(SortingList::new(5,0.0));
|
||||
aw!(bogoSort(&mut list));
|
||||
assert_eq!( list.isSorted(), true);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ use super::*;
|
|||
|
||||
#[test]
|
||||
fn bubblesort_correct() {
|
||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
||||
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||
aw!(bubbleSort(&mut list));
|
||||
assert_eq!( list.isSorted(), true);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ use super::*;
|
|||
|
||||
#[test]
|
||||
fn coctailshakersort_correct() {
|
||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
||||
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||
aw!(cocktailShaker(&mut list));
|
||||
assert_eq!( list.isSorted(), true);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ use super::*;
|
|||
|
||||
#[test]
|
||||
fn insertsort_correct() {
|
||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
||||
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||
aw!(insertSort(&mut list));
|
||||
assert_eq!( list.isSorted(), true);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ use super::*;
|
|||
|
||||
#[test]
|
||||
fn quicksort_correct() {
|
||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
||||
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||
aw!(quickSort(&mut list));
|
||||
assert_eq!( list.isSorted(), true);
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ use super::*;
|
|||
|
||||
#[test]
|
||||
fn radixsort_correct() {
|
||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
||||
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||
aw!(radixSort(&mut list));
|
||||
assert_eq!( list.isSorted(), true);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ use super::*;
|
|||
|
||||
#[test]
|
||||
fn radixsort_correct() {
|
||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
||||
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||
aw!(radixSort(&mut list));
|
||||
assert_eq!( list.isSorted(), true);
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@ use std::path::Path;
|
|||
|
||||
use dropdown::ButtonDropDown;
|
||||
|
||||
use macroquad::audio::PlaySoundParams;
|
||||
use macroquad::audio::play_sound;
|
||||
use macroquad::audio::play_sound_once;
|
||||
|
||||
use macroquad::prelude::*;
|
||||
|
||||
use macroquad::hash;
|
||||
|
|
Loading…
Reference in a new issue