{"id":396,"date":"2012-08-23T19:18:55","date_gmt":"2012-08-24T02:18:55","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/infs1609\/?p=396"},"modified":"2012-08-26T21:48:29","modified_gmt":"2012-08-27T04:48:29","slug":"lab-week-7-multidimensional-arrays","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/infs1609\/blog\/2012\/08\/lab-week-7-multidimensional-arrays\/","title":{"rendered":"Lab Week 7 &#8211; Multidimensional Arrays"},"content":{"rendered":"<p>In this tutorial you will be working with 2D arrays to do some image manipulation.<\/p>\n<p>Download the BlueJ project\u00a0<a href=\"http:\/\/www.cse.unsw.edu.au\/~is1609\/12s2\/examples\/ASCIIArt.zip\">ASCIIArt.zip<\/a>. Inside you will find a class that contains the method\u00a0<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 \u20193\u2032 pixels) with a white border (the bright \u20195\u2032 pixels) pointing to the right on a black background (the \u20190\u2032 pixels).<\/p>\n<p>Your tasks:<\/p>\n<ol>\n<li>Write a method to\u00a0<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<tbody>\n<tr>\n<th>Brightness<\/th>\n<th>Character<\/th>\n<\/tr>\n<tr>\n<td><\/td>\n<td>0<\/td>\n<td><code>'X'<\/code><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>1<\/td>\n<td><code>'8'<\/code><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>2<\/td>\n<td><code>'o'<\/code><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>3<\/td>\n<td><code>':'<\/code><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>4<\/td>\n<td><code>'.'<\/code><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>5<\/td>\n<td><code>' '<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>So the triangle above would be rendered as:<br \/>\n<code><br \/>\n<strong> <\/strong><\/code><\/p>\n<p><code><strong><\/p>\n<pre>XXXXXXXXX\r\nX XXXXXXX\r\nX   XXXXX\r\nX ::  XXX\r\nX ::::  X\r\nX ::  XXX\r\nX   XXXXX\r\nX XXXXXXX\r\nXXXXXXXXX<\/pre>\n<p><\/strong><\/code><code><strong> <\/strong><br \/>\n<\/code><\/li>\n<li>Write a method to\u00a0<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\u00a0<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\u00a0<strong>rotate<\/strong> an image clockwise. It should input an image and return a rotated copy.<\/li>\n<\/ol>\n<p>Try these sample images<\/p>\n<ol>\n<li>http:\/\/sfpl.org\/images\/graphics\/chicklets\/google-small.png<\/li>\n<li>http:\/\/a0.twimg.com\/profile_images\/2258868342\/Pokemon_Red_Sprite_normal.jpg<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial you will be working with 2D arrays to do some image manipulation. Download the BlueJ project\u00a0ASCIIArt.zip. Inside you will find a class that contains the method\u00a0readImage(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 the 2D [&hellip;]<\/p>\n","protected":false},"author":328,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[236],"tags":[],"class_list":["post-396","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/users\/328"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/comments?post=396"}],"version-history":[{"count":6,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/396\/revisions"}],"predecessor-version":[{"id":405,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/396\/revisions\/405"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/media?parent=396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/categories?post=396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/tags?post=396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}