Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. int circleSize = 20;
  2. int numberOfPositions = 100;
  3. int []mousePosX = new int[numberOfPositions];
  4. int []mousePosY = new int [numberOfPositions];
  5. void setup()//
  6. {
  7. size(842, 480);
  8. }
  9.  
  10. void draw()//
  11. {
  12. clear();
  13. background(0);
  14. addMousePosition();
  15. for (int i = 0; i < mousePosX.length; i++) {
  16. // alpha will define the transparancy (alpha).
  17. // The number of steps between 255 and 0 will be inline with number of elements in the array.
  18. float alpha = map(i, 0, mousePosX.length, 255, 0);
  19. fill(255, alpha);
  20. ellipse(mousePosX[i], mousePosY[i], circleSize, circleSize);
  21. }
  22. }
  23.  
  24. void addMousePosition() {
  25. noStroke();
  26. fill(255);
  27. // Shift the array backwards, so the current mouse position can be added to
  28. // the array on index position 0
  29. for (int i = mousePosX.length-1; i > 0; i--) {
  30. mousePosX[i] = mousePosX[i-1];
  31. mousePosY[i] = mousePosY[i-1];
  32. }
  33. mousePosX[0] = mouseX;
  34. mousePosY[0] = mouseY;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement