Monthly Archive for October, 2009

How Maple helps

Sometimes it’s good to test some math model before coding it into ActionScript or any other language, draw some cool graphs and play with parameters. Of course you could write a simple flash application to draw graphs for you but why waste time if there are a lot of math software around? In school we used Maple, so from time to time I use it to check stuff before actually coding it. I have to say that I’m not good at it but my knowledge is enough for my own tasks.

Well, right now I need to code a pseudo random movement. I need some kind of a periodic pattern with bursts and decaying.

So, I opened Maple and set several constants I had in mind.

mpl1

minAmp — minimal value of global amplitude,
maxAmp — maximum value,
minLen — minimal wave length,
deltaLen — minLen + deltaLen = maxLen — maximum wave length,
speed — wave speed (rendered useless).

After that I wrote functions for amplitude.

mpl2

In the example I used constant wave length, didn’t have time to play more with it. Here everything is simple. We have some x value from which wave length and amplitude is counted. Both are periodical.

mpl4

Here’s the graph.

mpl3

Now we can add one more sin which will be limited by this amplitude.

mpl5

We are getting a periodical movement but it’s too boring. Here goes the magic.

mpl6

This function generates all the randomness. Simply put, there’s some seed which grows from 0 to 1 (actually a bit more) by dseed and after it reaches 1 it goes back to almost zero and dseed (delta seed — seed change speed) changes to some other value controlled by minRand and ampRand. At the end we get new value in the last line.

That’s how we get such a jerky rhythm, and because of dseed the movement can be be fast and slow. And everything is limited by periodic amplitude.

Let’s check the result.

mpl7

This is just what I wanted. If you play with parameters a bit ou can get very interesting results.

Here’s the example. You shouldn’t stare it for a long time q: It uses much CPU so I recommend you to close the tab after you finish reading.

Maple source.

Why not Unity3d use Flash?

Flash could be great in Unity3d for interfaces, minigames and even animated textures. They should definitely research the possibility of using it. Maybe it’s possible to write a custom Flash Player how the guys from Scaleform did.

Prolog for Mac

Let’s assume that you need to set up Prolog for OS X. If you are still here let’s continue.

After reading some book from 80s about Prolog I found that language to be interesting and I decided to write some simple things in it. But I had to install it somehow on my Mac preferably without any stupid virtual machines. So here’s what I ended with.

  • All crossplatform solutions are based on Eclipse, so first of all you need Eclipse. There are a lot of versions, but I chose the one with less stuff I don’t need because I won’t use anything related to Java development.
  • The first plugin I tested was PDT which is too old and doesn’t work with Eclipse 3.5, I downloaded 3.1 but haven’t tested it because I got another plugin which works — ProDT. This is just what I need. From Downloads you should choose the smallest file.
  • For ProDT to work you need SWI-Prolog — some kind of opensource Prolog.
  • I’m not sure if SWI-Prolog requires MacPorts, but anyway I recommend you to install it. It’s useful.
  • Extract ProDT to eclipse/dropins/prodt/eclipse/plugins, run eclipse which installs it automatically.
  • After that in ProDT preferences ( Eclipse -> Preferences -> Prolog -> Compilers -> Swi Compiler ) set compiler path which is at /opt/local/bin/swipl.
  • Switch to Prolog view Window -> Show Perspective -> Other… -> Prolog.

That’s it. Now you can test if it actually works:

yes( one ).
yes( two ).

Run and write in console:

yes(X).
x = one ;
x = two.

OOP

2009_09_11_11_31_pictureisunrelated_com_wp_content_uploads_2009_08_MartinK_mustunplug

OOP in action.