Due: Wednesday 11/20 10:00am
Submission name: work26_chargrid
You will write a program that works with a 2d array of char
values. Remember that char
values can be set to characters like '!'
or integers like 33
. I will provide setup
and draw
functions below. You will write the following functions:
void orderedChars(char[][] cd)
- Populates
cd
with characters starting at!
(which has an ASCII value of 33), and going up by 1 until the end of the array has been reached.
void drawGrid(char[][] cd)
- Draw
cd
to the screen. - Set the
textSize
so that the width of the screen evenly splits up a row of characters incd
. - Use, LEFT, TOP as the text alignment values.
- Sample image for an array populated by
orderedChars
:
void randomLetters(char[][] cd)
- Populate
cd
with random upper case letters only.
Use the following driver code:
int NUM_ROWS = 6;
int NUM_COLS = 15;
char[][] grid;
void setup() {
size(600, 300);
grid = new char[NUM_ROWS][NUM_COLS];
orderedChars(grid);
drawGrid(grid);
}//setup
void draw() {
background(0);
drawGrid(grid);
}//draw
void keyPressed() {
if (key == 'o') {
orderedChars(grid);
}
if (key == 'r') {
randomLetters(grid);
}
}//keyPressed