Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.hamoid.*;
- VideoExport videoExport;
- ArrayList<Person> people;
- Boundary world;
- Boundary hospital;
- int population = 2000;
- PopStats pStats;
- int daysInfectedWithoutSymptoms = 3;
- int daysInfectedWithSymptoms = 7;
- int daysRecoveringButInfectious = 4;
- int simTicksPerDay = 60;
- int walkSpeed = 1;
- float mortalityRate = 0.01;
- boolean qStayIn = false;
- boolean qWithoutSymptoms = false;
- boolean qWithSymptoms = true;
- boolean qInRecovery = false;
- boolean govReccomend = false;
- boolean govRecFinished = false;
- boolean govMandate = false;
- boolean govManFinished = false;
- int recDayTicks = 28 * 60;
- int manDayTicks = 14 * 60;
- int recTicks = 0;
- int manTicks = 0;
- ArrayList<PopStats> graph = new ArrayList<PopStats>();
- int FinishedTick = 0;
- void setup() {
- //fullScreen();
- size(1400, 1600);
- videoExport = new VideoExport(this);
- videoExport.startMovie();
- world = new Boundary(0, 280, 1400, 1120);
- people = new ArrayList<Person>();
- for (int i = 0; i < population; i++) {
- people.add(new Person(world));
- }
- people.get(0).setInfState(1);
- pStats = new PopStats();
- for (int i = 0; i < 1400; i++) {
- graph.add(new PopStats());
- }
- }
- void draw() {
- background(51);
- world.show();
- for (Person p : people) {
- p.update();
- p.bounds();
- }
- for (Person p : people) {
- p.collide();
- p.show();
- }
- pStats.update();
- graph.add(new PopStats());
- if (pStats.healthy + pStats.recd + pStats.dead == population) {
- FinishedTick++;
- if (FinishedTick >= 300) {
- videoExport.endMovie();
- exit();
- }
- }
- graph.get(graph.size()-1).healthy = pStats.healthy;
- graph.get(graph.size()-1).infWOSym = pStats.infWOSym;
- graph.get(graph.size()-1).infWSym = pStats.infWSym;
- graph.get(graph.size()-1).recWOSym = pStats.recWOSym;
- graph.get(graph.size()-1).recd = pStats.recd;
- graph.get(graph.size()-1).dead = pStats.dead;
- if (graph.size() > width) {
- graph.remove(0);
- }
- println(graph.get(0).healthy/(population*1.0)*200 + ", " + graph.get(graph.size()-1).healthy/(population*1.0)*200 + ", " + graph.get((graph.size()-1)/2).healthy/(population*1.0)*200);
- for (int i = 0; i < graph.size()-1; i++) {
- strokeWeight(1);
- float s1 = (graph.get(i).healthy * 1.0) / (population*1.0) * 200.0;
- float s2 = (graph.get(i).infWOSym * 1.0) / (population*1.0) * 200.0;
- float s3 = (graph.get(i).infWSym * 1.0) / (population*1.0) * 200.0;
- float s4 = (graph.get(i).recWOSym * 1.0) / (population*1.0) * 200.0;
- float s5 = (graph.get(i).recd * 1.0) / (population*1.0) * 200.0;
- float s6 = (graph.get(i).dead * 1.0) / (population*1.0) * 200.0;
- stroke(127, 127, 127);
- line(i, 1400, i, 1400 + s1);
- stroke(255, 255, 0);
- line(i, 1400 + s1, i, 1400 + s1 + s2);
- stroke(255, 0, 0);
- line(i, 1400 + s1 + s2, i, 1400 + s1 + s2 + s3);
- stroke(255, 0, 255);
- line(i, 1400 + s1 + s2 + s3, i, 1400 + s1 + s2 + s3 + s4);
- stroke(0, 0, 255);
- line(i, 1400 + s1 + s2 + s3 + s4, i, 1400 + s1 + s2 + s3 + s4 + s5);
- stroke(0, 0, 0);
- line(i, 1400 + s1 + s2 + s3 + s4 + s5, i, 1400 + s1 + s2 + s3 + s4 + s5 + s6);
- }
- if (govReccomend == true && govRecFinished == false && recTicks < recDayTicks) {
- recTicks++;
- if (recTicks >= recDayTicks) {
- govReccomend = false;
- govRecFinished = true;
- }
- }
- if ((pStats.infWSym / 1.0) / (population / 1.0) > 0.02) {
- if (!govRecFinished) {
- govReccomend = true;
- }
- }
- if (govRecFinished) {
- if (govMandate == true && govManFinished == false && manTicks < manDayTicks) {
- manTicks++;
- if (manTicks >= manDayTicks) {
- govMandate = false;
- govManFinished = true;
- }
- }
- if ((pStats.infWSym / 1.0) / (population / 1.0) > 0.25) {
- if (!govManFinished) {
- govMandate = true;
- }
- }
- }
- fill(255);
- textSize(20);
- text("Healthy: " + pStats.healthy, 10, 20);
- text("Infected: " + (pStats.infWOSym + pStats.infWSym + pStats.recWOSym), 10, 45);
- text("Showing Symptoms: " + pStats.infWSym + " (" + (round(pStats.infWSym / (population/1.0)*1000.0)/10.0) + "% of pop.)", 10, 70);
- text("People showing symptoms stay home sick.", 450, 70);
- text("Recovered: " + (pStats.recd), 10, 95);
- text("Dead: " + (pStats.dead), 10, 120);
- if (govReccomend == true && govRecFinished == false) {
- fill(255, 255, 0);
- text("Stay-In reccomended by government. 60% of the population is adhering to the Stay-In.", 10, 160);
- text(round((recDayTicks-recTicks)/(recDayTicks*1.0)*28.0) + " days of Stay-In remaining.", 10, 185);
- }
- if (govMandate == true && govManFinished == false) {
- fill(255, 0, 0);
- text("Government Mandate issued. All of the population is adhering.", 10, 160);
- text(round((manDayTicks-manTicks)/(manDayTicks*1.0)*14.0) + " days of mandate remaining.", 10, 185);
- }
- videoExport.saveFrame();
- }
- class Person {
- int infState;
- /*
- 0 = Healthy
- 1 = Infected Without Symptoms
- 2 = Infected
- 3 = Recovering But Infectious
- 4 = Recovered
- 5 = Dead
- */
- int isoState;
- /*
- 0 = In Public
- 1 = At Home
- 3 = Hospitalized
- 4 = Dead
- */
- int[] infTick = new int[6];
- int job; //0 = public, 1 = hospital
- PVector pos;
- PVector vel;
- Boundary bounds;
- color infCol;
- boolean socDist = false;
- boolean followRec;
- Person(Boundary b) {
- infState = 0;
- isoState = 0;
- bounds = b;
- pos = new PVector(random(bounds.right) + bounds.left, random(bounds.bottom) + bounds.top);
- vel = new PVector(walkSpeed, 0).rotate(random(TWO_PI));
- infCol = color(127, 127, 127);
- followRec = random(1)>0.4;
- }
- void update() {
- infTick[infState] += 1;
- if (infState == 1 && infTick[1] >= daysInfectedWithoutSymptoms * simTicksPerDay) {
- setInfState(2);
- }
- if (infState == 2 && infTick[2] >= daysInfectedWithSymptoms * simTicksPerDay) {
- setInfState(3);
- }
- if (infState == 3 && infTick[3] >= daysRecoveringButInfectious * simTicksPerDay) {
- setInfState(4);
- }
- if (infState == 1 || infState == 2 || infState == 3) {
- float mortalityCheck = random(1);
- if (mortalityCheck <= 1.0 / ((daysInfectedWithoutSymptoms+daysInfectedWithSymptoms+daysRecoveringButInfectious) * simTicksPerDay / mortalityRate)) {
- setInfState(5);
- }
- }
- if (!(socDist || govMandate || (followRec && govReccomend))) {
- pos.x += vel.x;
- pos.y += vel.y;
- }
- }
- void setInfState(int i) {
- if (i == 1) {
- infState = 1;
- infCol = color(255, 255, 0);
- socDist = qWithoutSymptoms || qStayIn;
- }
- if (i == 2) {
- infState = 2;
- infCol = color(255, 0, 0);
- socDist = qWithSymptoms || qStayIn;
- }
- if (i == 3) {
- infState = 3;
- infCol = color(250, 0, 250);
- socDist = qInRecovery || qStayIn;
- }
- if (i == 4) {
- infState = 4;
- infCol = color(0, 0, 255);
- socDist = qStayIn;
- }
- if (i == 5) {
- infState = 5;
- infCol = color(0, 0, 0);
- socDist = true;
- }
- }
- void bounds() {
- if (pos.x > bounds.left + bounds.right) {
- pos.x = 2 * bounds.left + 2 * bounds.right - pos.x;
- vel.x *= -1;
- }
- if (pos.y > bounds.top + bounds.bottom) {
- pos.y = 2 * bounds.top + 2 * bounds.bottom - pos.y;
- vel.y *= -1;
- }
- if (pos.x < bounds.left) {
- pos.x = 2 * bounds.left - pos.x;
- vel.x *= -1;
- }
- if (pos.y < bounds.top) {
- pos.y = 2 * bounds.top - pos.y;
- vel.y *= -1;
- }
- }
- void collide() {
- boolean hit = false;
- PVector newVel = new PVector(0, 0);
- for (Person p : people) {
- if (p != this && !(p.socDist || govMandate || (p.followRec && govReccomend))) {
- if (!(socDist || govMandate || (followRec && govReccomend))) {
- if (pos.dist(p.pos) < 10) {
- fill(255, 0, 0);
- hit = true;
- PVector tempVel = new PVector(pos.x - p.pos.x, pos.y - p.pos.y).normalize();
- newVel.x += tempVel.x;
- newVel.y += tempVel.y;
- if (p.infState == 1 || p.infState == 2 || p.infState == 3) {
- if (infState == 0) {
- setInfState(1);
- }
- }
- }
- }
- }
- }
- if (hit) {
- newVel.normalize().setMag(walkSpeed);
- vel.x = newVel.x;
- vel.y = newVel.y;
- }
- }
- void show() {
- noStroke();
- fill(infCol);
- circle(pos.x, pos.y, 10);
- }
- }
- class Boundary {
- float top;
- float bottom;
- float left;
- float right;
- Boundary(float a, float b, float c, float d) {
- left = a;
- top = b;
- right = c;
- bottom = d;
- }
- void show() {
- stroke(255);
- strokeWeight(5);
- noFill();
- rect(left, top, right, bottom);
- }
- }
- void keyPressed() {
- if (key == 'q') {
- videoExport.endMovie();
- exit();
- }
- }
- class PopStats {
- int healthy = population;
- int infWOSym = 0;
- int infWSym = 0;
- int recWOSym = 0;
- int recd = 0;
- int dead = 0;
- void update() {
- healthy = 0;
- infWOSym = 0;
- infWSym = 0;
- recWOSym = 0;
- recd = 0;
- dead = 0;
- for (Person p : people) {
- switch(p.infState) {
- case 0:
- healthy++;
- break;
- case 1:
- infWOSym++;
- break;
- case 2:
- infWSym++;
- break;
- case 3:
- recWOSym++;
- break;
- case 4:
- recd++;
- break;
- case 5:
- dead++;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement