Verified Commit f514205e authored by Jenny's avatar Jenny
Browse files

added rect feature

parent 4f2e1cde
......@@ -33,7 +33,7 @@ fn draw_image_slice(image_path: &String, host: &String, offset_x: u32, offset_y:
//stream.shutdown(Shutdown::Both).expect("Failed to shutdown connection!");
}
pub fn slice_image(image_path: &str, host: &str, slices: u32, offset_x: u32, offset_y: u32) {
pub fn draw_sliced_image(image_path: &str, host: &str, slices: u32, offset_x: u32, offset_y: u32) {
let img = image::open(Path::new(image_path)).expect("Failed to open image!");
let x_max = img.dimensions().0 - 1;
......
use clap::{Arg, App};
mod image;
mod rect;
const VERSION: &str = "1.1.0";
const AUTHOR: &str = "Netali <me@netali.de>";
......@@ -58,6 +59,54 @@ fn main() {
.default_value("0")
)
)
.subcommand(
App::new("rect")
.version(VERSION)
.author(AUTHOR)
.about("Rectangle spammer module")
.arg(Arg::new("color")
.short('c')
.long("color")
.value_name("RGB-HEX-COLOR")
.about("Hex-color to fill the rectangle (with optional alpha value)")
.takes_value(true)
.required(true)
)
.arg(Arg::new("height")
.short('h')
.long("height")
.value_name("HEIGHT")
.about("Height of the rectangle")
.takes_value(true)
.required(true)
)
.arg(Arg::new("width")
.short('w')
.long("width")
.value_name("WIDTH")
.about("width of the rectangle")
.takes_value(true)
.required(true)
)
.arg(Arg::new("offset-x")
.short('x')
.long("xoffset")
.value_name("OFFSET")
.about("Offset on the x-axis")
.takes_value(true)
.required(false)
.default_value("0")
)
.arg(Arg::new("offset-y")
.short('y')
.long("yoffset")
.value_name("OFFSET")
.about("Offset on the y-axis")
.takes_value(true)
.required(false)
.default_value("0")
)
)
.get_matches();
let host = matches.value_of("host").unwrap();
......@@ -70,7 +119,17 @@ fn main() {
let offset_x: u32 = matches.value_of_t_or_exit("offset-x");
let offset_y: u32 = matches.value_of_t_or_exit("offset-y");
image::slice_image(image_path, host, slices, offset_x, offset_y);
image::draw_sliced_image(image_path, host, slices, offset_x, offset_y);
}
Some("rect") => {
let matches = matches.subcommand_matches("rect").unwrap();
let color = matches.value_of("color").unwrap();
let height: u32 = matches.value_of_t_or_exit("height");
let width: u32 = matches.value_of_t_or_exit("width");
let offset_x: u32 = matches.value_of_t_or_exit("offset-x");
let offset_y: u32 = matches.value_of_t_or_exit("offset-y");
rect::draw_rect(host, color, height, width, offset_x, offset_y);
}
None => {
println!("No subcommand specified!");
......
use std::io::prelude::Write;
use std::net::TcpStream;
pub fn draw_rect(host: &str, color: &str, height: u32, width: u32, offset_x: u32, offset_y: u32) {
let mut stream = TcpStream::connect(host).expect("Failed to connect!");
loop {
for x in 0..=width {
for y in 0..=height {
let target_x = x + offset_x;
let target_y = y + offset_y;
let msg = format!("PX {} {} {}\n", target_x, target_y, color);
stream.write(msg.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