Category: ‘Toys’

Fluid Hydrodynamics

[Projects,Toys] (07.22.10, 5:04 pm)

A while ago I had a brilliant idea of doing a fluid simulation to get interesting material effects that could potentially be used in Painter. I did some research and discovered a paper on Particle-based Viscoelastic Fluid Simulation. The implementation described was pretty much exactly what I needed, so I set forth to make a library to handle effects.

And of course, it’s also useful to have a nice shiny demo.

Looks like applets don’t work for you. Go to www.java.com to get Java.

Spy Games

[Projects,Toys] (05.31.10, 5:16 pm)

This is a project for my Game AI course in Spring 2010. The project was a collaboration between Ken Hartsook and myself. The AI system used for the NPCs was inspired by Cutumisu and Szafron 2009. “An Architecture for Game Behavior AI: Behavior Multi-Queues“. The primary goal of the project was to develop a game in which social interaction is a primary game mechanic.

To play the game, click on the other characters and choose options to engage with them socially.

Looks like applets don’t work for you. Go to www.java.com to get Java.


[Experiments,Projects,Toys] (11.22.09, 12:50 pm)

At long last I have a demo of Painter that does something interesting. Click on it below to have it start.

Looks like applets don’t work for you

More Cellular Automata

[Genetic Image,Toys] (04.17.09, 6:56 pm)

I’ve been very interested in doing experiments with cellular automata and other soft of image generation work, and amid reading AI papers, I’ve done some miscellaneous code experiments. Right now I’ve built a nifty little system that is able to handle many types of CAs, and can represent in space in several ways, represent their contents in several ways, and render them in a variety of ways as well.

I’ve included a little demo applet which handles a small diffusion-like CA, and is hopefully a sign of some things potentially to come.

Looks like applets don’t work for you


[Experiments,General,Toys] (01.21.09, 10:22 pm)

I am really interested in metaprogramming, writing programs which can modify themselves dynamically. More notably, users of metaprograms will be able to change their functional operation. The advantage of being able to do this is that it enables a great deal of power for development and creating things, but primarily, it’s just a lot of fun. There is something about being able to call functions using reflection that just is really pleasing and entertaining to me.

Most commonly scripting frameworks are used to create secure environments for scripts, and often these scripts will be developed ahead of time, but they also enable a possibility of dynamic scripting, where a scripting environment may be able to do interesting things during run time. Possible examples of run time uses are controlling agents within a world by issuing commands and writing code for an agent’s “brain”, then loading to that into the agent which is live in the world. It would be possible to create a dynamic music or image making program, where the artist can control what is being played or drawn using the scripted code.

With the recent release of Java 1.6, we now have standardized implementation of JSR 223, also known as the scripting framework, which enables some exciting metaprogramming possibilities. This allows one to script on top of Java. So, it would be possible to interact with Python, Ruby, Javascript, or any  other sort of scripting language through this one framework. Interestingly, it is also possible to use Java as a scripting language. Thus, you can script for a Java program… in Java. This may seem ridiculous to some, but I think this is simply delightful.

Here is an example of the scripting framework in use. Note, to actually run this, you must add the java-engine.jar, found in jsr223-engines.zip to the classpath.

package scripttest;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

 * @author Calvin Ashmore
public class Main {

     * @param args the command line arguments
    public static void main(String[] args) {

        ScriptEngineManager mgr = new ScriptEngineManager();

        ScriptEngine scriptEngine = mgr.getEngineByName("java");
        Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
        for (Entry<String, Object> entry : bindings.entrySet()) {
            System.out.println("  " + entry);

        try {
            scriptEngine.put(ScriptEngine.FILENAME, "Toasty.java");
            String script = "public class Toasty {" +
                    "  private float myStuff;" +
                    "  public Toasty(float stuff) {" +
                    "    myStuff = stuff;" +
                    "  }" +
                    "  public String toString() {" +
                    "    return \"I have a thingy! \"+myStuff;" +
                    "  }" +
                    "  public int performWombat(String theWombat, float multiplier) {" +
                    "    int toast = Integer.valueOf(theWombat);" +
                    "    float thingy = toast * multiplier;" +
                    "    double d = Math.sqrt(1 + thingy*thingy);" +
                    "    return (int) d;" +
                    "  }" +

            Class toastyClass = (Class) scriptEngine.eval(script);
            Constructor c = toastyClass.getConstructor(float.class);
            Method m = toastyClass.getMethod("performWombat", String.class, float.class);

            Object toasty = c.newInstance(1.0f);
            System.out.println("My toasty: " + toasty);

            System.out.println("This will work:");
            System.out.println("result: " + m.invoke(toasty, "234", 1.23f));

            System.out.println("This will not:");
            System.out.println("result: " + m.invoke(toasty, "eek", 1.23f));

        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

(Apologies for the strange variable names) It generates the output:

My toasty: I have a thingy! 1.0
This will work:
result: 287
This will not:
Jan 21, 2009 9:27:15 PM scripttest.Main main
SEVERE: null
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at scripttest.Main.main(Main.java:70)
Caused by: java.lang.NumberFormatException: For input string: "eek"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:447)
        at java.lang.Integer.valueOf(Integer.java:553)
        at Toasty.performWombat(Unknown Source)
        ... 5 more

This example is able to instantiate and call methods on a simple object effectively. However, in order to do the more interesting things described above, we need to make use of interfaces. So, the scripted class will implement an interface defined by the main program. That interface will define the contract for operation. So, instead of using reflection to call methods, we can simply cast the object to belong to the interface and call the methods directly. I’m not going to write this yet, but maybe soon.

Fun with the Henon map

[General,Toys] (12.10.08, 11:08 pm)

I just built something that I’ve been meaning to make for years. I tried building something like it before, about 5 years ago, right before I graduated from CMU. At the time, I had strong programming ability for small projects, but didn’t really know how to write programs modularly with any effectiveness. I’ve learned so much since then, so now something that took a really inordinate amount of time and never got off the ground before took two days to write. I like to program recreationally. It’s a very bizarre habit. It’s not a compulsion, but really just a passtime.

The project in question is a visualizer for strange attractors. I did research on them as an undergraduate at CMU, and I’ve been wanting to make this project as a general tool ever since. I wanted something that could display stuff in both parameter space and phase space, and effectively get at all of the peculiar things that can happen with strange attractors.  The example below only does anything interesting in phase space, but it’s rather flexible, and has a nice modular architecture, which means that it will be easy to adjust properties, add or remove visual elements, and generally do interesting things.

It does not seem to behave quite properly with the mouse wheel at the moment, but it should have zoom functionality…

Java 1.5 or higher is required to run this applet. Please download a JRE from java.sun.com.

That’s organic!

[General,Toys] (04.25.08, 9:58 am)

So, yesterday’s experiments with Cellular Automata filled me with a curious desire to represent natural patterns and forms. I like CAs, but they usually wind up being lacking at some fundamental level in representing something that is natural. Perhaps it is because of their small granularity and pixelated nature. After all, they’re cellular. Natural forms too have cells, but pigmentation usually is much more fuzzy.

I tried to create something that took yesterday’s applet and blurred it, producing an aesthetic effect.

By the way, about the controls: The first drop down is the blur control, the second is the algorithm, the third is the number of inputs (3 means that the CA takes three cells above it as input), and the last one is the number of colors for discrete automata.

Looks like applets don’t work for you

A New Kind of Silliness

[Art,Experiments,General,Toys] (04.24.08, 7:29 pm)

I’ve been familiar with Cellular Automata for a while, and I generally tend to approve of them. Especially when they have some nice evocative qualities. We read and discussed Wolfram’s A New Kind of Science in one of my classes, which was a lot of fun. We really tore into it. My problem with the book is that while I appreciate and respect the ideas behind his work, the mathematician in me wants to wring the book until theorems come out, which of course they don’t, because there are no proofs.

I feel especially frustrated on that account because of the work I did with strange attractors. I found significant visual evidence that the parameter space for the attractors has fractal characteristics, but I was never able to prove it. Very sad.

Anyway, revisiting Wolfram led me to remember my use of cellular automata in GeneticImage, and thinking about how they could be used in Painter or other projects. I was quite pleased with the last applet posted regarding Painter, so due to this, I think I will post one with a cellular automata generator. This is primarily intended for artistic rather than any other purpose. Please fiddle with knobs and levers to your heart’s content!

Looks like applets don’t work for you

More progress on Painter

[General,Genetic Image,Projects,Toys] (04.19.08, 12:18 am)

Because I don’t know when to quit on these things (or, possibly because working on somethings helps me relax from working on others), I made some nice progress on Painter, and rather than showing images, I figured I might embed an applet. This is very simple, and contains some primitive graphical methods, but is nonetheless quite neat and has its own sort of style.

The applet will think when you click on it, and if it thinks for too long (10 seconds) it will realize that it is confused and allow you to click again. If you are interested in this project, it is available via svn on the Painter site. The documentation on the site is abhorrent, I know.

EDIT: Due to strange technical issues, I had to take the applet down, as it was causing issues with browsers. I truly regret having to do so, but I just haven’t been able to fix it yet.