Giter Site home page Giter Site logo

mtrajk / virus-spreading Goto Github PK

View Code? Open in Web Editor NEW
81.0 5.0 15.0 2.69 MB

Simple virus spreading simulation tool made with plain/vanilla JavaScript

Home Page: https://mtrajk.github.io/virus-spreading/

License: MIT License

CSS 19.25% HTML 15.05% JavaScript 65.70%
simulation javascript vanilla-javascript canvas css covid-19 coronavirus virus-spreading

virus-spreading's Introduction

Virus Spreading

Simple virus spreading simulation inspired by this great article (written by Harry Stevens on WashingtonPost).
The goal of this tool is to experiment with several parameters to find the best way to "flatten the curve".
The whole simulation is made with plain/vanilla JavaScript and CSS. But why vanilla JavaScript (without some newer specification like ES6)? Because I wanted to be runnable in older/all browsers without using a JS compiler. Btw I'm not saying to ignore JS frameworks, JS compilers, or ES6 (they are great!), but for this project, I decided not to use something like that.

Note: This is not a mathematical simulation nor a 100% real-world simulation (because there are many more factors in the real world, and the people aren't just balls that are bouncing), but it could show how important the social distancing is and how quickly a virus could spread among the population.

Try it here

Description

Several details about the simulation:

  • The simulation and chart are responsive and mobile-friendly.
  • Each simulation lasts 30 seconds.
  • A healthy ball (green) could be infected by a sick ball with a collision (the infection depends on the "infection rate" parameter).
  • A sick ball (red) will be sick between 6 and 8 seconds. After that, it changes the state in recovered or dead (this depends on the "death rate" parameter). The number of sick balls depends on the "sick population" parameter.
  • A recovered ball (orange) can't be infected again.
  • A dead ball (black) is a ball that doesn't move and doesn't collide (doesn't exist for the other balls).
  • Healthy, vaccinated, sick and recovered balls could be social distancing balls, which means that the ball doesn't move but the moving balls can collide with it. The number of social distancing balls depends on the "social distancing" parameter.
  • In the chart there is a "safe limit" line (grey), that line is the hospital capacity, in this case, that limit is 30% of the total population (in the real-world this percent is much lower).
  • Two new parameters were added to the original simulation (around 11 months later): "vaccinated" population (blue balls) and "vaccine efficiency". Vaccinated balls are blue. Each vaccinated ball may develop virus immunity, this depends on the "vaccine efficiency" parameter.

Repo structure

  • images - logo (made by me, an amateur "designer") and a gif from the simulation
  • src - the source code of the application
    • index.html - a simple HTML page, JS and CSS files are imported and the parameters, notes, and canvases are defined here
    • css/styles.css - used to define media queries (for responsiveness), and other very simple CSS rules (for buttons, ranges, and texts)
    • js/common.js - all constants used in simulation
    • js/vector2d.js - 2 dimensional vector class, all vector related things are located here
    • js/ball.js - balls collision and movement logics/physics
    • js/chart.js - chart logics and drawings
    • js/simulation.js - simulation drawings and logics (without ball logics)
    • js/app.js - the role of this js is to control the whole app/workflow, used to initialize (using the values from the parameters), stop the simulation and all other interaction

Resources

Useful resources about virus spreading (you can find the same resources in the application):

License

This project is licensed under the MIT - see the LICENSE file for details

virus-spreading's People

Contributors

mtrajk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.