2012年11月29日 星期四

Web Audio API 簡單範例

這是Jimmy's papa整理出來的Web Audio API 簡單範例,可發出特定頻率的正弦聲波,
僅適用Chrome
        var context = new webkitAudioContext();
        var sampleRate = context.sampleRate;
        var node = context.createJavaScriptNode(128, 1, 1);
        var amplitude=0.8,frequency=300,currentSoundSample=0;

        node.onaudioprocess = function(e) { 
              var right = e.outputBuffer.getChannelData(0),
                  left = e.outputBuffer.getChannelData(1);

            var k = 2* Math.PI * frequency / sampleRate;
              for (var i = 0; i < right.length; ++i) {
                right[i] = left[i] = amplitude * Math.sin(k * currentSoundSample++);} 
            };

        function play() {
            frequency = parseFloat(document.getElementById("freq").value);
            currentSoundSample=0;
            node.connect(context.destination);
        }

        function pause() {
              node.disconnect();
        }

Jimmy的樂高積木修行--虎之卷95頁--手動搖搖窗

手動搖搖窗,很適合用在城堡的巨大鐵窗,開窗時只要輕輕鬆鬆搖幾下就好
寄件者 scratchlab02
寄件者 scratchlab02
寄件者 scratchlab02

2012年11月21日 星期三

[ Forth.js ] OOP

下為實驗中的Forth.js OOP指令用法,
或是到此下載(forthjstest1.zip )測試檔
class Vehicle weight  power  travelon   end_class
instance Vehicle MyBike
20 to MyBike.weight
new MyCar
2000 MyCar price 
MyCar.price 
1000 +to MyCar.price
: move bra bra bra ;
assign  move MyCar.move 
:method MyCar.stop  bra bra bra ;


以下測試案例,運用see指令,透視每個新建類別(class),物件(object),屬性(attribute)及方法(method)的內部

Example: OOP

<p class="forth" forthcode=' .( (Test1 define class ) ) class Vehicle weight power travelon  end_class see Vehicle '>nil</p>

(Test1 define class )
Scanning Vehicle
(000113) doInstanceAllAttr
(000114) weight
(000115) power
(000116) travelon
(000117) exit

<p class="forth" forthcode=' .( (Test2 class instance ) )  instance Vehicle MyBike see MyBike see MyBike.weight 20 to MyBike.weight see MyBike.weight'>nil</p>

(Test2 class instance )
Scanning MyBike
(000118) doAttr
(000119) MyBike
(000120) exit
Scanning MyBike.weight
(000121) doValue
(000122) 0
(000123) exit
Scanning MyBike.weight
(000121) doValue
(000122) 20
(000123) exit

<p class="forth" forthcode=' .( (Test3 new object) ) new MyCar see MyCar 2000 MyCar price see MyCar.price cr MyCar.price . 1000 to MyCar.price MyCar.price . '>nil</p>

(Test3 new object)
Scanning MyCar
(000130) doAttr
(000131) MyCar
(000132) exit
Scanning MyCar.price
(000133) doValue
(000134) 2000
(000135) exit
2000 1000

<p class="forth" forthcode=' .( (Test4 object method) ) : move ." Just Moving!!!" ; see move assign move MyCar.move     see MyCar.move cr cr MyCar.move cr see MyCar'>nil</p>

(Test4 object method)
Scanning move
(000136) (.")
(000137) Just Moving!!!
(000138) exit
Scanning MyCar.move
(000136) (.")
(000137) Just Moving!!!
(000138) exit

Just Moving!!!

Scanning MyCar
(000130) doAttr
(000131) MyCar
(000132) exit

<p class="forth" forthcode=' .( (Test5 object method) ) :method MyCar.stop ." Just Stopping!!!" ; see MyCar.stop  cr cr  MyCar.stop  cr cr  see MyCar'>nil</p>

(Test5 object method)
Scanning MyCar.stop
(000139) (.")
(000140) Just Stopping!!!
(000141) exit

Just Stopping!!!


Scanning MyCar
(000130) doAttr
(000131) MyCar
(000132) exit

2012年11月15日 星期四

熱氣球在高雄夢時代升空了

上個週日很幸運,去逛展覽時聽到志工阿姨提到,夢時代那邊有熱氣球展,雖然已接近傍晚,眼看大大的紅太陽快貼近地平線,還是趕忙驅車至夢時代,想說至少讓Jimmy小朋友看一眼熱氣球也好

不過到了現場,才發現熱氣球才剛剛準備加熱升空,第一次看到熱氣球,尤其是加熱時噴出的巨大火焰的震撼感,讓Jimmy小朋友超興奮

Jimmy的樂高積木修行--虎之卷115頁--滑輪應用

寄件者 scratchlab02
寄件者 scratchlab02

2012年11月9日 星期五

[ Forth.js ] Version 1.0.1

Jimmy's papa在本機測試include指令沒問題,不過貼到部落格倒是怪怪的,可能與某些東西衝突到了,有空再除錯


JimmyScratchLab Forth.js(a fork of JeForth) Demo

Example: Append to TagId='div1':
    <script type="text/forth">
         : c c" pi = 3.14" >tag h1   >tag div >tagid div1 ;  c
    </script>
    <div id='div1'></div>



Example: Show Table
<script type="text/forth">
    : showtable     c" WORD" >tag th >tag tr c" Stack" >tag th >tagnode  >tagid table1
         c" .tag" >tag td >tag tr c" ( str <tagname> --  )" >tag td >tagnode  >tagid table1
         c" >tagid" >tag td >tag h1 >tag tr c" ( x|node <tagid> --  )" >tag td >tagnode  >tagid table1    
         c" >tag" >tag td >tag tr c" ( x|node <tag> -- node )" >tag td >tagnode  >tagid table1 
         c" >tagnode" >tag td >tag tr c" ( node x|childnode -- node )" >tag td >tagnode  >tagid table1
    ;   showtable 
    </script>
    <table id='table1' border="1"></table>



Example: include
    <script type="text/forth">
         c" ./forth/testcase.f" include
    </script>
    <p class="forth" forthcode=" x "> </p>

nil




Example: 9*9
<p class="forth" forthcode=": 9*9 9 for cr r@ 9 for dup r@ * 2 .r space next drop next ; 9*9">nil</p>

nil




Example: fib1
<p class="forth" forthcode=" : fib1 1 1 begin over . swap over + dup 10000 > until 2drop ; fib1">nil</p>

nil




Example: fib2
<p class="forth" forthcode=" fib2 ">nil</p>

nil




Example: abs
<p class="forth" forthcode='-16 abs -20 abs -12 abs -9 abs -3 abs -11 abs -8 abs .s c" abs ok!" .tag h1'>nil</p>

nil




Example: version
<p class="forth" forthcode=" .( *** ) version . .( *** ) ">nil</p>

nil

test

Jimmy的樂高積木修行--虎之卷148頁

最近Jimmy小朋友拿到了發條積木,虎之卷裡有幾頁與發條積木相關的作品都能做了
寄件者 scratchlab02
寄件者 scratchlab02
寄件者 scratchlab02

2012年11月3日 星期六

[ Forth.js ] Run Forth words code on your web page

Jimmy's papa搞定了可直接執行內嵌在網頁標籤上符式程式碼(Forth code),如下
    <script type="text/forth">
        : fib2 1 1 begin over . swap over + dup 20000 > until 2drop ;
    </script>
    <p>9*9:</p>
    <p class="forth" forthcode=": x 9 for cr r@ 9 for dup r@ * 2 .r space next drop next ; x">nil</p>
    <p>fib 1:</p>
    <p class="forth" forthcode=" : fib1 1 1 begin over . swap over + dup 10000 > until 2drop ; fib1">nil</p>
    <p>fib 2:</p>
    <p class="forth" forthcode=" fib2 ">nil</p>
如此一來會增加網頁程式設計師對Forth語言的興趣吧??? 哈哈....應該還有一段遙遠的路要走吧!!
寄件者 scratchlab02
如果你看到底下的內容與上圖相同,則執行成功!!!

JimmyScratchLab Forth.js(a fork of JeForth) Demo

9*9:

nil

fib 1:

nil

fib 2:

nil