- Drake's blog
- 留言回應
- 22 reads
Dracula2 by gource
上週五用 gource 這個玩意兒,把 Dracula 2 的開發過程(持續開發中),以視覺化的方式呈現出來,實在很有趣。
最後的樣子,是楓葉?
- Drake's blog
- 留言回應
- 188 reads
My first experience in Erlang
I recently started learning Erlang, one of famous functional programming languages, which is also a general-purpose concurrent programming language developed by Joe Armstrong. (I love the name Armstrong. Sounds cool!) And why do I bother to learn another programming language? I think I has been influenced by The Pragmatic Programmer, which suggests programmers to pick up a new programming language once a year to fresh your mind.
Some of my experiences:
- Compared to C/C++ family's semicolon ";" in the end of statements, Erlang's usage of decimal point "." is kinda interesting. It makes me think of programming as writing an essay.
- The force of variable's name to be started with an uppercase letter (ex, "Drake" is a variable name while "drake" is not.) is so tiresome. It might destroy my left little finger one day. But it is, at least, better than using dollar signs :p
- Preventing double "pattern matching" (or variable bounding) of one variable is new to me and I am getting used to it to figure out what really benefits I can have to this restriction.
- The built-in data type, integer, is kinda like Big-Num, which I love so much!
- The meaning of "=" is not assignment but "pattern matching" guides me to the ideas of no-side-effects in FP.
-
Some mathematic or arithmetic operators are so weird:
- ">=", but "=<" ?! (not "<=")
- "=:=" means equality testing.
- "or" and "orelse" are different.
- In some context, ";" is semantically equal to OR; while "," is AND.
- The braces "{}" are used for data type, Tuple, is not that familiar to me cause I have already used to Python's way by parenthesis "()".
- Making usage of Tuple for record (or struct in C way) is not that cool for Dictionary for that in Python.
-
Claus, the great way to express some function definition in more mathematic way. It somehow looks like polymorphism in OOP and I love this more than OOP way!! Ex.
area({rectangle, Width, Ht}) -> Width * Ht;
area({circle, R}) -> 3.14159 * R * R. - The different syntax for "function definition" and "claus definition" troubles me sometimes. (put "end" in the end of fun()...)
- The Erlang shell's auto-completion is kinda weak when I am used to ipython's convenience.
- The functional way to describe/define the function has so much fun!!!
-
List comprehensions in Erlang seems more powerful than in Python. Check this out:
pythag(N) ->[ {A,B,C} ||A <- lists:seq(1,N),B <- lists:seq(1,N),C <- lists:seq(1,N),A+B+C =< N,A*A+B*B =:= C*C].
> lib_misc:pythag(40).[{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17},{9,12,15},{12,5,13},{12,9,15},{15,8,17}] - Still, I have to say, "the Erlang shell is so weak!". I think a powerful shell is the necessary to make a learning programmer happy and easy-life.
- Drake's blog
- 留言回應
- 691 reads
Functional Programming: Lisp
What Made Lisp Different. The 9 original and new ideas embodied by Lisp, a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax, are:
- Conditionals.
- A function type.
- Recursion.
- Dynamic typing.
- Garbage-collection.
- Programs composed of expressions.
- A symbol type.
- A notation for code using trees of symbols and constants.
- The whole language there all the time.
在看 Hackers & Painters 過程中,稍為了解 C -> C++ -> Java -> Perl -> Python -> Ruby 的演化,一種“趨向 Lisp 的進步方式“。根據 Paul Graham 書中的陳述,這些語言一個一個發展下去,從最早的“執行起來快“的 C/C++,慢慢往“語言本身能力比較厲害“的方向走,然後最厲害的,就是 1958 年由 John McCarthy 發明的 Lisp 了。(正確來說,是他的學生 Steve Russell 實現了第一個 Lisp interpreter,有趣的是,這位 Russell 同時是歷史上,寫出第一個 video game, Spacewar!, 的作者!)
根據 The Pragmatic Programming 的說法,一位積極進取的 programmer 應該做的事情之一,就是每一陣子去學習一個新的程式語言,另一種有別於你已經會的程式語言。透過從骨子裏學習新的語言,除了可以喚醒你「初學程式語言的新鮮感」,同時可以讓你學到以不同的觀點看待“寫程式“。為此,我打算隔一陣子,來去學學大一之後就沒有再接觸的 Lisp 家族。
- Drake's blog
- 留言回應
- 943 reads
TIFF file handling in PIL
# TIFF is a flexible, if somewhat aged, image file format originally
# defined by Aldus. Although TIFF supports a wide variety of pixel
# layouts and compression methods, the name doesn't really stand for
# "thousands of incompatible file formats," it just feels that way.
thousands of incompatible file formats, 這個的確有挖苦到 TIFF 這個格式 XD
- Drake's blog
- 留言回應
- 966 reads
Maya Scripting: MEL V.S. Python
Maya scripting 現在有了 MEL 與 Python 可供選擇,對於大部分的 Maya 使用者來說,這是件微不足道的事,但對於天天使用與撰寫 Maya scripting 的人來說(ex, TD?!)(或保守一點的說,很有機會被要求寫點程式的人),這重要極了。
個人淺見,Python 與之後由 Luma Pictures 的 Chad Dombrova 所推出的 pymel (0.7.8),是 Autodesk 買下 Maya 後,在 8.5 所做的 features 裏頭,最最重要的一點了。好吧,我是以 RD/TD/SD 人員的角度來看事的,請先暫時原諒我這有點狹隘的說詞,然後接著繼續看文章。
Maya 8.5 發表以前,在 Maya 上頭工作的技術人員,除了和大家一樣要去了解與使用 Maya 以外(說真的,Maya 的學習曲線有點長,進入門檻有點兒高,以致於很多資訊系所的電腦圖學實驗室,都不容易利用這個工具來做點什麼,實在很可惜),可能還需要去了解一下 Maya ascii file format, Maya nodes, Hierarchy in a Maya scene file, Mel, Maya C++ API, 技術名詞, …好不容易似懂非懂一些東西後,就是寫些程式來試試看。
舉些個例子。如果你想寫個可以自動幫你架好骨架的 joints 與一些 IK/FK 的設定的東西,你可以利用 Mel 來做到;如果你希望有一個特別的材質球,它會在你的模型有互相穿刺時,用紅色這種非常鮮豔且帶警告意味的顏色來提醒人,你可以用 C++ API 寫個 plugin 來提供一個特製化的 material node;如果你想用透過一個放在 Maya shelf 上頭的按鈕,讓 lighter 可以很快的下算圖指令的話,那你可以使用 Mel 外加 RMS/MtoR 提供的指令來做到;如果你想利用 locator 來實作 instance(一些 Maya instance 無法做到的情況下),同時要讓這個 locator 秀出原 reference model 的各種動態的話,你得用 Maya API 外加對於 Maya node 的了解(當然,你也可以使用 billboard(sprite) 做到);…
事情就是這麼複雜,以致於要訓練出一位可以依靠的 3D/CG TD,實在很花時間。如果很不幸地又沒辦法好好留住他,或是他個人不夠積極與拼命學習的話,可能浪費了兩三年,然後拍拍屁股走人,什麼都沒有留下來!!
這邊我們也許應該換個觀點,先來想想:「為什麼 Maya 把事情搞得這麼麻煩?」
- Drake's blog
- 2 則回應
- 閱讀全文
- 3325 reads
Python Puzzle
Interesting subsequent comparison:
>>> a = 1
>>> b = 10
>>> c = 100
>>> a < b < c
True
>>> (a < b) < c
True
The following 2 code snippets are equal, which can explain why the above code works in that way.
if a < b < c:
doSomething()
if (a < b) and (b < c):
doSomething()
How about booleans? Is True bigger than False?
>>> True < c
True
>>> True > c
False
>>> False < True
True
>>> False > True
False
And I just noticed that True / False are 1 / 0 in one implementation of CPython 2.5?! According to official document, the True & False are special type called "bool" which should not be used to compare against other type.
>>> False == 0
True
>>> True == 1
True
>>> True == 2
False
>>> False == 2
False
How about is?
>>> None is None is None
True
>>> (None is None) is None
False
>>> None is (None is None)
False
Because is is also a comparison (not a binary operator)!!! It might be not that intuitive to figure out this situation especially when you are programming some logical expression with if.
Let's do play again True and False and I believe this time you can get it through.
>>> True is True is True
True
>>> False is False
True
>>> (False is False) is False
False
Check this if you wanna get more idea about Python's expression.
- Drake's blog
- 留言回應
- 1805 reads
Cancellation Error
今天聽莊永裕教授的 Digital Image Synthesis 課時,聽到一個 Cancellation Error 的東西,是個與 IEEE floating point 有關的「數值計算問題」。
投影片上如是說:
Cancellation error: devastating loss of precision when small numbers are computed from large numbers by addition or subtraction.
寫了個簡單的 c 程式親身試驗一下。
void main(){
double x1 = 10.000000000000004;
double x2 = 10.000000000000000;
double y1 = 10.00000000000004;
double y2 = 10.00000000000000;
double z = (y1-y2)/(x1-x2);
printf("%f\n", z);
}
// output:
// # 11.500000
接著我在想,Python 會不會有這個問題呢? 結果試了一下…一樣!! 看來 CPython 的 number 這個 type 真的是用 double 實作的 :o
- Drake's blog
- 留言回應
- 4189 reads






