We usually treat the outer array index as a row (y coordinate) and the inner array index as a column (x coordinate). In this assignment, we will be dealing with grayscale images, in which each pixel goes from black (0) to white (1). Part 1: Grayscale Images and TextĪs we discussed in our 2D arrays module, a 2D array is a natural data structure for image data, since an image is a two dimensional object with both an x and y coordinate for each pixel. Please download the skeleton code for this assignment. In this assignment, we will restrict ourselves to characters in the ASCII subset of UTF-8, including lowercase letters, uppercase letters, and some special characters hence the name “ASCII Art.” An example is given below with the UC logo. Students will write a program to automatically generate “ASCII Art”, which is text that approximates a given image. ![]() In this assignment, you will work with with 2D arrays in Java with a concrete, visual application. Please refer to the following readings and examples offering templates to help get you started: To traverse and manipulate a 2-dimensional array.The displayable ASCII values are only 32 (the space) through 126 (tilde) inclusive.CS173: Intro to Computer Science - ASCII Art (100 Points) Assignment Goals Others like DEL (ASCII 127) are simply hard to represent: how would you represent a delete character? Some of them like BEL (ASCII 7) are leftovers from the days of telegraphs and teletype machines. Those question marks inside boxes represent ASCII characters that cannot be displayed. ASCII 0 prints out a space, the closest representation to its real value, NUL. ASCII 9 has a lot of space after it because it is the tab character or “\t”. ASCII 10 is the new line character “\n”, and ASCII 13 is the old carriage return. And what are all those squiggly question marks in boxes about?īoth 10 and 13 represent ways to enter to a new line. What’s going on here? Five characters were supposed to print out per line, not two or three. At the end, we print out another blank line to move the cursor to a new line. ![]() The modulus operator, “%”, divides the value on its left by the value on its right and returns the remainder. The “&” is a logical AND, meaning both sides have to be true, for the condition to evaluate to true. To keep all the characters from printing on a single line, we print a new line if i > 0 and is evenly divisible by 5 (line 32). For each int, we print the int, then cast it to a char and print the char. To print out all the ASCII characters, we use a for-loop to step through all integers from 0 to 127 inclusive. * Prints out all 128 ASCII characters - 63 is authentically the question mark ![]() To explore some of the fun things we can do with ASCII characters, let’s make an ASCII viewer program to print them out. This means that when we cast an int to a char, we’re really just telling the computer “I know a char is 8 bits shorter than an int, but I only want the last (least significant) eight bits.” To a computer, both ints and chars are represented as one byte (8 bits) of 1’s and 0’s, with each 1 or 0 representing 1 bit. To explore the representation of ASCII a little more let’s look at it on the binary level. ![]() While limited compared to the unicode set of characters (ASCII can’t represent á, for example), ASCII is the workhorse of most file systems. Represented in a Java in a manner identical to the first 128 unsigned integers, they can be substituted for ints at any time, and ints 32 -126 inclusive can be cast to chars and printed. ASCII art like the greeting above is common, but ASCII characters are useful for a lot more.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |