Wednesday, June 15, 2011

Animating Touch, v. 0.1

Animating Touch is a simple animation editor that allows you to create short toons. Creative work in Animating Touch is quite easy. First, you don't need to draw every frame to get smooth motions. Instead of this, you create keyframes only and intermediate frames are built automatically. Second, skeletal animation is used here. It means every object consist of a number of connected "bones", which can be dragged.
Here are some ideas how you can use it:
  •  Drawing quick drafts of short stories or comics
  •  Creating hand-made greeting cards with your custom story
  •  Using as an animation training aid or a toy for children. It can be a good tool for little filmmakers
  •  Just for fun

    Below is the current list of features
    •  Three built-in models
    •  Two editing modes. You can edit nodes as well as rotate and drag whole objects
    •  Speech bubbles
    •  Displaying a skeleton of the previous frame to help you create keyframes more accurately.
    •  Undo
    •  Zoom/unzoom
    •  Save/load
    •  Adjustable speed of animation
    •  Choosing colors of skeletons and background
    Also for each object on a scene you can call a context menu through double click and perform various actions like deleting and editing properties.

    So far it's an alpha-version so there still can be bugs and many important features are missed.
    In future versions you will find exporting video, adding audio, backgrounds and many others.  

    Stay tuned.

    Wednesday, February 2, 2011

    Go Sling!

    Go Sling! is a slingshot shooter, its aim is to shot ducks, hedgehogs and other creatures with a sling. They can hide behind various obstacles like stones, trees, barrels, etc. You have to get a certain number of points to pass through the next level.

    Currently three levels are available:
    1. Rocky Lakes
    2. Fairway
    3. Apple Madness

    Here you can see a several game screenshots

    Go Sling! is free and available in Android Market


    AsciiCamera allows you to take a picture in ASCII style. In other words it converts your snapshot into a sequence of letters, digits and other symbols.

    The application has the following set of features:
    •  Switching between color and grayscale modes
    •  Inverting. When you select it, the background turns white, the letters turn black. It's useful if you want to see how can the text result look in a text editor.
    •  Scaling
    •  Importing existing images for processing
    •  Saving the result either as png image or as HTML-page (example)

    You can choose one of two ways to process images. Let's take a closer look at the algorithms.

    First one takes a bunch of pixels (2x2 or 4x4) and calculates their average brightness (that means "value" in HSV color model). Then we replace these pixels with a relevant symbol. The brighter the pixels - the more "colorful" symbol we use. For instance, "@" is equivalent to white and dot is equivalent to dark gray.

    The second approach is a bit more interesting. It takes every 4 pixels (2x2) and find a symbol that seems similar to these pixels (visually). So we build a matching table (16 rows in this case) that looks like this:

    Here you can see a few examples of how it works.

    You can find it in Android Market. QR-code:

    Tuesday, February 1, 2011

    Android: using unix pipes for tracking progress of native code execution

    One of my projects required tracking of how much code is executed at the moment. The situation was complicated by the fact that for a number of reasons some pieces of code were being executed in a few separate processes in turn.

    There was three options to choose from:

    • IPC-calls from native code
    • logcat parsing
    • passing data through pipes

    The last choice seemed best. Pipe is a common communication channel that may be used for one-way interprocess communication. Pipe has a file interface so we can handle it as it was an usual file. The main point of pipes is that we cannot write into it until someone start to read from this pipe and conversely, reading call blocks if no one writes into it. Another benefit is that several processes can write into a single pipe simultaneously (no synchronization mechanism needed).

    Here you can find a demo project. It starts a service that writes into a pipe from native code. Also there is a reading thread that can read data from the pipe and display it.

    Writing thread. It emulates a long running piece of code publishing its own progress. Below you can see the native implementation of "process" method.

        final String pipename = intent.getStringExtra("fn");
        new Thread(new Runnable() {
          public void run() {

    JNIEXPORT jint JNICALL Java_ru_jecklandin_cats_ProcessingService_process
     (JNIEnv * env, jobject, jstring path) {
      const char* cpath = env->GetStringUTFChars(path, NULL);
      struct stat buf;
      if ( stat(cpath, &buf) < 0 || ! (buf.st_mode | S_IFIFO)) {
        LOGD("The file isn't a pipe");
        return -1;
      int fp = open(cpath, O_WRONLY);
      if(fp == -1) {
        LOGD("Could not open the pipe");
        return -1;
      for (int i=0; i<10; ++i) {
        write(fp, &i, 1);
      env->ReleaseStringUTFChars(path, cpath);
      return 0;

    Reading thread. Creates a new pipe and starts to read from it as if it was a simple file. "read" call blocks until someone on the other side of the pipe starts to write data into it.


        final TextView disp = new TextView(this);
        final String pipename = getDir("pipedemo", Context.MODE_WORLD_WRITEABLE)
         .getAbsolutePath() + "/pipe";
        final File pipe = new File(pipename);
        new AsyncTask<Void, Integer, Integer>() {

         protected void onProgressUpdate(Integer... values) {
         protected Integer doInBackground(Void... params) {
          //create a pipe
          if (mkfifo(pipename) == -1) {
           Log.d(TAG, "Pipe error");
           return -1;
          FileInputStream fis;
          try {
           fis = new FileInputStream(pipe);
           int res = 0;
           while (res != -1) { //blocks until someone writes to this pipe
            res =;
          } catch (Exception e) {
          return 0;

    * This source code was highlighted with Source Code Highlighter.

    Warning 1: Despite our code might be run into a separate process, always launch long-running pieces of code in separate threads. Otherwise, the system can kill the hosting process without notice.

    Warning 2. Don't create pipes on sdcard - FAT32 doesn't support them.

    Add "process" attribute to our service in AndroidManifest.xml to make sure it works in a separate process.

    <service android:name=".ProcessingService"

    DDMS displays both processes

    When you compile and run the project, there will be an increasing number on the screen (not very eye-catching, I know).

    If you need a duplex channel, just create one more pipe. Sure, this solution isn't a silver bullet. If there is a need to pass complicated objects between processes, you should consider using standard Android IPC tools (I mean aidl).

    Useful references:


    Saturday, January 17, 2009

    Console screencast

    Recording your work sessions in terminal is easy. The tool by the name of "script" that is included into util-linux-ng package can track all your actions, write them into a file and playback later. More specifically, the program records your input and terminal's output. The most interesting part is replaying these logs in realtime. That can be performed with the help of "typescript" tool (written in Perl).

    > script -t 2>replayfile
    > # perform actions..
    > Ctrl^D
    > scriptreplay ./replayfile

    Option -t means the timeline will be written to stderr. By default, scriptreplay reads "typescript" file and playbacks it at the normal speed. You can change it by pointing another file or setting another playback speed:

    > script -t 2>replayfile my_typescript
    > scriptreplay ./replayfile ./my_typescript 3

    Here "3" means the actions will be played 3 times faster.

    Another interesting use is recording working sessions with pseudographic applications. It can be useful if you perform some risky actions (for example, disk partitioning with cfdisk) and you need to blamestorm later or to give a master class. Creating tutorials - one more way to prove your virtuosity in using vim.