Advertisement
caitlinorbanek

Char 2 - Final for Intro to Comp Media

Dec 15th, 2011
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement