Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Char 2 - Final for Intro to Comp Media

By: caitlinorbanek on Dec 15th, 2011  |  syntax: None  |  size: 0.92 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. char key_pressed;
  2.  
  3. PFont f;
  4.  
  5.  
  6. String yourtext = "";
  7.  
  8.  
  9. String saved = "";
  10.  
  11. void setup() {
  12.   size(800, 800);
  13.   f = loadFont("GentiumBasic-16.vlw");
  14.  
  15.  
  16.  
  17. }
  18.  
  19. void draw() {
  20.   background(255, 0, 0);
  21.   int indent = 400;
  22.  
  23.   // Set the font and fill for text
  24.   textFont(f);
  25.   fill(0);
  26.  
  27.   // Display everything
  28.   text("Type in this window to see a secret messaging code. \nTry not to feel too James Bond- it's just a computer. ", indent, 40);
  29.   text(yourtext,indent-300,150);
  30.   text(yourtext,indent-300,200);
  31.  
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38. void keyPressed() {
  39.  
  40.   if ((key >= 65 && key < 90) | (key >= 97 && key < 122)){
  41.                 key_pressed = (char)(key + 1);
  42.         }
  43.         else if (key == 91 | key == 122) {
  44.                 key_pressed = (char)65;
  45.         }
  46.  
  47.   // If the return key is pressed, save the String and clear it
  48.  if (key == '\n' ) {
  49.    saved = yourtext;
  50.     yourtext = "";
  51.   } else {
  52.     yourtext = yourtext + key_pressed;
  53.   }
  54. }