int left_boundary= -600; int right_boundary = 600; int xpos = 0; // horizontal (x) position left square int ypos = 0; // vertical (y) position left int xpos2 = 600; int ypos2 = 18; int w = 8; //square width int h = 2; // square height int speed = 3; //speed of square movement per pixel boolean moveit_right = true; boolean moveit_left = true; Name [] letters; // Code that runs forever goes here -set up the applet void setup() { size(600,20); // applet size framerate(80); // speed of animation letters = new Name [7]; // Name (char lt, color co, int lz, int hp, int vp) letters [0] = new Name ('V', 50, 20, 5, 15); letters [1] = new Name ('i', 60, 20, 15, 15); letters [2] = new Name ('v', 70, 20, 20, 15); letters [3]= new Name ('i', 80, 20, 29, 15); letters [4]= new Name ('a', 90, 20, 34, 15); letters [5]= new Name ('n', 100, 20, 43, 15); letters [6]= new Name ('a', 110, 20, 53, 15); } void draw(){ background(155,200,0); // bg color PFont font; // The font must be located in the sketch's // "data" directory to load successfully font = loadFont("AmericanTypewriter-Condensed-48.vlw"); textFont(font, 40); smooth (); textSize(20); for(int i=0; i<7; i++) { letters [i].write_letters ();// specify which cell in the array -placement in array letters [i].move_name(); } // drawing the squares noStroke(); fill(#ffff00); //square on the left rect(xpos, ypos, w, h); smooth (); noFill(); noStroke(); fill(#ffff00); //square on the right rect(xpos2, ypos2, w, h); smooth (); noFill(); //------------ xpos = xpos + speed; //left square moving right if (moveit_right == true) { xpos = xpos + 5; } else { // else going left subtract 5 xpos = xpos/2 - 5; } // if on right edge start going left if (xpos > width) { moveit_right = false; } // if on left edge start going right else if (xpos < 0) { moveit_right = true; } //-------------- xpos2 = xpos2 - speed; // right square moving left if (moveit_left == true) { xpos2 = xpos2 + 5; } else { // else going left subtract 5 xpos2 = xpos2/2 - 5; } // if on right edge start going left if (xpos2 > width) { moveit_left = false; } // if on left edge start going right else if (xpos2 < 0) { moveit_left = true; } } //------------ //Declare variables (put outside of void setup and draw) class Name{ char let_ter; color letter_color; int letter_size; int left_boundary= -600; int right_boundary = 600; int xpos; // horizontal (x) position left square int ypos; // vertical (y) position left int xpos2 = 600; int ypos2 = 18; int w = 8; //square width int h = 2; // square height int speed = 3; //speed of square movement per pixel boolean moveit_right = true; boolean moveit_left = true; Name (char lt, color co, int lz, int hp, int vp){ let_ter = lt; letter_color = co; letter_size = lz; xpos = hp; ypos = vp; } void write_letters (){ fill (letter_color); text (let_ter, xpos, ypos); } // move letters -- set the horizontal position void move_name() { xpos += speed; if (xpos > right_boundary) { xpos = right_boundary; speed *= -1; } else if (xpos < left_boundary) { xpos = left_boundary; speed *= -1; } } }