[−][src]Struct evolution::fish::Fish
An entity that has the behavior of eating food and avoiding predators, along with basic physics.
Fields
animation_index: usize
The index of the current animation frame index stored in
ANIMATION_FRAMES
frame_index: u8
The current frame number of the window to determine when to update the animation frame
specified from FishConfig.frames_per_animation_frame
dna: [f32; 4]
The DNA currently holds values for the weights of attraction and repulsion and the radii of perception for prey and predators respectively
color: (f32, f32, f32)
The rbg color of the fish
health: f32
The health of the fish starts at 1 (full) and will decline by 0.001 per frame. A health of 0 or lower will result in an invisible fish. The opacity of a fish is dependant on its health.
scale: f32
The scale of the fish. E.g. A scale of 2 would result in a fish twice as large as the original image.
max_speed: f32
The maximum velocity magnitude that the fish is able to reach
max_steering_force: f32
The maximum steering/turning force that is able to be applied to the fish.
pos: Point2<f32>
The 2D position of the fish (the fish's location is in relation to its center)
angle: f32
A radian angle that determines where the fish is pointed towards. An angle of zero would point the fish towards the right. This value is set to wherever the velocity vector is pointed towards.
vel: Vector2<f32>
The 2D velocity vector.
acc: Vector2<f32>
The 2D acceleration vector.
Methods
impl Fish
[src]
pub fn new(
fish_config: &FishConfig,
group_index: &usize,
window_size: &(f32, f32),
rng: &mut ThreadRng
) -> Self
[src]
fish_config: &FishConfig,
group_index: &usize,
window_size: &(f32, f32),
rng: &mut ThreadRng
) -> Self
Creates a new fish based on the provided and default attributes.
pub fn clone(&self, rng: &mut ThreadRng, mutation_rate: f32) -> Self
[src]
Creates a clone of a fish, with possible mutation(s) to the DNA
pub fn draw(
&mut self,
ctx: &mut Context,
image: &Image,
frames_per_animation_frame: f32
) -> GameResult
[src]
&mut self,
ctx: &mut Context,
image: &Image,
frames_per_animation_frame: f32
) -> GameResult
Draw the image that represents the fish, and animates it.
pub fn update(&mut self)
[src]
Update the state of the fish in the simulation
pub fn behave(
&mut self,
food: &mut Vec<Food>,
prey: &mut [Vec<Self>],
predator_positions: &Option<Vec<Point2<f32>>>,
eating_radius: f32
)
[src]
&mut self,
food: &mut Vec<Food>,
prey: &mut [Vec<Self>],
predator_positions: &Option<Vec<Point2<f32>>>,
eating_radius: f32
)
Applies the seeking behavior to the fish to eat prey and avoid predators.
pub fn eat(
&mut self,
food: &mut Vec<Food>,
prey: &mut [Vec<Self>],
eating_radius: f32
) -> Vector2<f32>
[src]
&mut self,
food: &mut Vec<Food>,
prey: &mut [Vec<Self>],
eating_radius: f32
) -> Vector2<f32>
Determine the closest Entity
in food and prey, and what the steering force should be applied to the
Fish
to head towards that Entity
.
Returns a the steering force of atraction for the Entity
fn consume<E: Entity>(
&mut self,
entities: &mut Vec<E>,
entity_index: usize,
record: f32,
eating_radius: f32
) -> Vector2<f32>
[src]
&mut self,
entities: &mut Vec<E>,
entity_index: usize,
record: f32,
eating_radius: f32
) -> Vector2<f32>
Returns the steering force to head towards the provided entity. If this fish's radius is overlapping the provided entity's radius, then remove it from its collection.
pub fn avoid(&mut self, predator_positions: &Vec<Point2<f32>>) -> Vector2<f32>
[src]
Determine the closest predator, and what the steering force should be applied to the
Fish
to avoid that predator
pub fn bound(&mut self, window_size: &(f32, f32), boundary_padding: f32)
[src]
Bounds the fish to swim within the window based on the provided padding thickness.
pub fn seek(&mut self, target: Point2<f32>) -> Vector2<f32>
[src]
Returns a force that will point the fish towards its target.
pub fn is_alive(&self) -> bool
[src]
Returns whether or not this fish is alive
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
Sets value
as a parameter of self
.
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,