Skip to content

Commit

Permalink
WASM: add new method: gaussian
Browse files Browse the repository at this point in the history
  • Loading branch information
altunenes committed Aug 24, 2023
1 parent dde90cb commit 5cf3a7e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/setup/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,43 @@ DrawingMethod::Gaussian => {
}).insert(Ellipse);
}
},

DrawingMethod::Phyllotaxis => {
let golden_angle = 137.5_f32.to_radians();
let distance = 15.0;

let generate_positions = |num_ellipses, x_offset| {
let mut positions = Vec::new();
for i in 0..num_ellipses {
let theta = i as f32 * golden_angle;
let r = distance * (i as f32).sqrt();
let pos_x = x_offset + r * theta.cos();
let pos_y = r * theta.sin();
positions.push((pos_x, pos_y));
}
positions
};

let left_positions = generate_positions(num_ellipses_1, x);
let right_positions = generate_positions(num_ellipses_2, x_2);
for (pos_x, pos_y) in left_positions {
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(radius.0).into()).into(),
material: materials.add(ColorMaterial::from(ellipse_color_resource.0)),
transform: Transform::from_translation(Vec3::new(pos_x, pos_y, 0.)),
..default()
}).insert(Ellipse);
}

for (pos_x, pos_y) in right_positions {
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(radius.0).into()).into(),
material: materials.add(ColorMaterial::from(ellipse_color_resource.0)),
transform: Transform::from_translation(Vec3::new(pos_x, pos_y, 0.)),
..default()
}).insert(Ellipse);
}
},
}

experiment_state.ellipses_drawn = true;
Expand Down
1 change: 1 addition & 0 deletions src/state/experiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub enum DrawingMethod{
Circular,
Spiral,
Gaussian,
Phyllotaxis
}

#[derive(Debug,Resource)]
Expand Down
3 changes: 2 additions & 1 deletion src/system/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub fn display_instruction_system(
DrawingMethod::Grid => DrawingMethod::Circular,
DrawingMethod::Circular => DrawingMethod::Spiral,
DrawingMethod::Spiral => DrawingMethod::Gaussian,
DrawingMethod::Gaussian => DrawingMethod::Uniform,
DrawingMethod::Gaussian => DrawingMethod::Phyllotaxis,
DrawingMethod::Phyllotaxis => DrawingMethod::Uniform,
};
}

Expand Down

0 comments on commit 5cf3a7e

Please sign in to comment.