tornado.pde 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class Tornado {
  2. int xPos = 0;
  3. int yPos = 0;
  4. int lineWidth = 0;
  5. int tornadoWidth = 0;
  6. Tornado(int x, int y, int width, int tWidth) {
  7. this.xPos = x;
  8. this.yPos = y;
  9. this.lineWidth = width;
  10. this.tornadoWidth = tWidth;
  11. }
  12. void draw(int moveX) {
  13. stroke(255, 255, 255);
  14. int offset = (this.tornadoWidth - this.lineWidth) / 2;
  15. line(this.xPos + offset + moveX, this.yPos, this.lineWidth + offset + moveX, this.yPos);
  16. }
  17. }
  18. Tornado[] lines = new Tornado[40];
  19. int lastWidth = 200;
  20. int lastTop = 0;
  21. int tornadoWidth = 200;
  22. void setup() {
  23. size(300, 250);
  24. background(0,0,0);
  25. for(int i = 0; i < lines.length; i++) {
  26. lines[i] = new Tornado(40, lastTop + 40, lastWidth + 40, tornadoWidth);
  27. int randomWidthVariance = int(random(0,10));
  28. int newWidth = lastWidth - randomWidthVariance;
  29. lastWidth = newWidth;
  30. int randomVariance = int(random(2, 8));
  31. int newY = randomVariance + lastTop;
  32. lastTop = newY;
  33. }
  34. }
  35. int frameDelay = 10;
  36. void draw() {
  37. if(frameDelay ==0) {
  38. background(0,0,0);
  39. for(int i = 0; i < lines.length; i++) {
  40. int xPos = int(random(0, 40));
  41. lines[i].draw(xPos);
  42. }
  43. frameDelay = 10;
  44. } else {
  45. frameDelay--;
  46. }
  47. }