main
Charlotte Som 2021-08-28 05:58:04 +01:00
parent 6bb5d90d54
commit 344a979e92
1 changed files with 26 additions and 11 deletions

View File

@ -16,6 +16,7 @@ struct Body {
pos: DVec2,
vel: DVec2,
mass: i64,
color: Rgb,
}
struct Model {
@ -25,12 +26,13 @@ struct Model {
fn model(_app: &App) -> Model {
let mut bodies = Vec::new();
const MASS_SUN: i64 = 150000000000000000;
const MASS_SUN: i64 = 50000000000000000;
bodies.push(Body {
pos: (0.0, 0.0).into(),
vel: (0.0, 0.0).into(),
mass: MASS_SUN,
color: rgb(1.0, 1.0, 1.0),
});
const G: f64 = 6.67408e-11;
@ -39,18 +41,28 @@ fn model(_app: &App) -> Model {
let d_theta: f64 = (360.0 / COPIES as f64).to_radians();
for i in 0..COPIES {
let theta = i as f64 * d_theta;
let palette = &[
rgb(85.0 / 255.0, 205.0 / 255.0, 252.0 / 255.0),
rgb(1.0, 1.0, 1.0),
rgb(247.0 / 255.0, 168.0 / 255.0, 184.0 / 255.0),
];
for i in 10..250 {
let r = 5.0 * i as f64;
let m = 10000000 / i;
for i in 0..COPIES {
let mut theta = i as f64 * d_theta;
for i in 1..=256 {
let r = 25.0 + 5.0 * i as f64;
let m = 50000000000u64 / i;
let curr_color = palette[i as usize % palette.len()];
bodies.push(Body {
pos: (r * theta.cos(), r * theta.sin()).into(),
vel: (0.0, (G * MASS_SUN as f64 / r).sqrt()).into(),
mass: m,
mass: m as i64,
color: curr_color,
});
theta += 1.94161103873;
}
}
@ -78,7 +90,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
let delta = other_body.pos - body.pos;
let dist_sq = body.pos.distance_squared(other_body.pos);
if dist_sq < 1.0 {
if dist_sq <= (body.mass as f64).log10() {
return;
}
@ -95,12 +107,15 @@ fn update(app: &App, model: &mut Model, _update: Update) {
fn view(app: &App, model: &Model, frame: Frame) {
// let t = app.duration.since_start.as_secs_f64();
let draw = app.draw().scale(2.0);
let draw = app.draw().scale(1.0);
draw.background().color(BLACK);
for body in model.bodies.iter() {
let diameter = (body.mass as f32).log10(); // should be proportional to cuberoot but this is so we can actually see the small ones
draw.ellipse().w_h(diameter, diameter).xy(body.pos.as_f32());
let diameter = (body.mass as f32).log10() * 2.0; // should be proportional to cuberoot but this is so we can actually see the small ones
draw.ellipse()
.w_h(diameter, diameter)
.xy(body.pos.as_f32())
.color(body.color);
}
draw.to_frame(app, &frame).unwrap();