[][src]Struct evolution::fish::Fish

pub struct Fish {
    animation_index: usize,
    frame_index: u8,
    dna: [f32; 4],
    color: (f32, f32, f32),
    health: f32,
    scale: f32,
    max_speed: f32,
    max_steering_force: f32,
    pos: Point2<f32>,
    angle: f32,
    vel: Vector2<f32>,
    acc: Vector2<f32>,
}

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]

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]

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]

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]

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]

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

impl Entity for Fish[src]

fn pos(&self) -> Point2<f32>[src]

Returns a reference to the fish's position

fn radius(&self) -> f32[src]

Returns the radius around the center of the fish at which it can interact with other entities

Auto Trait Implementations

impl Send for Fish

impl Sync for Fish

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,