{"id":736,"date":"2021-09-14T21:18:39","date_gmt":"2021-09-15T01:18:39","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/?p=736"},"modified":"2021-09-14T21:18:46","modified_gmt":"2021-09-15T01:18:46","slug":"lsh-lineexercises","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/lsh\/09\/14\/lsh-lineexercises\/","title":{"rendered":"lsh-LineExercises"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.24.34-PM-601x480.png\" alt=\"\" width=\"601\" height=\"480\" class=\"alignnone size-medium wp-image-737\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.24.34-PM-601x480.png 601w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.24.34-PM-1024x818.png 1024w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.24.34-PM-768x614.png 768w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.24.34-PM-1536x1228.png 1536w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.24.34-PM-2048x1637.png 2048w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.24.34-PM-1200x959.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.11-PM-464x480.png\" alt=\"\" width=\"464\" height=\"480\" class=\"alignnone size-medium wp-image-738\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.11-PM-464x480.png 464w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.11-PM-991x1024.png 991w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.11-PM-768x794.png 768w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.11-PM-1486x1536.png 1486w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.11-PM-1200x1240.png 1200w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.11-PM.png 1664w\" sizes=\"(max-width: 464px) 85vw, 464px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.41-PM-464x480.png\" alt=\"\" width=\"464\" height=\"480\" class=\"alignnone size-medium wp-image-739\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.41-PM-464x480.png 464w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.41-PM-991x1024.png 991w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.41-PM-768x794.png 768w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.41-PM-1486x1536.png 1486w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.41-PM-1200x1240.png 1200w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.25.41-PM.png 1664w\" sizes=\"(max-width: 464px) 85vw, 464px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.13-PM-601x480.png\" alt=\"\" width=\"601\" height=\"480\" class=\"alignnone size-medium wp-image-741\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.13-PM-601x480.png 601w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.13-PM-1024x818.png 1024w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.13-PM-768x614.png 768w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.13-PM-1536x1228.png 1536w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.13-PM-2048x1637.png 2048w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.13-PM-1200x959.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.34-PM-601x480.png\" alt=\"\" width=\"601\" height=\"480\" class=\"alignnone size-medium wp-image-742\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.34-PM-601x480.png 601w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.34-PM-1024x818.png 1024w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.34-PM-768x614.png 768w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.34-PM-1536x1228.png 1536w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.34-PM-2048x1637.png 2048w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.26.34-PM-1200x959.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.27.01-PM-464x480.png\" alt=\"\" width=\"464\" height=\"480\" class=\"alignnone size-medium wp-image-743\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.27.01-PM-464x480.png 464w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.27.01-PM-991x1024.png 991w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.27.01-PM-768x794.png 768w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.27.01-PM-1486x1536.png 1486w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.27.01-PM-1200x1240.png 1200w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-14-at-7.27.01-PM.png 1664w\" sizes=\"(max-width: 464px) 85vw, 464px\" \/><\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/weights.svg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/weights.svg\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-medium wp-image-745\" \/><\/a><\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/calligraphic-1.svg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/calligraphic-1.svg\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-medium wp-image-748\" \/><\/a><\/p>\n<p>I decided to do the following exercises in Rust as a technical challenge. This proved to be a little bit more of an undertaking than I expected, so here are some notes on some of the hurdles I ran into.<\/p>\n<p>I decided to use <a href=\"https:\/\/nannou.cc\/\">nannou<\/a> for most of the exercises, since I did not want to attempt implementing each interaction I needed in <a href=\"https:\/\/wgpu.rs\/\">WGPU<\/a>. Nannou seems incredibly powerful, but the guide left much to be desired (when they become more complete I will definitely come back for another look!). Figuring out registering the events I cared about took a significant amount of searching, since the guide did not seem to document it. Eventually I ended up using the <a href=\"https:\/\/github.com\/nannou-org\/nannou\/blob\/master\/examples\/nannou_basics\/all_functions.rs\">all_functions example<\/a> as a base and removing everything I didn&#8217;t care about. The second quirk that came up was nannou&#8217;s coordinate system, which puts the origin at the center of the screen. This proved to be problematic later on as I moved to SVG.<\/p>\n<p>Rust also is completely opposed to implicit casts, which is fair, but also meant a lot of code was shifting between data structures. This was particularly apparent in managing the points for lines, which required taking the VecDeque.to_owned() each frame for drawing the polyline.<\/p>\n<p>The SVG generation was its own ordeal. Nannou&#8217;s line builder seems to use the <a href=\"https:\/\/github.com\/nical\/lyon\">lyon<\/a> package for SVG rendering. <a href=\"https:\/\/github.com\/nannou-org\/nannou\/issues\/379\">Lyon however does not allow actually exporting an SVG<\/a>, so I ended up using the svg crate. It is also worth mentioning that the svg crate seems to be set up in a way which makes it hard to create SVGs programmatically. Specifically, I had to define the &#8220;Data&#8221; element mutable and constantly reassign it to the result of data.move_to() or data.line_to().<\/p>\n<p>All in all, I would say the technical challenge was fun to play with, but I would not recommend this method over more mature frameworks like Processing or openFrameworks.<\/p>\n<p>Feel free to check out the code behind the images above on <a href=\"https:\/\/github.com\/lsh\/line-exercises-rs\">GitHub<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I decided to do the following exercises in Rust as a technical challenge. This proved to be a little bit more of an undertaking than I expected, so here are some notes on some of the hurdles I ran into. I decided to use nannou for most of the exercises, since I did not want &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/lsh\/09\/14\/lsh-lineexercises\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;lsh-LineExercises&#8221;<\/span><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/736"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":6,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":760,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/736\/revisions\/760"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/categories?post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/tags?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}