为四川人民祈祷! www.crcf.org.cn
logo of kjam.org

让我们为四川人民祈祷!

让我们为四川人民祈祷!

那么多小孩子阿, 真可怜. 希望能救活更多的人.


发现一个可以在线捐款的地方:
www.onefoundation.cn 支持支付宝, 财付通以及 Firefox 可以用的 Paypal.
comments: 0  
by kernel1983

Let's dream of a day without flash and java applet

我预感, 或许有一天我们可以把Flash, Java Applet 还有该死的 Internet Explorer 一起丢到 Trash 里面去

为了实现这一个伟大的梦想, 我要给朋友们看两个links
http://developer.mozilla.org/en/docs/HTML:Canvas
http://ejohn.org/blog/processingjs/

第一个比较重要一点, Firefox为我们带来的惊喜. 我们可以在 Firefox 中直接使用 JS 画出图形.

一直以来, 浏览器天生缺乏这方面的功能, 只能以插件方式来实现(Flash和Java Apple, 对了还有 ActiveX ). Gecko 1.8 引擎(Firefox 1.5)的开始支持 canvas标签, Webkit 也有支持(就是 Safari, 测试过), 据说最新 Opera 也支持.

第二个link是 jQuery 作者的一篇 blog post, 他做了一件很酷的事情, 就是让超级好玩的玩具 Processing 的语法可以被 JS 解释, 并且将结果显示在一个 canvas html 标签中, 不过, 看起来暂时还只能在 Firefox 中得到正确的结果.

看来最近大家都对图像多媒体比较感兴趣, 难道是最近趋势?
comments: 0  
by kernel1983

Rubik's Cube modeling in python

虽然知道一定有人写过这样的东西, 好起兴依然驱使我花时间做这样一件事情.
Rubik's Cube 的数据结构如何表现, 在多次失败以后, 发现坐标绝对是超级好用的东西. 在图形编程中, 千万不能小看坐标的威力.
from math import *

class RubikCore(object): # example of define the data struct of a rubik's cube R = 0.5 # red G = 0,1,0 # green B = 0,0,1 # blue W = 0,0,0 # white Y = 1,1,0 # yellow D = 0,1,1 # dark brown cube = {} def __init__(self): self.init_cube() self.fill_face()
def init_cube(self): # create a matrix seq = (-1, 0, 1) for x in seq: for y in seq: for z in seq: self.cube[(x,y,z)] = {}
def fill_face(self): # fill color for every face seq = (-1, 0, 1) colors = {(1,0,0): self.R, (-1,0,0): self.G, (0,1,0): self.B, (0,-1,0): self.W, (0,0,1): self.Y, (0,0,-1): self.D,} for x in seq: for y in seq: for z in seq: for i,v in colors.iteritems(): self.cube[(x,y,z)][i] = v
def find(self, axis, value): # give axis and value find all the objects matched
AXIS = {'x':0, 'y':1, 'z':2} res = [] for i in self.cube: if i[AXIS[axis]] == value: res.append(i) return res def _rotate_plane(self, x1, y1): """ x'=xcosA-ysinA y'=ycosA+xsinA """ x2 = int(round( x1*cos(-pi/2) - y1*(sin(-pi/2)) )) y2 = int(round( y1*cos(-pi/2) + x1*(sin(-pi/2)) )) return x2,y2 def _rotate(self, axis, t): # pass a tuple(x,y,z) if axis == 'x': y,z = self. _rotate_plane(t[1],t[2]) return (t[0],y,z)
elif axis == 'y': x,z = self. _rotate_plane(t[0], t[2]) return (x, t[1], z)
elif axis == 'z': x,y = self. _rotate_plane(t[0], t[1]) return (x, y, t[2]) else: return None
def turn(self, axis, value): t = self.find(axis, value) n1 = {} for i in t: n1[self._rotate(axis, i)] = self.cube[i] n2 = {} #print self.cube[i] for l in self.cube[i]: n2[self._rotate(axis, l)] = self.cube[i][l] #print n2 self.cube[i].update(n2)
self.cube.update(n1)

写了一个数据结构的core, 要显示这个cube, 方法很多, 可以用OpenGL, 用PyGame, 只要继承这个类就可以了.

我自己在调试的时候使用了最偷懒的方法, NodeBox. 而且看起来, 想要找一个不错的3D引擎来搞定这些凡人的活, 还是很有挑战性的. OpenGL的抽象程度还是太低了, NodeBox在3D方面仍然缺乏足够的力量... 这样的工作如果使用Panda3D之类的东西来做, 是不是又有用牛刀的嫌疑?

或许我们真的需要一个能抽象OpenGL的python lib, free your mind的图像玩具, 就像Processing那样.

最后, 这样一个core code的确可以更好的优化一下, 比如把着色的顶点坐标都写进去. 不过剩下的已经基本是体力活了, 作为一个prototype, 要继续它最好是换一种语言(用Flex或者Processing, 至少作为劳动成果可以得到一个swf或者applet放在网上展示)

OK, 总算搞定一件一直都想做的事情.
comments: 2  
by kernel1983

Spotlight crash and lxml install on leopard

Leopard在我欢天喜地的更新到了10.5.2以后, SPOTLIGHT Crash whenever I type...

Dam!

在网上找找解决方案, 只有一个家伙和我一样倒霉. 尝试他的方法, 删掉了spotlight的index文件, 重新索引, 无效.

找Crash Dump, 找到了Crash的线程
Thread 3 Crashed:
0   libxml2.2.dylib               	0x02e424fc xmlXPathCacheNewString + 44
1   libxml2.2.dylib               	0x02e4e3f2 xmlXPathCompPathExpr + 2546
2   libxml2.2.dylib               	0x02e4ebb5 xmlXPathCompUnaryExpr + 213
3   libxml2.2.dylib               	0x02e4edbf xmlXPathCompMultiplicativeExpr + 15
4   libxml2.2.dylib               	0x02e4efaf xmlXPathCompAdditiveExpr + 15
5   libxml2.2.dylib               	0x02e4f0ff xmlXPathCompRelationalExpr + 15
6   libxml2.2.dylib               	0x02e4f36b xmlXPathCompEqualityExpr + 203
7   libxml2.2.dylib               	0x02e4f40f xmlXPathCompAndExpr + 15
8   libxml2.2.dylib               	0x02e4f582 xmlXPathCompileExpr + 18
9   libxml2.2.dylib               	0x02e5464a xmlXPathCtxtCompile + 90
10  libxslt.1.dylib               	0x03c5f6e9 xsltXPathCompile + 76
11  libxslt.1.dylib               	0x03c6f939 xsltStylePreCompute + 1530
12  libxslt.1.dylib               	0x03c5b223 xsltParseTemplateContent + 2542
13  libxslt.1.dylib               	0x03c5b51e xsltParseStylesheetProcess + 105
14  libxslt.1.dylib               	0x03c5c78e xsltParseStylesheetImportedDoc + 493
15  libxslt.1.dylib               	0x03c5c7fc xsltParseStylesheetDoc + 26
16  com.apple.DictionaryServices  	0x007d4305 PredefinedXSLTDoc(DCSTransformStyle) + 267
17  com.apple.DictionaryServices  	0x007d4396 CopyTransformedTextFromXML + 110
18  com.apple.DictionaryServices  	0x007d155d DCSRecord::copyData(DCSTransformStyle) + 137
19  com.apple.DictionaryServices  	0x007d3393 DCSCopyTextDefinition + 417
20  com.apple.spotlight           	0x0002b916 0x1000 + 174358
21  com.apple.Foundation          	0x00471b34 -[NSOperation start] + 772
22  com.apple.Foundation          	0x00471822 __runop + 34
23  libSystem.B.dylib             	0x90ecd743 _pthread_wqthread + 331
24  libSystem.B.dylib             	0x90ecd5f6 start_wqthread + 30

难道是自作孽, stupid!

还记得我曾经在blog里面教大家怎么安装python lxml lib吗? 把链接改回来, 也就是libxml2的版本换回2.6.16, spotlight comes back.


但是lxml.etree还是彻底不能用了. 看来不能这样安装, 找一些更加安全的方法. 我可是spotlight的重度依赖者

另外, 还有一条信息, libxslt和libxml2据说要配套的用, 为了安全起见, 在/usr/local/下面安装最新的libxslt

重新安装lxml, 用下面的命令
python setup.py build_ext
    --with-xml2-config=/usr/local/bin/xml2-config
    --with-xslt-config=/usr/local/bin/xslt-config
python setup.py build
python setup.py install

这回应该是完美解决方案了
python
>>> from lxml import etree

终于没有报错, 安装成功

上面的命令可是我读lxml的setupinfo.py源码得出的, 果然源代码面前没有秘密

最后, 清理一下/usr/lib下面无用的文件, 收工!
comments: 0  
by kernel1983

PyDev on Flex Builder OS X

尝试在OS X的Flex Builder 3上安装PyDev

Flex Builder 3是一个构建在eclipse上的工具, 因为是Flex专用所以连JDT都没有带上. 不过本质上它还是一个eclipse.

安装PyDev过程中没有出现什么问题, 倒是配置python interpreter的时候出现了莫名其妙的错误.

原因是这样的, 由于eclipse安装的目录是在/Applications/Adobe Flex Builder 3/目录下的, 目录中有空格. 所以,在配置python interpreter的时候出现失败的提示. 解决方法很简单, 暂时把/Applications/Adobe Flex Builder 3/目录名字改为/Applications/eclipse/或者任何没有空格的名字, 问题就解决了.

配置完成以后, 还可以改回去.
comments: 0  
by kernel1983
1234567...17