raverlights.pde 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. Twinkle[] twinkle = new Twinkle[10];
  2. void setup()
  3. {
  4. size(640, 360);
  5. background(0);
  6. fill(0,0,0,0);
  7. frameRate(30);
  8. for(int i = 0; i < 10; i++) {
  9. twinkle[i] = new Twinkle();
  10. }
  11. }
  12. void draw()
  13. {
  14. for(int i = 0; i < 10; i++) {
  15. twinkle[i].update();
  16. }
  17. background(0);
  18. for(int i = 0; i < 10; i++) {
  19. twinkle[i].draw();
  20. }
  21. }
  22. class Twinkle {
  23. private float[] lastX = new float[4];
  24. private float[] lastY = new float[4];
  25. int[] colorVal = new int[3];
  26. public Twinkle() {
  27. lastX[0] = 320;
  28. lastY[0] = 180;
  29. lastX[1] = 320;
  30. lastY[1] = 180;
  31. lastX[2] = 320;
  32. lastY[2] = 180;
  33. lastX[3] = 320;
  34. lastY[3] = 180;
  35. colorVal[0] = (int)random(0, 255);
  36. colorVal[1] = (int)random(0, 255);
  37. colorVal[2] = (int)random(0, 255);
  38. }
  39. public void update() {
  40. float newX = lastX[3];
  41. float newY = lastY[3];
  42. float differenceX = random(-width / 4, width / 4);
  43. float differenceY = random(-height / 4, height / 4);
  44. if(abs(differenceX) < 1) {
  45. differenceX = 0;
  46. }
  47. if(abs(differenceY) < 1) {
  48. differenceY = 0;
  49. }
  50. newX += differenceX;
  51. newY += differenceY;
  52. newX = constrain(newX, 0, width);
  53. newY = constrain(newY, 0, height);
  54. lastX[0] = lastX[1];
  55. lastY[0] = lastY[1];
  56. lastX[1] = lastX[2];
  57. lastY[1] = lastY[2];
  58. lastX[2] = lastX[3];
  59. lastY[2] = lastY[3];
  60. lastX[3] = newX;
  61. lastY[3] = newY;
  62. }
  63. public void draw() {
  64. stroke(colorVal[0], colorVal[1], colorVal[2]);
  65. curve(lastX[0], lastY[0], lastX[1], lastY[1], lastX[2], lastY[2], lastX[3], lastY[3]);
  66. }
  67. }