DEV Community

Discussion on: Simple Disease Outbreak Modeling - Inspired by a 3b1b video

Collapse
 
crimsonmed profile image
Médéric Burlet • Edited

Interesting tutorial But I would have loved for you to modernize it using current best practices.

for instance:

for(let i = 0; i<infected;i++){
    dots.push([Math.random()*Math.min(cv.width,cv.height)*3/4,Math.random()*Math.min(cv.width,cv.height)*3/4,1,speed*Math.random(),speed*Math.random()]
}

Enter fullscreen mode Exit fullscreen mode

I would have also decomposed the above formula with step by step.

Another example is your refresh function declaration:

const refresh = () => {

}
Enter fullscreen mode Exit fullscreen mode

You might also want to look into p5 which has amazing drawing capabilities for this kind of work.

p5js.org/examples/simulate-flockin...

Collapse
 
quantalabs profile image
QLabs • Edited

Thanks for your feedback! Although p5 might have better drawing techniques and styles, I felt like the whole process of learning a new library and using it in the simulation defeats my purpose of keeping the simulation simple. I don't usually use const but it is something you could use as a substitute. These suggestions though should help the reader, and I encourage you to use what you thought was better or current. Once again, thanks for your feedback.

Collapse
 
crimsonmed profile image
Médéric Burlet

Const and let is not just to substitute. Its for scope, security and more