Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const p = {
- agentCount: 1000,
- agentSize: 3,
- agentAlpha: 1,
- minStepSize: 0.2,
- maxStepSize: 4,
- timeIntervalBetweenUpdates: 300
- }
- let agents
- let timeOfLastUpdate
- function setup() {
- createCanvas(540, 540)
- agents = []
- let a
- for (let i = p.agentCount - 1; i >= 0; i--) {
- a = new Agent()
- a.stepSize = random(p.minStepSize, p.maxStepSize)
- agents.push(a)
- }
- background(255)
- timeOfLastUpdate = millis()
- }
- function draw() {
- let currentTime = millis()
- // Mise à jour de la position
- if (currentTime - timeOfLastUpdate > p.timeIntervalBetweenUpdates) {
- timeOfLastUpdate = currentTime
- agents.forEach(a => {
- a.angle = random(0, TWO_PI)
- })
- agentAngle = random(0, TWO_PI)
- }
- agents.forEach(a => {
- a.updatePosition()
- })
- // Dessin
- background(255, 255, 255, 3)
- stroke(23, p.agentAlpha)
- strokeWeight(p.agentSize)
- noFill()
- agents.forEach(a => {
- line(a.previousPosition.x, a.previousPosition.y, a.position.x, a.position.y)
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement