# Corona Transfer Simulation

Warning : Contains stuff on COVID-19, not recommended if Corona is a sensitive topic to you

Here's the link to the website

I made a Corona Transfer Simulation using JavaScript, p5 specifically. It starts with a bunch of circles bouncing around with random velocity in a box, and one of them is red and infected with corona-virus. If the red circle collides with a healthy one, the healthy one gets infected. In a very short period of time, all the balls get infected.

This is actually just part of a game I'm working on, but my friend Krishna Karthik wanted to see the Simulation part so I am making this post.

Hopefully, this shows you why Social Distancing is important and must be followed. Anyways, stay safe, bye!

Note by A Former Brilliant Member
5 months ago

This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.

When posting on Brilliant:

• Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .
• Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.
• Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold
- bulleted- list
• bulleted
• list
1. numbered2. list
1. numbered
2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in $$ ... $$ or $ ... $ to ensure proper formatting.
2 \times 3 $2 \times 3$
2^{34} $2^{34}$
a_{i-1} $a_{i-1}$
\frac{2}{3} $\frac{2}{3}$
\sqrt{2} $\sqrt{2}$
\sum_{i=1}^3 $\sum_{i=1}^3$
\sin \theta $\sin \theta$
\boxed{123} $\boxed{123}$

Sort by:

@Krishna Karthik I can't write simulation notes as good as yours lol

@Percy Jackson Woah... that looks so good! How did you write the collision bit? Is it based on momentum transfer? That's really cool :)

- 5 months ago

Thanks!!!

So for the collision function -

• Step 1 - Check distance between center's of two balls.

• Step 2 - Define a minimum distance before which they collide and change velocity

• Step 3 - Check if distance is less than or equal to minimum distance

• Step 4 - If distance is greater than min. distance, leave it be, otherwise do Step 5

• Step 5 - I'm not really sure how to define this, I just put together a function with code that I learnt from different places. It is kinda based on momentum transfer, but its not exactly accurate. It calculates the acceleration/retardation and direction of the ball after collision then changes the values accordingly.

• Step 6 - Iterate over every pair of balls. This above function works for only 2 balls. I used a for loop to iterate it over every single ball that I make.

That's all. You can look at the code in the link I gave below the image. It'll help clear out my vague step 5 lol :)

And now I need to see the simulation where social distance comes into the picture too

- 5 months ago

No!!! More simulation = more JS = more work!!! lol I'm not sure I can do that...

Hmm.. sad :( ): (whichever type you are)

- 5 months ago

lol i'll try :)

I tried to make the balls to play tag, but for some reason they play for sometime and then get bored ( I think they only play tag with higher balls and not the lower balls)

- 5 months ago

lol i am not doing anything to them for now, I need to work on the other features of my game :)

Once I am successfully in making them play tag I will put it here

- 5 months ago

Realised what was wrong, the balls were cheating and tagging the one which tagged them

- 5 months ago

Kinda improved it now, now you can see them cheating, previously you couldn’t so it’s a gain

- 4 months, 4 weeks ago

I realised that all collisions happen several times (6-7) times and only the first collision sends the balls in different directions, so somehow I have to do something so that the balls change colors in the first collision and none of the others

- 4 months, 3 weeks ago

So somehow I have to figure out how to predict whether the balls are moving closer or moving apart, which I have the idea only in my head and it can’t come out easily so I give up on tag

- 4 months, 3 weeks ago

Can you send me a link of what you're doing?

- 4 months, 3 weeks ago

I hadn’t saved what I did last don’t exactly remember it either, so had to do again, did something different this time so can’t see them tagging each other at collision very well now

- 4 months, 3 weeks ago

Ok wait how do I send you the one I did without making an account

- 4 months, 3 weeks ago

You can't. Send me the code you changed and were you changed it, so that i can see it.

- 4 months, 3 weeks ago

 1 2 3 colBall(a) { for (let i = 0; i < 15; i++) { if (i !== a) { 

  1 2 3 4 5 6 7 8 9 10 11 this.ix -= ax; this.iy -= ay; balls[i].ix += ax; balls[i].iy += ay; if (this.corona === "positive") { this.corona = "negative"; balls[i].corona = "positive" } if (balls[i].corona === "positive") { this.corona = "positive"; balls[i].corona = "negative" 

 1 2 3 4 5 for (let a = 0; a < 15; a++){ balls[a].draw(); balls[a].move(); balls[a].colWall(); balls[a].colBall(a); 

# Just the “a” in colBall was added

Deleted infect(not required) and also deleted this

 1 2 3 4 5 for (let i = 0; i < 15; i++) { if(balls[i].corona === "positive"){ for (let z = 0; z < 15; z++) { balls[i].infect(balls[z]); } 

- 4 months, 3 weeks ago

Ok, I'll try it out.

- 4 months, 3 weeks ago

You know that in Washington post are a paper with the same variables and enviroemnt simulator. The thing now is to made a enviroment behavior of COVID and with in my case do a matplotlib graphs represents different para meterse of the simulation of the curve of (death, neutral, contagious) and compare the curve of real one and the simulator. Anyway good job of thar program in JavaScript I made my simulator in Python using now streamlit and before pygame.

- 5 months ago

@Jason Gomez - Can you mention me in that Primes to a Million thing again if it is important? I dismissed all my notifications.

- 4 months, 3 weeks ago

You can find it on my about easily

- 4 months, 3 weeks ago

Found it and saw your comment. Took me about 15-20 seconds to completely load. Why the heck have you posted a million prime numbers?

- 4 months, 3 weeks ago

It wasn’t there on Brilliant so I put it, was useful to Jeff, so it’s a win for me

- 4 months, 3 weeks ago

ok

- 4 months, 3 weeks ago

@Jason Gomez - I have a problem. I'm kinda conflicted about the Mathathon thing. I wanna do it, but at the same time, I'm not sure I do. I want it to continue, but I just don't have enough time and don't wanna let everyone who joined down. Thoughts?

- 4 months, 2 weeks ago

If you really have no time then don't do it, other than Jeff and Nscs all the other guys are new to Mathathon, so I don't expect that your decision will let them down, so the only guys you will be letting down is Jeff, Nscs and me

- 4 months, 2 weeks ago

Would you like to be a judge?

- 4 months, 2 weeks ago

Dam, I would be honoured to be (I hope you weren’t joking)

- 4 months, 2 weeks ago

lmao I actually was joking, but I'll give you two options, either be a judge with me or be a participant. You can't be both a participant and judge, k? You choose. Also, I got over my dilemma, I chose to complete the Mathathon by reorganizing time and stuff.

- 4 months, 2 weeks ago

Ofc how can someone be the judge he is participating in(unless it’s some special event), you can choose what you want me to be

- 4 months, 2 weeks ago

You can use the old inky pinky pinky way for a random choice, or python or JavaScript or a coin flip

- 4 months, 2 weeks ago

No u choose, it is completely your choice.

- 4 months, 2 weeks ago

Hmm okay I’ll be participant, don’t judge me against this

(guess which method I used)

- 4 months, 2 weeks ago

lol did you inky pinky ponky that? Well, it's your choice. You're a participant, your names on the members list :)

- 4 months, 2 weeks ago

Used inky pinky pinky to choose which then used python

- 4 months, 2 weeks ago

lmao

- 4 months, 2 weeks ago

I'm deactivating my account after the mathathon ends. I'm too busy from April on. I may reactivate it later on in my life, so I am not permanently deleting, but yeah...

- 4 months, 2 weeks ago

Might be the same case with me

- 4 months, 2 weeks ago

:(

- 4 months, 2 weeks ago

I was just wondering if I became judge would you accept more participants, if more than 30 are ready to join then maybe you can keep me as a judge...

- 4 months, 2 weeks ago

Gods no...25 is enough. The offer is still open till the first problem is posted, if you want to change your mind.

- 4 months, 2 weeks ago

Hmm if I go, one more spot will be open, I think that’s better, I’ll be happy to judge (not gonna change decision and don’t allow me to change decision) (hopefully Jeff hasn’t seen this convo)

- 4 months, 2 weeks ago

Ok, judge then. Yeah, Jeff shouldn't find this. He'd be annoyed. To be honest I don't wanna add him just because I know he's too childish.

- 4 months, 2 weeks ago

Have you and Siddharth been messing around in the Mathathon note? I got about 20 notifs from you guys, and I saw that thread about Siddharth spamming which confused me...@Jason Gomez

- 4 months, 2 weeks ago

Nah none of the comments were deleted, I many of my comments were deleted because I was “organising your note”

- 4 months, 2 weeks ago

- 4 months, 2 weeks ago

That’s the one where I talked about you being confused

- 4 months, 2 weeks ago

lol

- 4 months, 2 weeks ago

×