CSc 101: Section 11 – Strings!

In this section, you are going to work using and displaying strings to the canvas and various string methods.


Problem 1

Write a sketch named section_13_2. This time, display the same lyrics, but you may use the text() function only one time. How can this be done?


Problem 2

Write a sketch named section_13_3. Next, repeat the lyrics four (or more) times on the canvas, as is pictured. Don't just copy/paste text() calls four times. Instead, store the String into a variable, and use the variable when displaying the text. Using the variable will help you reduce the size and reprtition in your program.


Problem 3

Write a sketch named section_13_4. As you can see, this sketch simulates the scrolling-space-text seen at the beginning of most Star-Wars films (Trivia: which movie does this scrolling-space-text text not appear in?). You can use the same text as I did, or find other text from Star-Wars online. You should put the text into a String variable, and you may only use one String variable and one use of the text() function. To do this, but newlines (\n) directly into the string with the text. Also, don't forget to incldue some stars in the background!


Problem 4

Write a sketch named section_13_5. This sketch will display some strings to the canvas that keep track of the mouse clicks, key clicks, and frames of your program. Each time the mouse is clicked, the clicked count will increase by one. Each time any key on the keyboard is pressed, the keyboard count will increase by one. Each time a new fram is displayed (in other words, each time draw is run) the frame count will increase. You should keep track of these three values with integer variables in your program. To display the words to the screen, you will need to concatenate strings and numbers together with the + sign. Also, you will probably want to make your frameRate() slow, so that the last line doe not change insanely fast.


The last few problems require the use of the substring() function in processing. We just barely got to talk about this function in class before your section. If you don’t feel confident in using it, do one or more of the following before tackling these problems:


Problem 5

Write a sketch named section_13_6. This sketch will display one simple string, the word "COOL". However, the only string variable that you are allowed to "hard-code" in your program is the following:
String alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
You must create a new String variable with the contents "COOL" in it by acess substrings of the alph string. Recall that to do this, use the substring() function, which is built-into all String variables. For example, to access the letter "D" in the alph variable, you would do the following:
String letterD = alph.substring(3, 4);
This will but the string that begins at index 3 and ends before index 4 into the letterD variable. This ends up just being the letter "D". Create a new string variable the has "COOL" in it using this technique, and then display it on the canvas.


Problem 6

Write a sketch named section_13_6. In this program, you will build off of what you did in problem 6. Using the same alph variable, extract three words: "COOL", "STORY" and "BRO". Once you have extracted them, display them on the canvas in three different colors, as shown


Problem 7

Write a sketch named section_11_7. You can use the below code as a starting point:
void setup() {
  size(700, 200);
  textSize(50);
}

String str = "ABCDEFGHIJKLMN[x]OPQRSTUVWXYZ";

void draw() {
  background(100);
  // put your code here!
}
You code should split the string str into two chunks, based on where the [x] is. After splitting, show the string that is before it and after it on the canvas. You should not just hard-code the indexes to work with only "ABCDEFGHIJKLMN[x]OPQRSTUVWXYZ". It should worf for other strings with [x] in it as well.


Submit at least 3 solutions to the D2L dropbox