{"id":403,"date":"2012-08-22T21:41:32","date_gmt":"2012-08-23T04:41:32","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=403"},"modified":"2012-08-22T21:43:06","modified_gmt":"2012-08-23T04:43:06","slug":"tutorial-wk-7-ascii-art","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2012\/08\/tutorial-wk-7-ascii-art\/","title":{"rendered":"Tutorial Wk 7 &#8211; ASCII Art"},"content":{"rendered":"<p>In this tutorial we will be working with 2D arrays to do some image manipulation.<\/p>\n<p>Download the BlueJ project <a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/labs\/ASCIIArt.zip\">ASCIIArt.zip<\/a>. Inside you will find a class that contains the method <code>readImage(String url)<\/code>. This method takes the URL for any image on the web and converts it into a 2D array of integers. Each entry in the 2D array represents the brightness of one pixel. The values range from zero (black) to 5 (white). Entries are arranged in width by height order so an array like:<br \/>\n<code><br \/>\n{{0, 0, 0, 0, 0, 0, 0, 0, 0},<br \/>\n {0, 5, 0, 0, 0, 0, 0, 0, 0}<br \/>\n {0, 5, 5, 5, 0, 0, 0, 0, 0},<br \/>\n {0, 5, 3, 3, 5, 5, 0, 0, 0},<br \/>\n {0, 5, 3, 3, 3, 3, 5, 5, 0},<br \/>\n {0, 5, 3, 3, 5, 5, 0, 0, 0},<br \/>\n {0, 5, 5, 5, 0, 0, 0, 0, 0},<br \/>\n {0, 5, 0, 0, 0, 0, 0, 0, 0},<br \/>\n {0, 0, 0, 0, 0, 0, 0, 0, 0}}<br \/>\n<\/code><br \/>\nrepresents a grey triangle (the &#8216;3&#8217; pixels) with a white border (the bright &#8216;5&#8217; pixels) pointing to the right on a black background (the &#8216;0&#8217; pixels).<\/p>\n<p>Your tasks:<\/p>\n<ol>\n<li>Write a method to <strong>draw<\/strong> an image on the console using ASCII art. That is, each pixel of the image is drawn as a character according to the following table:<br \/>\n<table>\n<tr>\n<th>Brightness<\/th>\n<th>Character<\/th>\n<\/tr>\n<td>\n<td>0<\/td>\n<td><code>'X'<\/code><\/td>\n<\/tr>\n<td>\n<td>1<\/td>\n<td><code>'8'<\/code><\/td>\n<\/tr>\n<td>\n<td>2<\/td>\n<td><code>'o'<\/code><\/td>\n<\/tr>\n<td>\n<td>3<\/td>\n<td><code>':'<\/code><\/td>\n<\/tr>\n<td>\n<td>4<\/td>\n<td><code>'.'<\/code><\/td>\n<\/tr>\n<td>\n<td>5<\/td>\n<td><code>' '<\/code><\/td>\n<\/tr>\n<\/table>\n<p>So the triangle above would be rendered as:<br \/>\n<code><br \/>\n<strong><\/p>\n<pre>\r\nXXXXXXXXX\r\nX XXXXXXX\r\nX   XXXXX\r\nX ::  XXX\r\nX ::::  X\r\nX ::  XXX\r\nX   XXXXX\r\nX XXXXXXX\r\nXXXXXXXXX\r\n<\/pre>\n<p><\/strong><br \/>\n<\/code>\n<\/li>\n<li>Write a method to <strong>invert<\/strong> an image, so that bright pixels are converted to dark and vice versa. It should input an image and return an inverted copy.<\/li>\n<li>Write a method to <strong>flip<\/strong> an image horizontally. It should input an image and return a flipped copy.<\/li>\n<li><strong>Challenge:<\/strong> Write a method to <strong>rotate<\/strong> an image clockwise. It should input an image and return a rotated copy.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we will be working with 2D arrays to do some image manipulation. Download the BlueJ project ASCIIArt.zip. Inside you will find a class that contains the method readImage(String url). This method takes the URL for any image on the web and converts it into a 2D array of integers. Each entry in [&hellip;]<\/p>\n","protected":false},"author":80,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[630],"tags":[],"class_list":["post-403","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/users\/80"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/comments?post=403"}],"version-history":[{"count":10,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/403\/revisions"}],"predecessor-version":[{"id":413,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/403\/revisions\/413"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}