refactor: reformatted code, removed redundant code
This commit is contained in:
parent
b57ed1fa70
commit
d39e337002
32
src/main.rs
32
src/main.rs
@ -1,15 +1,13 @@
|
|||||||
use crossterm::cursor::MoveTo;
|
use crossterm::cursor::MoveTo;
|
||||||
use crossterm::style::Attribute::Dim;
|
use crossterm::event::{poll, read, Event, KeyCode};
|
||||||
use crossterm::style::{Color, Print, SetForegroundColor};
|
use crossterm::style::{Color, Print, SetForegroundColor};
|
||||||
use crossterm::terminal::{Clear, ClearType, enable_raw_mode};
|
use crossterm::terminal::{enable_raw_mode, Clear, ClearType};
|
||||||
use crossterm::{execute, QueueableCommand};
|
use crossterm::{QueueableCommand};
|
||||||
use ndarray::{arr1, arr2, Array1, Array2};
|
use ndarray::{arr1, arr2, Array1};
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use crossterm::event::{Event, KeyCode, poll, read};
|
|
||||||
|
|
||||||
const X_DRAW_SCALING_FACTOR: f32 = 2.8;
|
const X_DRAW_SCALING_FACTOR: f32 = 2.8;
|
||||||
|
|
||||||
@ -158,14 +156,11 @@ fn plot_line_vertical(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
static ANGLE: Mutex<f32> = Mutex::new(0.);
|
|
||||||
|
|
||||||
fn draw_rotating_mesh(meshes: Vec<Mesh>) -> anyhow::Result<()> {
|
fn draw_rotating_mesh(meshes: Vec<Mesh>) -> anyhow::Result<()> {
|
||||||
let mut angle = (0., 0., 0.);
|
let mut angle = (0., 0., 0.);
|
||||||
let mut zoom = 1.;
|
let mut zoom = 1.;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
||||||
if poll(Duration::from_millis(10))? {
|
if poll(Duration::from_millis(10))? {
|
||||||
if let Event::Key(key) = read()? {
|
if let Event::Key(key) = read()? {
|
||||||
match key.code {
|
match key.code {
|
||||||
@ -178,7 +173,7 @@ fn draw_rotating_mesh(meshes: Vec<Mesh>) -> anyhow::Result<()> {
|
|||||||
KeyCode::Char(',') => zoom = 0.2f32.max(zoom - 0.02),
|
KeyCode::Char(',') => zoom = 0.2f32.max(zoom - 0.02),
|
||||||
KeyCode::Char('.') => zoom = 1f32.min(zoom + 0.02),
|
KeyCode::Char('.') => zoom = 1f32.min(zoom + 0.02),
|
||||||
KeyCode::Esc | KeyCode::Backspace | KeyCode::Char('c') => exit(0),
|
KeyCode::Esc | KeyCode::Backspace | KeyCode::Char('c') => exit(0),
|
||||||
_ => {},
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -246,7 +241,6 @@ fn draw_rotating_mesh(meshes: Vec<Mesh>) -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
|
|
||||||
let random_rectangle = Mesh {
|
let random_rectangle = Mesh {
|
||||||
@ -255,20 +249,12 @@ fn main() -> anyhow::Result<()> {
|
|||||||
arr1(&[0., 10., 0.]),
|
arr1(&[0., 10., 0.]),
|
||||||
arr1(&[10., 0., 0.]),
|
arr1(&[10., 0., 0.]),
|
||||||
arr1(&[0., -10., 0.]),
|
arr1(&[0., -10., 0.]),
|
||||||
|
|
||||||
|
|
||||||
],
|
|
||||||
edges: vec![
|
|
||||||
[0, 1],
|
|
||||||
[1, 2],
|
|
||||||
[2, 3],
|
|
||||||
[3, 0],
|
|
||||||
],
|
],
|
||||||
|
edges: vec![[0, 1], [1, 2], [2, 3], [3, 0]],
|
||||||
line_color: Some(Color::Red),
|
line_color: Some(Color::Red),
|
||||||
node_color: Some(Color::DarkRed)
|
node_color: Some(Color::DarkRed),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let cube = vec![
|
let cube = vec![
|
||||||
arr1(&[-10., -10., 10.]),
|
arr1(&[-10., -10., 10.]),
|
||||||
arr1(&[-10., 10., 10.]),
|
arr1(&[-10., 10., 10.]),
|
||||||
@ -288,20 +274,16 @@ fn main() -> anyhow::Result<()> {
|
|||||||
[0, 2],
|
[0, 2],
|
||||||
[1, 3],
|
[1, 3],
|
||||||
[2, 3],
|
[2, 3],
|
||||||
|
|
||||||
// right face
|
// right face
|
||||||
[4, 5],
|
[4, 5],
|
||||||
[4, 6],
|
[4, 6],
|
||||||
[5, 7],
|
[5, 7],
|
||||||
[6, 7],
|
[6, 7],
|
||||||
|
|
||||||
// center edges
|
// center edges
|
||||||
[0, 8],
|
[0, 8],
|
||||||
[3, 8],
|
[3, 8],
|
||||||
|
|
||||||
[4, 9],
|
[4, 9],
|
||||||
[7, 9],
|
[7, 9],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let thing = Mesh {
|
let thing = Mesh {
|
||||||
|
Loading…
Reference in New Issue
Block a user