Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. const p = {
  2. agentCount: 1000,
  3. agentSize: 3,
  4. agentAlpha: 1,
  5. minStepSize: 0.2,
  6. maxStepSize: 4,
  7. timeIntervalBetweenUpdates: 300
  8. }
  9.  
  10. let agents
  11. let timeOfLastUpdate
  12.  
  13. function setup() {
  14. createCanvas(540, 540)
  15. agents = []
  16. let a
  17. for (let i = p.agentCount - 1; i >= 0; i--) {
  18. a = new Agent()
  19. a.stepSize = random(p.minStepSize, p.maxStepSize)
  20. agents.push(a)
  21. }
  22. background(255)
  23. timeOfLastUpdate = millis()
  24. }
  25.  
  26. function draw() {
  27. let currentTime = millis()
  28. // Mise à jour de la position
  29. if (currentTime - timeOfLastUpdate > p.timeIntervalBetweenUpdates) {
  30. timeOfLastUpdate = currentTime
  31. agents.forEach(a => {
  32. a.angle = random(0, TWO_PI)
  33. })
  34. agentAngle = random(0, TWO_PI)
  35. }
  36.  
  37. agents.forEach(a => {
  38. a.updatePosition()
  39. })
  40.  
  41. // Dessin
  42. background(255, 255, 255, 3)
  43. stroke(23, p.agentAlpha)
  44. strokeWeight(p.agentSize)
  45. noFill()
  46. agents.forEach(a => {
  47. line(a.previousPosition.x, a.previousPosition.y, a.position.x, a.position.y)
  48. })
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement