// Importing crate
use macroquad::*;
//NEED
#[macroquad::main("BasicShapes")]
async fn main() {
// loop is essential for program
// NEED
loop {
clear_background(RED);
const RHO: f64 = 28.0;
const BETA: f64 = 8.0/3.0;
const SIGMA: f64 = 10.0;
let color = BLACK;
let x = 0.0;
let y = 0.1;
let z = 0.0;
let mut dx_dt = SIGMA * (y - x);
let mut dy_dt = x * (RHO - z) - y;
let mut _dz_dt = x * y - BETA * z;
draw_circle((dx_dt as f32) + 100.0, (dy_dt as f32) + 50.0, 10.0, color);
//NEED
next_frame().await
}
}
So I am working on a 2D implementation of the lorenz attractor using the macroquad library
But the problem is when the circle is drawn it just drawn once but I have to draw it a lot of times run the program yourself and you will see just on circle.
So what should I do
And if you are asking why I am making it in 2d is because macroquad doesn't has good options for 3D things so I did 2d.
You mean the circle isn’t moving? That’s because the position you calculate is the same every single frame. If you do something like—I don’t know—maybe let x = get_time(); instead of let x = 0.0, then you’ll see that stuff is happening.
Your x, y, and z are the same each loop.
If you send a number into your loop, you can use that number to modify your x, y, or z.
As an example, the variable "i" sent into this loop is 1 the first loop, 2 the second loop, and so on. Then you can use the "i" inside the loop to change x, y, or z. I use 'i" do modify "x" below.
// Importing crate
use macroquad::*;
//NEED
#[macroquad::main("BasicShapes")]
async fn main() {
// loop is essential for program
// NEED
for i in 0..1_000_000 {
clear_background(RED);
const RHO: f64 = 28.0;
const BETA: f64 = 8.0 / 3.0;
const SIGMA: f64 = 10.0;
let color = BLACK;
let x = (i as f64 / 13.0).sin();
let y = 0.1;
let z = 0.0;
let mut dx_dt = SIGMA * (y - x);
let mut dy_dt = x * (RHO - z) - y;
let mut _dz_dt = x * y - BETA * z;
draw_circle((dx_dt as f32) + 100.0, (dy_dt as f32) + 50.0, 10.0, color);
//NEED
next_frame().await
}
}
I cam up with another code but that jut draws a damn line.
use macroquad::*;
fn canvas() -> Vec<i64>{
let mut can: Vec<i64> = Vec::new();
for i in 1..401 {
can.push(i)
}
return can;
}
fn code () -> Vec<[f64;3]>{
let mut x = 0.01;
let mut y = 0.0;
let mut z = 0.0;
let canv = canvas();
let sigma = 10.0;
let rho = 28.0;
let bet: f64 = 8.0 / 3.0;
// Lorenz equations
// let mut row = Vec::new();
let dx_dt = sigma * (y - x);
let dy_dt = x * (rho - z) - y;
let dz_dt = x * y - bet * z;
let mut res: Vec<[f64;3]> = Vec::new();
for i in 0..1301 {
x += dx_dt;
y+=dy_dt;
z+=dz_dt;
// derivatives as vec
res.push([x,y,z]);
}
res
}
//NEED
#[macroquad::main("BasicShapes")]
async fn main() {
// loop is essential for program
// NEED
clear_background(BLACK);
loop {
let lor = code();
for i in lor {
let x = i[0];
let y = i[1];
draw_circle(x as f32 + 200.0, y as f32 + 100.0, 3.0,RED);
// println!("x: {}, y: {}",x,y);
}
//NEED
next_frame().await
}
}
I haven't tested this code, but I would believe that your line is probably just a lot of circles arranged in a line with small offsets. I don't think that you have any problems with the library but instead that your code just doesn't produce the thing you want.
I haven't got the time to give any detailed advice right now, but you might want to look into how to solve differential equations numerically or what kind of Rust libraries/crates might already exist for this. As for existing crates, I've searched a bit and found for example this one - no idea how easy to use that is though.