Corona Transfer Simulation

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


Here's the [link](https://editor.p5js.org/God<em>of</em>Awesomeness/sketches/PQyxx3Qoc) to the website 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

No vote yet
1 vote

  Easy Math Editor

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.
  • Stay on topic — we're all here to learn more about math and science, not to hear about your favorite get-rich-quick scheme or current world events.

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold

- bulleted
- list

  • bulleted
  • list

1. numbered
2. 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 1

paragraph 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×3 2 \times 3
2^{34} 234 2^{34}
a_{i-1} ai1 a_{i-1}
\frac{2}{3} 23 \frac{2}{3}
\sqrt{2} 2 \sqrt{2}
\sum_{i=1}^3 i=13 \sum_{i=1}^3
\sin \theta sinθ \sin \theta
\boxed{123} 123 \boxed{123}

Comments

Sort by:

Top Newest

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

Log in to reply

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

Krishna Karthik - 5 months ago

Log in to reply

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 :)

Log in to reply

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

Jason Gomez - 5 months ago

Log in to reply

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

Log in to reply

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

Jason Gomez - 5 months ago

Log in to reply

@Jason Gomez lol i'll try :)

Log in to reply

@A Former Brilliant Member 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)

Jason Gomez - 5 months ago

Log in to reply

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

Log in to reply

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

Jason Gomez - 5 months ago

Log in to reply

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

Jason Gomez - 5 months ago

Log in to reply

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

Jason Gomez - 4 months, 4 weeks ago

Log in to reply

@Jason Gomez 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

Jason Gomez - 4 months, 3 weeks ago

Log in to reply

@Jason Gomez 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

Jason Gomez - 4 months, 3 weeks ago

Log in to reply

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

A Former Brilliant Member - 4 months, 3 weeks ago

Log in to reply

@Jason Gomez 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

Jason Gomez - 4 months, 3 weeks ago

Log in to reply

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

Jason Gomez - 4 months, 3 weeks ago

Log in to reply

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

A Former Brilliant Member - 4 months, 3 weeks ago

Log in to reply

@Jason Gomez Added these lines

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]);
      }

Jason Gomez - 4 months, 3 weeks ago

Log in to reply

@Jason Gomez Ok, I'll try it out.

A Former Brilliant Member - 4 months, 3 weeks ago

Log in to reply

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.

Elijah Frank - 5 months ago

Log in to reply

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

A Former Brilliant Member - 4 months, 3 weeks ago

Log in to reply

You can find it on my about easily

Jason Gomez - 4 months, 3 weeks ago

Log in to reply

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?

A Former Brilliant Member - 4 months, 3 weeks ago

Log in to reply

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

Jason Gomez - 4 months, 3 weeks ago

Log in to reply

@Jason Gomez ok

A Former Brilliant Member - 4 months, 3 weeks ago

Log in to reply

@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?

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

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

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

Would you like to be a judge?

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

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

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

@Jason Gomez 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.

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

@A Former Brilliant Member 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

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

@A Former Brilliant Member You can use the old inky pinky pinky way for a random choice, or python or JavaScript or a coin flip

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

@Jason Gomez No u choose, it is completely your choice.

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

@A Former Brilliant Member Hmm okay I’ll be participant, don’t judge me against this

(guess which method I used)

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

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

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

@A Former Brilliant Member Used inky pinky pinky to choose which then used python

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

@Jason Gomez lmao

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

@Jason Gomez 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...

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

@A Former Brilliant Member Might be the same case with me

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

@Jason Gomez :(

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

@A Former Brilliant Member 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...

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

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

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

@A Former Brilliant Member 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)

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

@Jason Gomez 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.

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

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

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

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

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

We were just editing the comments we had already put and got many messages thru in just four comments

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

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

Jason Gomez - 4 months, 2 weeks ago

Log in to reply

@Jason Gomez lol

A Former Brilliant Member - 4 months, 2 weeks ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...