Kedama: A massively-parallel tile-scriptable particle system
Introduction
Kedama is a Japanese word for "fluffy ball", or "wooly ball". The latest version is Kedama 2.7.
1. Get started
- Now the easiest way to use Kedama is to visit http://www.squeakland.org and download the latest Squeakland version from there.
2. Get the Kedama world
- Bring 'Kedama' from ObjectTool's Kedama category. (See 0.png.) You'll get a black rectangle. It is the Kedama world.
- Bring up the viewer of the rectangle.
- Go to the 'kedama category in the viewer.
- From the "cracker" menu of "patch" instance variable, choose the first "grab morph" item. (See 1.png.)
- Drop the smaller black rectangle somewhere. (See 2.png.) This smaller one represents the pre-made patch variable.
3. Get an exemplar of turtles
- Choose "add a new turtle" item from the cracker menu of Kedama world's viewer. (See 3.png.)
- Drop the colored rectangle somewhere in the Morphic world. Notice that you get a dot in the same color in the Kedama world. The color is determined randomly. In the following explanation, I use the green color as in 4.png.
- Get the viewer of the colored rectangle. you'll see the viewer of the object called "turtle1".
| 3.png |
 |
4. Wrapping Atoms
- Drag out the turtle1's "forward by 5" tile and create a script.
- Start ticking the script. The green dot in the Kedama world will start moving.
- Increase the number of turtles by changing "turtle1's turtleCount". (See 4.png.) Newly created turtles are placed and headed randomly. Notice that a turtle is wrapping to the other end when it hits the edge.
- Change the speed of turtles by changing the value of forward by.
| 4.png |
 |
5. Bouncing Atoms
- Open the Kedama world's viewer.
- There are four "edgeMode" variables. Try different modes. If you change all of the edge mode to "bounce", it becomes bouncing atoms.
- Change the background color from the Kedama world' viewer if you like.
6. Trail
- Go to the turtles viewer, drag out "patchValueIn" tile and drop it onto the first scriptor. (See 5.png.) Change the argument value of the tile to 20. Notice that the color in the smaller rectangle gets "bluer" gradually. This tile specifies to put value 10 in the patch named "patch" at the position where the turtle resides.
- Press the little upward triangle at the left of "patchValueIn" to change it "patchValueIn patch increase by".
- Change the turtleCount to "20".
- Change the forward by argument to "2".
- Get the viewer of the patch variable (the smaller rectangle).
- Goto "kedama" category of the viewer of the patch variable.
- Change the "scaleMax" value to "50".
- Drag out the "diffusePatchVariable" and drop it onto the scriptor.
- Press the yellow exclamation mark at the left of "patch clear". You'll see the dots leaving "fume". (See 6.png.)
Phrases in a scriptor will be executed in a manner I call "line-wise synchronization." This means that a line will be executed after everything related to the previous line gets completed. For example, in this example in 6.png, "patch diffusePatchVariable" is executed after the everybody in turtle1 breed completes the "patchValueIn:" action.
| 5.png | 6.png |
 |
 |
7. Epidemic
You can implement a disease infection simulation. Each turtle has a variable called infected, and if a non-infected guy touches an infect guy, it gets infected.
- First, add an instance variable called "infected" to the turtle1. Set the data type of "infected" instance variable to "Boolean". (See 7.png).
- Switch to the Kedama world's Viewer, and add a variable to the Kedama world called "infectedCount".
- Create a script looks like the one in 8.png. Let's name it "setup". The idea of this script is to set the turtle count to 1000, everybody's infected variable to false, the "global" variable "infectedCount" to 0, and then infect only one guy. Execute the script once by clicking the yellow exclamation mark button and the Kedama world will look like 7.png, where only one guy is red and others are green.
- Create another script called "oneStep" that looks like the one in 9.png. The idea is that each turtle in turtle1 breed wanders around, and leaves a trail in the patch variable if it is infected. If a non-infected one sees the trail, it gets infected. If you start ticking the "oneStep", you should see what it is supposed to do.
Do you notice the common pattern in "setup" and "oneStep"? You can factor them out to one script and call the script from these. Do you think the simulation is too slow? You can increse the tick rate from the menu you get by holding the mouse button on the clock. 50 per second would do it.
8. Tick rate, diffusion rate, evaporation rate, logarithmic and linear display, and etc.
As I wrote above, the tick rate is vital to make an interesting simulation. Hold the clock button of a ticking script and change the tick rate. Diffusion rate controls how much dissusion happens per tick, and evaporation rate controls how much decaying happens per tick.
Internally a slot of the patch is represented as 32-bit unsigned integer.
There are two types of displaying. One is logarithmic (default) and another is linear. It is controlled by "useLogDisplay" variable in the viewer of a patch. In logarithmic type, the log value in the patch is used. the strength is relative to the "scaleMax" value. That is, the value of 1 or 0 is displayed as transparent, the value greater or equal to "scaleMax" is displayed as opaque, and the value inbetween are displayed as particular translucency.
In the linear mode (useLogDisplay = false), the value in patch is shifted by the "shiftAmount" value and the resulting value is used to represent a alpha value from 0 to 255.
You can also "show" and "hide" turtles. Choose command from the turtles viewer.
9. upHill
Turtles can sense the gradient of the patch values. See the "ants" example.
10. Fill the world with turtles
You can "fill" the world with turtles. If you drop a sketch, you get the turtles in the sketch'es pixel pattern. See the "pixel" example.
13. Angle to and distance to
See the "pixel" example and "forest fire" example.
14. TODOs
As of Jan 24th, 2005:
- Create a legitimate "TurtlePlayer" type.
- Give different colors to turtle actions and observer actions.
- Incorporate the "Point" type in the system.
Examples
- The epidemic example is here.
- The ant colony example is here.
- The pixel example is here.
- The gas tank example is here.
- The forest fire example is here.
- The Diffusion example is here.
- The Predator Prey example is here.
Contact
Yoshiki Ohshima
Viewpoints Research Institute
1209 Grand Central
Glendale, CA 91201