{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Infectious Diseases\n", "\n", "Consider a simple disease that follows these simple rules:\n", "\n", "* if you have it, then you always have it\n", "* if you come \"in contact\" with someone who has it, then you get it\n", "\n", "Sounds like zombies?\n", "\n", "What would happen? How can we model this world?\n", "\n", "## Simulation\n", "\n", "First, we must identify the objects we wish to model. Possibilities include: \n", "\n", "* people\n", "* world\n", "* disease\n", "\n", "First, let's consider what properties a person should have:\n", "\n", "* position in the world\n", "* whether it is carrying the disease or not\n", "* direction heading (vector, velocity on x and y)\n", "\n", "Also, what actions must a person be able to do:\n", "\n", "* move in the world\n", "* draw itself\n", "\n", "We might want to add other methods, but it needs to at least support those.\n", "\n", "## Person\n", "\n", "So, let's put together a person class. It might look something like:\n", "\n", "```java\n", "class Person {\n", " int x;\n", " int y;\n", " int vx;\n", " int vy;\n", " int carrying; // zero - not carrying disease; 1 - carrying disease\n", " \n", " Person(int x, int y) {\n", " this.x = int(x);\n", " this.y = int(y);\n", " this.randomizeDirection();\n", " this.carrying = 0;\n", " } \n", " ...\n", "}\n", "```\n", "\n", "Like the termites, instead of having them bounce off of the walls (like a ball simulation) we will instead have them \"wrap\" around (like a [torus](https://en.wikipedia.org/wiki/Torus)). For example, if a person goes too far to the left, it will wrap around to the right, and instantly appear there. Likewise, if a turtle goes below 0 or above height, then it wraps back around. Thus, we implement an infinite, repeating surface.\n", "\n", "This putting it all together might look like the following. \n", "\n", "Note:\n", "\n", "* people are represented by ovals. \n", "* people turn green when they are infected" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " Sketch #4:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "