sunjay / turtle

Create Animated Drawings in Rust
http://turtle.rs
Mozilla Public License 2.0
559 stars 54 forks source link

adding a write example #226

Closed JuanMarchetto closed 3 years ago

JuanMarchetto commented 3 years ago

Hi, i'm creating this example that draw any text you want. For example, if you run in console: cargo run --example write hello it will draw "Hello" if you don't introduce any text: cargo run --example write it will draw "Hello, World!" Captura de pantalla de 2021-02-21 19-56-03

you can also pass a font size as a second parameter: cargo run --example write "Hello, World!" 50 and all the letters will ajust to that size, if you don't pass that second parameter 20.0 will be the default.

I still need to implement some more letter but i like to show you the progress at this point. At this point if you introduce a character that currently doesn't have an implemtations will we replaced with '?' and in the console it will trow the followinig message:

Captura de pantalla de 2021-02-21 20-59-59

I hope you like it.

codecov[bot] commented 3 years ago

Codecov Report

Merging #226 (bf3e244) into master (3469f15) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #226   +/-   ##
=======================================
  Coverage   61.17%   61.17%           
=======================================
  Files          40       40           
  Lines        2697     2697           
=======================================
  Hits         1650     1650           
  Misses       1047     1047           

Continue to review full report at Codecov.

Legend - Click here to learn more Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data Powered by Codecov. Last update 3469f15...bf3e244. Read the comment docs.

sunjay commented 3 years ago

This is a very cool idea @JuanMarchetto! Great work! 😁 πŸŽ‰

I'm glad you chose to submit this early, as big examples like this often need a lot of feedback, so discussing it earlier is always better than later. Lots of code to review!

I won't have a chance to look at this in detail for a few days, but here's a couple of things I noticed from skimming through the code:

Argument Parsing Code ```rust use std::env; use std::process; fn main() { let (text, font_size) = parse_args(); println!("{}", text); println!("{}", font_size); } /// Parses the command line arguments or exits with a help message if there was /// an error fn parse_args() -> (String, f64) { let mut args = env::args(); // Skip the first argument (the executable name) args.next(); // First argument is the text to draw let text = match args.next() { Some(text) if text == "--help" => print_help(), // This can produce any text, including the empty string Some(text) => text, // Default to `Hello, World!` None => "Hello, World!".to_string(), }; // Second argument is the font size let font_size: f64 = match args.next() { Some(text) if text == "--help" => print_help(), Some(font_size) => match font_size.parse() { Ok(font_size) => if font_size >= 1.0 { font_size } else { println!("Font size argument must be at least 1.0"); println!(); print_help(); }, Err(err) => { println!("Font size argument must be a valid number: {}", err); println!(); print_help(); }, }, // Default to a font size of 20 None => 20.0, }; // Not expecting any other arguments if args.next().is_some() { print_help() } (text, font_size) } /// Prints the help message and then exits /// /// `!` is the "never type" and it means this function never returns fn print_help() -> ! { println!("Draws text on the screen using the turtle."); println!(); println!("EXAMPLES:"); println!(" cargo run --example letters 'Wow! So cool!'"); println!(" Draw the text 'Wow! So cool!'"); println!(); println!(" cargo run --example letters 'Big text!' 50"); println!(" Draw the text 'Big text!' with font size 50"); println!(); println!(" cargo run --example letters -- --help"); println!(" Show this help information"); println!(); println!("FLAGS:"); println!(" --help show this help information"); process::exit(0) } ```

Overall, really great work with this PR! It might take a little longer than last time to review and get merged since there is much more code, but I'm really looking forward to working with you to get this finished. Thanks for taking the time to work on this! πŸ₯³ πŸŽ‰

sunjay commented 3 years ago

Hey @JuanMarchetto I saw you pushed a new commit. Let me know when you're ready for a review. If you think this PR is ready, you can convert it from a draft PR to a regular PR.

JuanMarchetto commented 3 years ago

Hey @JuanMarchetto I saw you pushed a new commit. Let me know when you're ready for a review. If you think this PR is ready, you can convert it from a draft PR to a regular PR.

Hey @sunjay this is not ready yet, I've been busy this week, but the next one I'll will get back to this and let you know when is ready. Thanks!

sunjay commented 3 years ago

Sounds good! Take as much time as you need. Just wanted to make sure you weren't waiting on me. :)

Happy to help out with anything if you run into any issues. Thanks for all your work!

JuanMarchetto commented 3 years ago

@sunjay i made some progress here, i don't know how to address the coverage failing status do. and if you what this is ready to rewiev. thanks!

sunjay commented 3 years ago

@JuanMarchetto Great! I will have a look over a few days. If I don't get back to you by next week please don't hesitate to ping me. (Hoping to have it done much sooner than that, but thought I'd mention it just in case.)

Don't worry about the coverage status. Only the required statuses + an approval from me are needed to get this merged. :)

JuanMarchetto commented 3 years ago

@JuanMarchetto Great! I will have a look over a few days. If I don't get back to you by next week please don't hesitate to ping me. (Hoping to have it done much sooner than that, but thought I'd mention it just in case.)

Don't worry about the coverage status. Only the required statuses + an approval from me are needed to get this merged. :)

Hi @sunjay, can you have a look to this PR? Thanks!

sunjay commented 3 years ago

Hi @sunjay, can you have a look to this PR? Thanks!

Hey @JuanMarchetto! Sorry for the delay. I saw that you were still pushing things and assumed that you were still working on it. I will take a look over the next few days. Thanks for all your effort! 😁 πŸŽ‰

sunjay commented 3 years ago

Hey! Really sorry for not getting to your PR yet. Going through some things and will try to find time soon. I usually try to be really quick with these things, but it unfortunately didn't work out this time. I will get to this! :)

JuanMarchetto commented 3 years ago

Hey! Really sorry for not getting to your PR yet. Going through some things and will try to find time soon. I usually try to be really quick with these things, but it unfortunately didn't work out this time. I will get to this! :)

Hey sunjay, don't worry, i hope you are fine!