Radial random through macro
This commit is contained in:
parent
84b2053bea
commit
b6098ce825
2 changed files with 15 additions and 3 deletions
|
|
@ -9,6 +9,19 @@ pub use gene_source::GeneSource;
|
||||||
pub use gene_place::GenePlace;
|
pub use gene_place::GenePlace;
|
||||||
use godot::builtin::Vector2;
|
use godot::builtin::Vector2;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! radial_child_position {
|
||||||
|
($radius:literal) => {
|
||||||
|
|_|{
|
||||||
|
use rand::{RngExt};
|
||||||
|
use godot::builtin::Vector2;
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
|
||||||
|
Vector2::from_angle(rng.random_range(0.0..=1.0)*3.1415*2.) * rng.random_range(($radius/2.)..=$radius)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(PartialEq,Eq,Clone)]
|
#[derive(PartialEq,Eq,Clone)]
|
||||||
pub struct Gene {
|
pub struct Gene {
|
||||||
pub plant_source: GeneSource,
|
pub plant_source: GeneSource,
|
||||||
|
|
@ -58,10 +71,9 @@ impl Gene {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Display for Gene {
|
impl Display for Gene {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f,"({}) {}",self.plant_source,self.place)
|
write!(f,"({}) {}",self.plant_source,self.place)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,6 @@ fn get_place_head(place: GenePlace) -> Vector2 {
|
||||||
match place {
|
match place {
|
||||||
GenePlace::Mouth => Vector2::new(1.,4.),
|
GenePlace::Mouth => Vector2::new(1.,4.),
|
||||||
GenePlace::Eyes => Vector2::new(1.,-2.),
|
GenePlace::Eyes => Vector2::new(1.,-2.),
|
||||||
_ =>return Vector2::ZERO
|
_ => crate::radial_child_position!(10.)(place.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue