-
러스트로 "회전하는 도넛donut❤️" 출력하기 C언어로 하는거 보고 깃허브로 찾음코딩Coding/한글Rust강의★내가★공부하려고만듬 2022. 8. 14. 20:10728x90
C언어로 짠
Donut-shaped C code that generates a 3D spinning donut
회전하는 프린트로 시작
https://www.codegrepper.com/code-examples/rust/rust+spinning+rod+animation+in+text
https://economiceco.tistory.com/14689
❤️ Rust로 도넛 출력 하기 Donut is a 3D ASCII
https://github.com/Zaryob/donut
조그만한 도넛 ㅎㅎ
https://github.com/lucasvanmol/rusty-donut
Game of life
use rand::Rng; use std::collections::HashSet; use std::thread::sleep; use std::time::Duration; const X_MAX: i16 = 80; const Y_MAX: i16 = 60; fn main() { let mut world = HashSet::new(); let mut rng = rand::thread_rng(); for _ in 0..500 { let x = rng.gen_range(0..X_MAX); let y = rng.gen_range(0..Y_MAX); world.insert((x, y)); } loop { let new_world = iterate(X_MAX, Y_MAX, &world); display(X_MAX, Y_MAX, &new_world, &world); sleep(Duration::from_millis(50)); world = new_world; } } fn display( x_max: i16, y_max: i16, new_world: &HashSet<(i16, i16)>, old_world: &HashSet<(i16, i16)>, ) { print!("\x1B[2J\x1B[1;1H"); for y in 0..y_max { for x in 0..x_max { let point = (x, y); if new_world.contains(&point) { print!("O"); } else if old_world.contains(&point) { print!("."); } else { print!(" "); } } println!(); } } fn iterate(x_max: i16, y_max: i16, old_world: &HashSet<(i16, i16)>) -> HashSet<(i16, i16)> { let mut new_world = HashSet::new(); for x in 0..x_max { for y in 0..y_max { let mut n = 0; for (dx, dy) in [ (-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1), ] { if old_world.contains(&(x + dx, y + dy)) { n += 1; } } if n == 2 && old_world.contains(&(x, y)) { new_world.insert((x, y)); } if n == 3 { new_world.insert((x, y)); } } } new_world }
https://github.com/krisajenkins/game-of-life-rust
반응형'코딩Coding > 한글Rust강의★내가★공부하려고만듬' 카테고리의 다른 글
Haskell❤️JSON Parser 100% From Scratch in Haskell❤️ (0) 2022.08.17 ARM❤️Assembly Language Programming with ARM❤️ (0) 2022.08.16 러스트로 금융툴 만들기! 제3부 Making a finance tool with Rust! Part 3 (0) 2022.08.15 Rust로 만든 피아노 트레이너❤️Piano-trainer_Moemorize piano scale with ease! (0) 2022.08.14 Rust❤️Converts a Box<str> into a Box<[u8]> without copying or allocating. (0) 2022.08.14 Rust❤️Custom Deserialization with Serde (0) 2022.08.14 Inverting Binary Tree Without Recursion in Rust (0) 2022.08.14 Rust Termion❤️뭔가 만들때 쓰는 듯 터미널창에 마우스도 되고 다 되네 ㅎㅎ (0) 2022.08.14