Saturday, September 27, 2008

Light-Paint Piano Player

Light-Paint Piano Player from Ryan Cashman on Vimeo.


Thursday, September 25, 2008

Let's not use 3D pie chart

From this blog,

This is a share of textbooks for Tokyo metropolitan high schools.

The share of Nichibun (brown, 14.5%) is twice as much as Keirincan (blue, 7.2%) but the center angle is smaller than Keirincan, and those look nearly the same in size.

I would like people teach students not to use 3D pie chart in their information literacy class.
Pie chart itself is not good, as is described in R help,

Pie charts are a very bad way of displaying information. The eye is good at judging linear measures and bad at judging relative areas. A bar chart or dot chart is a preferable way of displaying this type of data.

Cleveland (1985), page 264: “Data that can be shown by pie charts always can be shown by a dot chart. This means that judgements of position along a common scale can be made instead of the less accurate angle judgements.” This statement is based on the empirical investigations of Cleveland and McGill as well as investigations by perceptual psychologists.

3D pie chart is even worth than pie chart.

This document is licensed under the Creative Commons Attribution 2.1 Japan License.
copyright by Haruhiko Okumura

Tuesday, September 16, 2008

Python virtual machine document

I've finished reading an excellent document on Python virtual machine and related stuff. (Japanese)

It covers

- disassembling with inspect module and dis module
- FrameObject, FunctionObject, CodeObject and their relationship
- data stack
- local, enclosure, global, builtin scope ... how they are implemented
- how to read Python Virtual Machine source code (ceval.c)
- other

I don't know if Japanese-English machine translation works well but if it does it'll be a good start to understand Python VM.

I'm currently reading inspect module to make a speech on "Python code reading", a meeting held by a local Python community in Tokyo.

Wednesday, September 10, 2008


matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts, the python and ipython shell (ala matlab or mathematica), web application servers, and six graphical user interface toolkits.

Looks nice.
Found the info from a blog entry on Ramblins about Python

Thursday, September 4, 2008

multiprocessing — Process-based “threading” interface in Python2.6
Haven't read it but looks it's a similar approach to POSH.
I'll update this post when I've read it through.

Wednesday, September 3, 2008

Visual programming

I have a strong interest in visual programming. Many programmers say it is not practical but they are ignoring its big success in CG. Most highend CG softwares have a node tree/graph and it is a visual programming environment in a sense.

Currently people are still making small ad-hock scripts for daily works if there's no appropriate tool exists, renaming files, file type conversion, registering something to another, opening a file, add some comment on it, save it and close it, find something in a file, replacing it, brabrabra... and the repeated execution of mixture of them. In big productions lots of works are automated but still they are doing a lot like this for non-procedual works daily.

In my opinion it's absolutely ridiculous to make scripts for them. Why do we have to make scripts for such small things? But currently there's no easier way.

There are several reasons why Python itself is not perfect for this reason.
- A module is too big to back-up dozens of smallest code snippets for later use.
- If a module has been changed, it'll be affected by all the scripts that uses it.
- Scripting is not intuitive.
- Python itself is not a tool to find a code snippet quickly.
- Try and error is not easy. Often you need to re-run a script.

(You may think "No, it's not. Everything listed here is so easy in Python", but I'm thinking of them from a point of view of non-technical people)

Several years ago I made a prototype of a Python based visual programming framework. It's target is artists who are not so much familiar with scripting. You can change the node network dynamically and see the result immediately, registering the node for later use, and reusing it by cloning. A node itself is a code snippet as well as a GUI representation tool so the user can relatively easily find where to look at when he is modifying the network .

You can find more information, and several capture movies here.

I'm making it with a German guy. Currently the project is almost frozen but I'm still hoping to release ver.1
I cannot say a lot cause we may release it commercially but he is looking at the tool from a different aspect, i.e. for professional programmers so it'll be a much larger system than what you would imagine after reading this post.

Test your color IQ

Test your color IQ

Found the test looking at my friend's SNS.
Drag&drop the tiles and reorder them.

I got perfect at the second try.

Why does a method becomes bound method when it is accessed with an instance?

Short answer:

Because it is part of Python specification.

Long answer:

It is something to do with __get__ special method.
If an attribute has a method __get__, it is called when the attribute is accessed with . (dot)

>>> class C(object):
... def __get__(*arg):
... print "hello", arg
>>> class D(object):
... d = C()
>>> D.__dict__["d"]
<__main__.C object at 0x00B32CB0>
>>> D.d
hello (<__main__.C object at 0x00B32CB0>, None, <class '__main__.D'>)
>>> D().d
hello (<__main__.C object at 0x00B32CB0>, <__main__.D object at 0x00B32CD0>, <cl
ass '__main__.D'>)

When you define a function, Python creates a function object and a function object has __get__ method.

>>> def f():pass
>>> f
<function f at 0x00B2EF30>
>>> dir(f)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__ge
tattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__r
educe__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'func_closure',
'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_na

and when you call __get__ of the function object, guess what will be returned?

>>> f.__get__(D())
<bound method ?.f of <__main__.D object at 0x00B32D90>>

Yeah it returns a bound method. That's why a method becomes bound method when it is accessed with an instance.

The short answer is a Python specification and the long answer is its implementation. property is also implemented with __get__.

>>> dir(property(f))
['__class__', '__delattr__', '__delete__', '__doc__', '__get__', '__getattribute
__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__
', '__set__', '__setattr__', '__str__', 'fdel', 'fget', 'fset']

Sep. 5 added:

> This is called the descriptor protocol.
> See the following for a long description of descriptors:

Thanx Fuzzyman!

X-Ray shader

Just a simple shader I made long long ago.

more info (Japanese)