commit 34dfa98509bbcd0603d9b341115abbe4b6509f70
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date: Mon, 28 May 2018 00:05:11 -0500
Initial commit.
Diffstat:
5 files changed, 107 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,4 @@
+/target
+**/*.rs.bk
+.bak
+*.svg+
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
@@ -0,0 +1,14 @@
+[[package]]
+name = "logo"
+version = "0.1.0"
+dependencies = [
+ "svg 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "svg"
+version = "0.5.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum svg 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "5ce4450d6982b758228fa5407db2fc27cefccb013c170ade23c03ec3a643bb72"
diff --git a/Cargo.toml b/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "logo"
+version = "0.1.0"
+authors = ["Shimmy Xu <shimmy1996@users.noreply.github.com>"]
+
+[dependencies]
+svg = "0.5.10"+
\ No newline at end of file
diff --git a/README.org b/README.org
@@ -0,0 +1,3 @@
+* Logo
+A simple script that generates my avatar icon thingy in any given size.
+Output format is =.svg=.
diff --git a/src/main.rs b/src/main.rs
@@ -0,0 +1,77 @@
+extern crate svg;
+
+use std::cmp;
+use std::io;
+use std::vec::Vec;
+use svg::Document;
+use svg::node::element::Polygon;
+use svg::node::element::Rectangle;
+
+fn print_points(points: &Vec<(f64, f64)>) -> String {
+ let mut result = String::new();
+ for point in points.iter() {
+ result.push_str(&format!("{},{} ", point.0, point.1));
+ }
+ result
+}
+
+fn main() -> io::Result<()> {
+ let primary_color = "#700000";
+ let secondary_color = "#707070";
+
+ let mut input = String::new();
+ println!("Desired width:");
+ io::stdin().read_line(&mut input)?;
+ let width = input.trim().parse::<i32>().unwrap();
+ input.clear();
+ println!("Desired height:");
+ io::stdin().read_line(&mut input)?;
+ let height = input.trim().parse::<i32>().unwrap();
+
+ let unit: f64 = (cmp::min(width, height) as f64) / 10.;
+ let center: (f64, f64) = ((width as f64) / 2., (height as f64) / 2.);
+
+ let flare_points: Vec<(f64, f64)> = vec![
+ (center.0 - 3. * unit, center.1),
+ (center.0 - 6. / 5. * unit, center.1 - 6. / 5. * unit),
+ (center.0 + 2. / 3. * center.1 - 2. * unit, 0.),
+ (width as f64, 0.),
+ (width as f64, center.1 + 2. * unit - 2. / 3. * center.0),
+ (center.0 + 6. / 5. * unit, center.1 + 6. / 5. * unit),
+ (center.0, center.1 + 3. * unit),
+ (center.0 - 6. / 5. * unit, center.1 + 6. / 5. * unit),
+ ];
+
+ let star_points: Vec<(f64, f64)> = vec![
+ (center.0 - 2. * unit, center.1),
+ (center.0 - 2. / 3. * unit, center.1 - 2. / 3. * unit),
+ (center.0, center.1 - 2. * unit),
+ (center.0 + 2. / 3. * unit, center.1 - 2. / 3. * unit),
+ (center.0 + 2. * unit, center.1),
+ (center.0 + 2. / 3. * unit, center.1 + 2. / 3. * unit),
+ (center.0, center.1 + 2. * unit),
+ (center.0 - 2. / 3. * unit, center.1 + 2. / 3. * unit),
+ ];
+
+ let sky = Rectangle::new()
+ .set("width", width)
+ .set("height", height)
+ .set("fill", primary_color);
+
+ let flare = Polygon::new()
+ .set("points", print_points(&flare_points))
+ .set("fill", secondary_color);
+
+ let star = Polygon::new()
+ .set("points", print_points(&star_points))
+ .set("fill", primary_color);
+
+ let document = Document::new()
+ .set("viewBox", (0, 0, width, height))
+ .add(sky)
+ .add(flare)
+ .add(star);
+
+ svg::save("logo.svg", &document).unwrap();
+ Ok(())
+}