Verified Commit 225affda authored by Jenny's avatar Jenny
Browse files

unified draw_area methods

parent e4153567
use std::io::prelude::Write;
use std::net::TcpStream;
use std::thread;
use std::thread::JoinHandle;
use rand::thread_rng;
use rand::seq::SliceRandom;
fn draw_circle_slice(host: String, area: Vec<String>) {
let mut stream = TcpStream::connect(host).expect("Failed to connect!");
let area_string: String = area.into_iter().collect();
loop {
stream.write(area_string.as_bytes()).expect("Failed to send message!");
}
}
use crate::utils;
pub fn draw_circle(host: &str, color: &str, slices: u8, radius: u16, center_x: u16, center_y: u16, shuffle: bool) {
let center_x = center_x as i32;
......@@ -90,7 +79,7 @@ pub fn draw_circle(host: &str, color: &str, slices: u8, radius: u16, center_x: u
}
let t = thread::spawn(move || {
draw_circle_slice(host_string, slice_area);
utils::draw_area(host_string, slice_area);
});
threads.push(t);
......
use std::io::prelude::Write;
use std::net::TcpStream;
use std::path::Path;
use std::thread;
......@@ -8,17 +6,9 @@ use std::thread::JoinHandle;
use rand::thread_rng;
use rand::seq::SliceRandom;
use image::GenericImageView;
fn draw_image_slice(host: String, area: Vec<String>) {
let mut stream = TcpStream::connect(host).expect("Failed to connect!");
let area_string: String = area.into_iter().collect();
use crate::utils;
loop {
stream.write(area_string.as_bytes()).expect("Failed to send message!");
}
}
use image::GenericImageView;
pub fn draw_image(image_path: &str, host: &str, slices: u8, offset_x: u32, offset_y: u32, shuffle: bool, skip_alpha: u8) {
let img = image::open(Path::new(image_path)).expect("Failed to open image!");
......@@ -68,7 +58,7 @@ pub fn draw_image(image_path: &str, host: &str, slices: u8, offset_x: u32, offse
}
let t = thread::spawn(move || {
draw_image_slice(host_string, slice_area);
utils::draw_area(host_string, slice_area);
});
threads.push(t);
......
......@@ -3,6 +3,7 @@ use clap::{Arg, App};
mod image;
mod rect;
mod circle;
mod utils;
const VERSION: &str = "1.4.0";
const AUTHOR: &str = "Netali <me@netali.de>";
......
use std::io::prelude::Write;
use std::net::TcpStream;
use std::thread;
use std::thread::JoinHandle;
use rand::thread_rng;
use rand::seq::SliceRandom;
fn draw_rect_slice(host: String, area: Vec<String>) {
let mut stream = TcpStream::connect(host).expect("Failed to connect!");
let area_string: String = area.into_iter().collect();
loop {
stream.write(area_string.as_bytes()).expect("Failed to send message!");
}
}
use crate::utils;
pub fn draw_rect(host: &str, color: &str, slices: u8, height: u32, width: u32, offset_x: u32, offset_y: u32, shuffle: bool) {
let mut area: Vec<String> = Vec::new();
......@@ -57,7 +45,7 @@ pub fn draw_rect(host: &str, color: &str, slices: u8, height: u32, width: u32, o
}
let t = thread::spawn(move || {
draw_rect_slice(host_string, slice_area);
utils::draw_area(host_string, slice_area);
});
threads.push(t);
......
use std::io::prelude::Write;
use std::net::TcpStream;
pub fn draw_area(host: String, area: Vec<String>) {
let mut stream = TcpStream::connect(host).expect("Failed to connect!");
let area_string: String = area.into_iter().collect();
loop {
stream.write(area_string.as_bytes()).expect("Failed to send message!");
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment