2018年8月26日 星期日

python 3 SWIG on windows 10

For python 3:

/* File : example.c */
 
 #include  <time.h>
 double My_variable = 3.0;
 
 int fact(int n) {
     if (n <= 1) return 1;
     else return n*fact(n-1);
 }
 
 int my_mod(int x, int y) {
     return (x%y);
 }
  
 char *get_time()
 {
     time_t ltime;
     time(&ltime);
     return ctime(&ltime);
 }

Interface file

 /* example.i */
 %module example
 %{
 /* Put header files here or function declarations like below */
 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();
 %}
 
 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();
 

Building a Python module

D:\temp\Documents\Python_call_C\example>swig -python -py3 example.i D:\temp\Documents\Python_call_C\example>gcc -c example.c example_wrap.c -I"D:\Program Files (x86)\Python36-32\include" D:\temp\Documents\Python_call_C\example>gcc -shared example.o example_wrap.o "D:\Program Files (x86)\Python36-32\python36.dll" "C:\Windows\System32\msvcr120.dll" -o _example.pyd
We can now use the Python module:
import example
print(example.fact(5))
print(example.my_mod(7,3))
print(example.get_time())
>>>>>>>>>>>>>>>>>>>>>>
Example Result:
120 1 Sun Aug 26 21:26:01 2018

2018年6月6日 星期三

2018年4月13日 星期五

用SeaMonkey製作WYSIWYG 網頁

1. Launch SeaMonkey
2. Click the third icon "設計師" from left bottom corner

==> Composer is web page editor 

2018年3月5日 星期一

Pygame超新手常中的陷阱

不曉得是Pygame本身的缺陷或bug,Pygame程式執行一段時間,必需要呼叫event一下,否則程式會變成沒有回應的情況,而程式畫面也會暫時停止更新。解決方法,就是確定程式沒互動時,get一下event,但也不是隨時都可以get event,因為當有event要處理時,例如按下滑鼠鍵,不適當處理event的話,可能造成沒處理event,例如可能造成吃鍵現像。一般,如果沒有multi-thread的話,可以在程式sleep前,get event以防止程式沒有回應。
例如,可以用以下delay(second),取代原本的time.sleep(second):

def delay(second):
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()           
    time.sleep(second)

2018年3月4日 星期日

Pyinstaller

If you want to hide the console window, here is the documentation: This is how you use the --noconsole option
python pyinstaller.py --noconsole yourscript.py
==> pyinstaller --noconsole main.py

Create a one-file bundled executable.
==> pyinstaller --noconsole -F main.py

2017年12月15日 星期五

Wettlauf nach El Dorado 競逐黃金國 完全空想 山寨計劃: 咸陽之路

這幾天玩了競逐黃金國,以下簡稱黃金國。裡面有三種資源,水手,刀和錢。覺得可以山寨成另一個時空背景的遊戲:項羽和劉邦爭霸的時候,曾經有一刻,是劉邦跟項羽比,看誰先到咸陽,最後因為項羽在跟秦國主力軍戰鬥,所以是劉邦先到咸陽作終,這山寨遊戲的三種資源,可以換成水軍,陸軍和錢,水軍就如同黃金國的水手,可以渡河。錢和原遊戲的錢,功能一樣。陸軍是原創的資源,捨棄了黃金國的刀,改用陸軍代替刀。黃金國中,擺放洞穴板塊的地點,在山寨遊戲中,可以放在村落上。而原本黃金國黑色,不能進入的區域,可以換成長城或關卡,一樣是不能進入。

2017年12月13日 星期三

AI的完全空想應用App

前幾年,Google宣佈餵給AI一堆有貓的影片,結果AI自動學會如何判別有貓的存在。我想到AI相關的應用,就是可以讀入結帳台附近的監視影片,然後由AI抓出誰沒有付錢,就偷走東西了,由於各個店家的裝飾不同,初期這種AI可能要訓練一下,才能Work。
未來相關的應用,也可以監視道路上,是否有人故意破壞公物或花草、樹木。目前看起來,我有生之年,應該能開發出相關的AI.

Lean 4 極簡教學 (Using VS Code on macOS)

 1. Install Lean Environment: https://lean-lang.org/install/ 試著完Step one, two, three 2. 在VS code下,建一新的project: 取名Hello_World 3. 嘗試執行Main.lea...