Macroquad: Is it capable of doing math?

In the processing language, I am able to use math such as cos() or other functions to do some math. Is the macroquad crate capable of doing this? if not then is there a third party library I can import that can do this for me?

You can get sin and cos values by using f64::sin and f64::cos. These methods are also available for f32.

So would I type something like this f64::cos()?

To get the consine of:

  • pi radians:
fn main() {
    let x = std::f64::consts::PI;
    println!("{}", x.cos()); // prints -1
}
  • 42 radians:
fn main() {
    let x: f64 = 42.0;
    println!("{}", x.cos());
}

sin and cos take a value in radians so you'll have to convert to radians if you have degrees.

  • 60 degrees:
fn main() {
    let x: f64 = 60.0;
    println!("{}", x.to_radians().cos());
}

For more, see the examples section for the methods linked above.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.