sound by polygons and ui for add polygons and change global rotation
This commit is contained in:
@@ -6,6 +6,10 @@ use iced::widget::canvas;
|
||||
use iced::widget::canvas::Stroke;
|
||||
use iced::widget::canvas::Style;
|
||||
use iced::{Color, Rectangle, Renderer, Theme};
|
||||
use kira::PlaySoundError;
|
||||
use kira::{
|
||||
AudioManager, AudioManagerSettings, DefaultBackend, sound::static_sound::StaticSoundData,
|
||||
};
|
||||
use std::time::Instant;
|
||||
|
||||
pub trait RotationExt {
|
||||
@@ -26,13 +30,16 @@ pub struct PolygonFrame {
|
||||
}
|
||||
|
||||
impl PolygonFrame {
|
||||
pub fn have_point_polygon_btw(&self, before: f32, after: f32) -> bool {
|
||||
pub fn all_sound_to_play_btw(&self, before: f32, after: f32) -> Vec<&StaticSoundData> {
|
||||
let mut all_sound: Vec<&StaticSoundData> = vec![];
|
||||
for poly in &self.polygons {
|
||||
all_sound.extend(poly.sound_to_play_btw(before, after));
|
||||
/*
|
||||
if poly.have_points_btw(before, after) {
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
false
|
||||
all_sound
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,26 +110,33 @@ impl<Message> canvas::Program<Message> for PolygonFrame {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Polygon {
|
||||
pub global_teta: f32,
|
||||
pub points_teta: Vec<f32>,
|
||||
pub sound: StaticSoundData,
|
||||
pub name: String,
|
||||
}
|
||||
#[warn(dead_code)]
|
||||
impl Polygon {
|
||||
pub fn have_points_btw(&self, before: f32, after: f32) -> bool {
|
||||
pub fn sound_to_play_btw(&self, before: f32, after: f32) -> Vec<&StaticSoundData> {
|
||||
let mut sound_to_play: Vec<&StaticSoundData> = vec![];
|
||||
if after < before {
|
||||
return self.have_points_btw(before, 2.0 * PI) || self.have_points_btw(0.0, after);
|
||||
sound_to_play = self.sound_to_play_btw(before, 2.0 * PI);
|
||||
sound_to_play.extend(self.sound_to_play_btw(0.0, after));
|
||||
return sound_to_play;
|
||||
}
|
||||
let mut p_g;
|
||||
for p in self.points_teta.clone() {
|
||||
p_g = (p + self.global_teta) % (2.0 * PI);
|
||||
if before <= p_g && p_g <= after {
|
||||
return true;
|
||||
sound_to_play.push(&self.sound);
|
||||
}
|
||||
}
|
||||
false
|
||||
sound_to_play
|
||||
}
|
||||
pub fn n_gon(teta: f32, n_side: u8) -> Self {
|
||||
|
||||
pub fn n_gon(teta: f32, n_side: u8, sound: StaticSoundData) -> Self {
|
||||
let mut v: Vec<f32> = Vec::with_capacity(n_side as usize);
|
||||
for i in 0..n_side {
|
||||
v.push((i as f32 * 2.0 * PI) / n_side as f32);
|
||||
@@ -130,22 +144,26 @@ impl Polygon {
|
||||
Polygon {
|
||||
global_teta: teta,
|
||||
points_teta: v,
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
}
|
||||
}
|
||||
pub fn segment(teta: f32) -> Self {
|
||||
Polygon::n_gon(teta, 2)
|
||||
pub fn segment(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon::n_gon(teta, 2, sound)
|
||||
}
|
||||
|
||||
pub fn triangle(teta: f32) -> Self {
|
||||
Polygon::n_gon(teta, 3)
|
||||
pub fn triangle(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon::n_gon(teta, 3, sound)
|
||||
}
|
||||
|
||||
pub fn square(teta: f32) -> Self {
|
||||
Polygon::n_gon(teta, 4)
|
||||
pub fn square(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon::n_gon(teta, 4, sound)
|
||||
}
|
||||
|
||||
pub fn nr_6_in_30(teta: f32) -> Self {
|
||||
pub fn nr_6_in_30(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
2.0 * 5.0 * PI / 30.0,
|
||||
@@ -157,8 +175,10 @@ impl Polygon {
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn nr_7_in_30(teta: f32) -> Self {
|
||||
pub fn nr_7_in_30(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
0.0,
|
||||
@@ -171,8 +191,10 @@ impl Polygon {
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn nr_8_in_30(teta: f32) -> Self {
|
||||
pub fn nr_8_in_30(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
2.0 * PI / 30.0,
|
||||
@@ -186,8 +208,10 @@ impl Polygon {
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn nr_9_in_30(teta: f32) -> Self {
|
||||
pub fn nr_9_in_30(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
0.0,
|
||||
@@ -202,8 +226,10 @@ impl Polygon {
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn nr_8_in_42(teta: f32) -> Self {
|
||||
pub fn nr_8_in_42(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
2.0 * 3.0 * PI / 42.0,
|
||||
@@ -217,8 +243,10 @@ impl Polygon {
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn nr_9_in_42(teta: f32) -> Self {
|
||||
pub fn nr_9_in_42(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
0.0,
|
||||
@@ -233,8 +261,10 @@ impl Polygon {
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn nr_10a_in_42(teta: f32) -> Self {
|
||||
pub fn nr_10a_in_42(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
2.0 * 6.0 * PI / 42.0,
|
||||
@@ -250,8 +280,10 @@ impl Polygon {
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn nr_10b_in_42(teta: f32) -> Self {
|
||||
pub fn nr_10b_in_42(teta: f32, sound: StaticSoundData) -> Self {
|
||||
Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
0.0,
|
||||
|
||||
Reference in New Issue
Block a user