mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-26 03:51:45 +00:00
prepare basic crate signature and API functionality
This commit is contained in:
parent
ef80491813
commit
4d15cefdbd
23
src/cell.rs
23
src/cell.rs
@ -6,6 +6,9 @@ use crate::K2;
|
|||||||
use crate::Q;
|
use crate::Q;
|
||||||
use crate::WIDTH;
|
use crate::WIDTH;
|
||||||
|
|
||||||
|
use reqwest::Error;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
// Class to store information about each cell
|
// Class to store information about each cell
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct Cell {
|
pub struct Cell {
|
||||||
@ -100,7 +103,11 @@ fn map_num(n: usize, s: usize, e: usize, a: usize, b: usize) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Display grid in console
|
// Display grid in console
|
||||||
pub fn display_grid(grid: &Vec<Vec<Cell>>) {
|
pub async fn display_grid(client: &reqwest::Client, grid: &Vec<Vec<Cell>>) -> Result<(), Error> {
|
||||||
|
let w = 192 / WIDTH;
|
||||||
|
let h = 192 / HEIGHT;
|
||||||
|
|
||||||
|
let mut map_list = Vec::new();
|
||||||
for j in 0..HEIGHT {
|
for j in 0..HEIGHT {
|
||||||
for i in 0..WIDTH {
|
for i in 0..WIDTH {
|
||||||
// Get cell in grid
|
// Get cell in grid
|
||||||
@ -114,6 +121,20 @@ pub fn display_grid(grid: &Vec<Vec<Cell>>) {
|
|||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create formdata serializable object
|
||||||
|
let mut fdata = HashMap::new();
|
||||||
|
fdata.insert("instructions", serde_json::to_string(&map_list).unwrap());
|
||||||
|
|
||||||
|
// Send POST request
|
||||||
|
let response = client
|
||||||
|
.post("http://10.42.0.1:8080/instructions")
|
||||||
|
.form(&fdata)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
println!("Status Code: {}", response.status());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate next generation
|
// Calculate next generation
|
||||||
|
@ -20,11 +20,12 @@ use std::{thread, time::Duration};
|
|||||||
async fn main() -> Result<(), Error> {
|
async fn main() -> Result<(), Error> {
|
||||||
// Initialize grid randomly
|
// Initialize grid randomly
|
||||||
let mut grid = init_grid(None);
|
let mut grid = init_grid(None);
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Display current generation
|
// Display current generation
|
||||||
print!("{esc}[2J{esc}[1;1H", esc = 27 as char);
|
print!("{esc}[2J{esc}[1;1H", esc = 27 as char);
|
||||||
display_grid(&grid);
|
display_grid(&client, &grid).await?;
|
||||||
// Calculate next generation and wait
|
// Calculate next generation and wait
|
||||||
update_grid(&mut grid);
|
update_grid(&mut grid);
|
||||||
thread::sleep(Duration::from_millis(1000 / (FPS as u64)));
|
thread::sleep(Duration::from_millis(1000 / (FPS as u64)));
|
||||||
|
Loading…
Reference in New Issue
Block a user