Drawing Amoebae Part 1


We've just started working on a simple Android game related to "the cell." We only have a vague idea, at this point, of what the general premise of the game is, but one of the graphics requirements is the ability to draw a dynamically moving and undulating amoeba with smooth graphics. So this is how we went about doing it.



To start, the outline of the amoeba consists of 20 or so evenly spaced nodes shaped as a circle. Here we will only show a few for simplicity. To get the locations for x number of nodes around a circle we use basic trigonometry.
increment = 2PI / numPoints;
For each point calculate the angle:
theta = i * increment;
To get the x and y locations from this angle use:
x = radius * cos(theta);
y = radius * sin(theta);




In order to keep the amoeba at a generally-similar size and shape it will be bound by somewhat of an exoskeleton. So at each of the previously calculated locations we create a node representing a piece of the exoskeleton which will not move or be visible (dotted) and an actual node mass which moves and makes up the shape of the amoeba (solid). These nodes are assigned random momenta so they start of moving in random directions.






If we just let the masses move off in their random directions decided in the previous step this wouldn't look like an amoeba at all. We now need to make the the amoeba undulate. We do this by simulating the physics which would happen if there were a spring between each node and a strong spring between each node and its corresponding exoskeleton point. This will keep all of the nodes close together so they are similar to the original circular shape, but allow them to undulate forming the basic outline of a moving amoeba.




Putting all of these steps together we get a very amoeba-like set of ~20 points, which undulates to varying degrees depending on the various constants we set. We are able to modify the spring constants, the masses of the nodes, and the number of nodes in order to experiment with various effects. Here is the result of our first few steps:

No comments:

Post a Comment