• fullscreen
  • LETTERS.pde
  • sketch_nov18a_bachmann.pde
  • // A class to describe a single Letter
    class Letter {
      char letter;
      
      // The object knows its original " home " location
      float homex,homey;
      
      // As well as its current location
      float x,y;
      
      Letter(float x_, float y_, char letter_) {
        homex = x = x_;
        homey = y = y_;
        letter = letter_;
      }
      
      // Display the letter
      void display() {
        fill(255,10,10);
        textAlign(LEFT);
        text(letter,x,y);
      }
      
      // Move the letter randomly
      void shake() {
        x += random(-5,5);
        y += random(-5,5);
      }
      
      // At any point, the current location can be set back to the home location by calling the home() function.
      void home() { 
        x = homex;
        y = homey;
      }
    }
    
    PImage img;
    PFont f;
    String message = "'not all cultures are equal'";
    
    // An array of Letter objects
    Letter[] letters;
    
    void setup() {
      size(640,469);
      img= loadImage("republicants.jpg");
      imageMode(CORNERS);
      background(255);
      smooth();
      
      // Load the font
      f = createFont("AmericanTypewriter-CondensedBold", 40, true);
      textFont(f);
      
      // Create the array the same size as the String
      letters = new Letter[message.length()];
      
      // Initialize Letters at the correct x location
      int x = 40;
      for (int i = 0; i < message.length(); i ++ ) {
        // Letter objects are initialized with their location within the String as well as what character they should display.
        letters[i] = new Letter(x,100,message.charAt(i)); 
        x += textWidth(message.charAt(i));
      }
    }
    
    void draw() {
       image (img,0,0);
      for (int i = 0; i < letters.length; i ++ ) {
        
        // Display all letters
        letters[i].display();
        
        // If the mouse is pressed the letters shake
        // If not, they return to their original location
        if (mousePressed) {
          letters[i].shake();
        } else {
          letters[i].home();
        }
      }
    }
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    michael gambale

    michelle bachmann

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.
    You need to login/register to comment.