Verified Commit 772408e0 authored by Jenny's avatar Jenny
Browse files

added circle module

parent 91607184
use std::io::prelude::Write;
use std::net::TcpStream;
pub fn draw_circle(host: &str, radius: u32, center_x: u32, center_y: u32, color: &str) {
// r^2 = x^2 + y^2
let center_x: f32 = center_x as f32;
let center_y: f32 = center_y as f32;
let mut area: Vec<String> = Vec::new();
for r in 0..=radius {
for x in 0..=r {
// y^2 = r^2 - x^2
let x = x as f32;
let r2: f32 = (r * r) as f32;
let x2: f32 = x * x;
let y2: f32 = r2 - x2;
let y = y2.sqrt().round();
let target_x_pos = x + center_x;
let target_x_neg = -1.0 * x + center_x;
let target_y_pos = y + center_y;
let target_y_neg = -1.0 * y + center_y;
let target_x: u32 = target_x_pos as u32;
let target_y: u32 = target_y_pos as u32;
let msg = format!("PX {} {} {}\n", target_x, target_y, color);
area.push(msg);
if target_x_neg >= 0.0 {
let target_x: u32 = target_x_neg as u32;
let target_y: u32 = target_y_pos as u32;
let msg = format!("PX {} {} {}\n", target_x, target_y, color);
area.push(msg);
}
if target_y_neg >= 0.0 {
let target_x: u32 = target_x_pos as u32;
let target_y: u32 = target_y_neg as u32;
let msg = format!("PX {} {} {}\n", target_x, target_y, color);
area.push(msg);
}
if target_x_neg >= 0.0 && target_y_neg >= 0.0 {
let target_x: u32 = target_x_neg as u32;
let target_y: u32 = target_y_neg as u32;
let msg = format!("PX {} {} {}\n", target_x, target_y, color);
area.push(msg);
}
}
}
let mut stream = TcpStream::connect(host).expect("Failed to connect!");
loop {
for pos in area.iter() {
stream.write(pos.as_bytes()).expect("Failed to send message!");
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ use clap::{Arg, App};
mod image;
mod rect;
mod circle;
const VERSION: &str = "1.2.0";
const AUTHOR: &str = "Netali <me@netali.de>";
......@@ -133,6 +134,46 @@ fn main() {
.required(false)
)
)
.subcommand(
App::new("circle")
.version(VERSION)
.author(AUTHOR)
.about("Circle spammer module (work in progress)")
.arg(Arg::new("color")
.short('c')
.long("color")
.value_name("RGB-HEX-COLOR")
.about("Hex-color of the circle (with optional alpha value)")
.takes_value(true)
.required(true)
)
.arg(Arg::new("radius")
.short('r')
.long("radius")
.value_name("RADIUS")
.about("Radius of the circle")
.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();
......@@ -161,6 +202,15 @@ fn main() {
rect::draw_rect(host, color, slices, height, width, offset_x, offset_y, shuffle);
}
Some("circle") => {
let matches = matches.subcommand_matches("circle").unwrap();
let color = matches.value_of("color").unwrap();
let radius: u32 = matches.value_of_t_or_exit("radius");
let offset_x: u32 = matches.value_of_t_or_exit("offset-x");
let offset_y: u32 = matches.value_of_t_or_exit("offset-y");
circle::draw_circle(host, radius, offset_x, offset_y, color);
}
None => {
println!("No subcommand specified!");
}
......
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