nicatronTg

Untitled

Apr 18th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. // Initialize the loading bar with intensities
  2. int[] loadingBar = {0,0,0,0,0,0,50,100,150,200,250,200,150,100,50};
  3. int boxWidth;
  4. // Save the number of boxes by getting the length of the array
  5. int numBoxes = loadingBar.length;
  6.  
  7. void setup() {
  8. size(650, 75);
  9. // move the bar slowly so you can see it move
  10. frameRate(5);
  11. // a box is as wide as the screen divided by the number of boxes
  12. boxWidth = width/numBoxes;
  13. }
  14.  
  15. // draw the loading bar
  16. void drawBar() {
  17. // cycle over each element of the array
  18. for (int i = 0; i < numBoxes; i += 1) {
  19. // set the stroke and fill to the intensity of the array value
  20. fill(loadingBar[i]);
  21. stroke(loadingBar[i]);
  22. // draw each box, starting at the top left corner
  23. rect(boxWidth * i, 0, boxWidth, height);
  24. }
  25. }
  26.  
  27. // change the intensity of each array value
  28. void changeState() {
  29.  
  30. // FIXME -- this should go right to left, and wrap around
  31. for (int i = 0; i < numBoxes - 1; i++) {
  32. // put the intensity of the box to the right into the current box
  33. loadingBar[i] = loadingBar[i+1];
  34. }
  35.  
  36. }
  37.  
  38. void draw() {
  39. drawBar();
  40. changeState();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment