若看不到內容,請稍待幾秒
若看不到內容,請稍待幾秒
這裡是Jimmy的實驗室用來發表Jimmy的Scratch程式作品,還有LEGO WEDO & NXT機器人設計 & Android, (本部落格引用圖文為教育教學目的合理使用) 想與我(Jimmy的爸爸 )聯絡 jimmyscratchlab@gmail.com
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
nil
指定畫布 畫布壹 畫布壹 0 0 150 150 實心方 畫布壹 保存畫布狀態 畫布壹 字" #0090F0" 填色調 畫布壹 15 15 120 120 實心方 畫布壹 保存畫布狀態 畫布壹 字" #F0F0F0" 填色調 畫布壹 0.5 透明 畫布壹 30 30 90 90 實心方 畫布壹 回復畫布狀態 畫布壹 45 45 60 60 實心方 畫布壹 回復畫布狀態 畫布壹 60 60 30 30 實心方
nil
指定畫布 畫布貳 : 繪製螺旋 { 大半徑 小半徑 圓心 } 畫布貳 開始構圖 畫布貳 大半徑 圓心 減 0 移筆 2000 1 做 區域變數 x2 區域變數 y2 畫布貳 大半徑 小半徑 加 i 180度 72 除 乘 餘弦 乘 小半徑 圓心 加 大半徑 小半徑 加 小半徑 除 i 180度 72 除 乘 乘 餘弦 乘 減 給 x2 x2 大半徑 小半徑 加 i 180度 72 除 乘 正弦 乘 小半徑 圓心 加 大半徑 小半徑 加 小半徑 除 i 180度 72 除 乘 乘 正弦 乘 減 給 y2 y2 拉線 x2 大半徑 圓心 減 不等於 y2 0 不等於 且 否定 若真 跳出循環 然後 循環 畫布貳 下筆 ; : 畫九個螺旋 畫布貳 0 0 300 300 實心方 3 0 做 3 0 做 畫布貳 保存畫布狀態 畫布貳 字" #9CFF00" 筆色調 畫布貳 50 i 100 乘 加 50 j 100 乘 加 移動原點 20 i 2 加 i 1 加 除 乘 ( 參數 大半徑 ) -8 j 3 加 j 1 加 除 乘 ( 參數 小半徑 ) 10 ( 參數 圓心 ) 繪製螺旋 畫布貳 回復畫布狀態 循環 循環 ; 畫九個螺旋
nil
指定畫布 畫布叁 畫布叁 75 75 移動原點 : 旋轉範例 6 1 做 畫布叁 保存畫布狀態 畫布叁 51 i 乘 255 51 i 乘 減 255 紅綠藍轉十六進制 填色調 i 6 乘 0 做 畫布叁 360度 j 6 乘 除 旋轉 畫布叁 開始構圖 畫布叁 0 j 12.5 乘 5 0 360度 反時鐘 弧 畫布叁 填圖 循環 畫布壹 回復畫布狀態 循環 ; 旋轉範例
nil
nil
nil
nil
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
nil
nil
nil
nil
nil
nil
nil
nil
nil
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
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();
}
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 ;
<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
<script type="text/forth">
: c c" pi = 3.14" >tag h1 >tag div >tagid div1 ; c
</script>
<div id='div1'></div>
<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>
<script type="text/forth">
c" ./forth/testcase.f" include
</script>
<p class="forth" forthcode=" x "> </p>
nil
<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
<p class="forth" forthcode=" : fib1 1 1 begin over . swap over + dup 10000 > until 2drop ; fib1">nil</p>
nil
<p class="forth" forthcode=" fib2 ">nil</p>
nil
<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
<p class="forth" forthcode=" .( *** ) version . .( *** ) ">nil</p>
nil
<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 |
9*9:
nil
fib 1:
nil
fib 2:
nil
寄件者 scratchlab02 |
<xml xmlns="http://www.w3.org/1999/xhtml"><block type="text_cquote" notchtype="LEFT_RIGHT" inline="false" x="1121" y="1274"><title name="STRING">./forth/testcase.f</title><value name="NEXTWORD"><block type="utility_include" notchtype="LEFT_RIGHT" inline="false"></block></value></block><block type="text_backslash" notchtype="LEFT_RIGHT" inline="false" x="1118" y="1316"><title name="STRING">Jimmyscratchlab 附註 執行測試案例</title></block></xml>
目前testcase.f的檔案內容
\ 試印出 99 乘法表
: x 9 for cr r@ 9 for dup r@ * 2 .r space next drop next ; x
var file=File(path) //insecure exception
但會產生insecure例外
var xmlhttp,fname;
if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();
if (xmlhttp == null) alert("Your browser does not support XMLHTTP.");
/*異步時,在open與send之前用這段程式碼*/
//xmlhttp.onreadystatechange = function() {
// if (xmlhttp.readyState==4) {
// alert(xmlhttp.responseText);}}
xmlhttp.open("GET", fname, false);//false為同步,true為異步
xmlhttp.send(null);
/*同步時,在open與send之後用這段程式碼*/
if (xmlhttp.status == 200 || xmlhttp.status == 0) { //0為本機開檔
alert('xmlhttp.status '+xmlhttp.status);
alert(xmlhttp.responseText);
}else{
alert(xmlhttp.statusText);}
<script type="text/ruby">
#class Foo; def initialize; @foo = 'whee'; end; end; f = Foo.new; f
Time.now
</script>
<script src="/processing.js"></script>
<canvas datasrc="blendColor.pjs" width="200" height="200"></canvas>
<script type="text/forth">
/ 試印出 99 乘法表
: x 9 for cr r@ 9 for dup r@ * 2 .r space next drop next ; x
</script>
或是
<script type="text/forth" src="/9x9.f"></script>
不過想歸想,實作時或許會遇到很多有趣的挑戰吧!!
【 世尊說:我見、人見、眾生見、壽者見, “Because (when) the Tathagata speaks of the view of an ego, a Personality, a being and a life, 即非我見、人見、眾生見、壽者見,是名我見、人見、眾生見、壽者見 “it is not really, (but) is (expediently) called the view of an ego, a personality a being and a life.” 】。雖然不甚了解此段經文的意義,反正是經典,小朋友有唸有保佑(BoBee)啦!!
Forth說 I,J,K 即非 I,J,K 是名 I,J,K寫慣一般程式語言的人,或許看了書上的Forth程式碼會主觀認定I是最內迴圈索引,J是外迴圈索引,K是外外迴圈索引
寄件者 scratchlab02 |
寄件者 scratchlab02 |
<xml xmlns="http://www.w3.org/1999/xhtml"><block type="processing_Setup" notchtype="LEFT_RIGHT" inline="false" x="54" y="20"><value name="NEXTWORD"><block type="variable_value" notchtype="LEFT_RIGHT" inline="false"><title name="NAME">psjObj</title><value name="NEXTWORD"><block type="procedures_callnoreturn" notchtype="LEFT_RIGHT" inline="false"><mutation name="psjObj"></mutation><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">230</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">230</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">230</title><value name="NEXTWORD"><block type="processing_BackgroundByValues" notchtype="LEFT_RIGHT" inline="false"></block></value></block></value></block></value></block></value></block></value></block></value></block><block type="procedures_callnoreturn" notchtype="LEFT_RIGHT" inline="false" x="55" y="58"><mutation name="psjObj"></mutation><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">0</title><value name="NEXTWORD"><block type="processing_FillByGray" notchtype="LEFT_RIGHT" inline="false"></block></value></block></value></block><block type="compile_define_highword" notchtype="Top_Bottom_Right" inline="false" x="55" y="96"><title name="NAME">MyHighWord</title><statement name="STACK"><block type="math_PushNumber" notchtype="TOP_BOTTOM_RIGHT" inline="false"><title name="NUM">20</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">0</title></block></value><next><block type="control_DoLoop" notchtype="Top_Bottom_Right" inline="false"><statement name="STACK"><block type="control_i" notchtype="TOP_BOTTOM_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">2</title><value name="NEXTWORD"><block type="math_Mod" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_TwoSlash" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="comment" notchtype="LEFT_RIGHT" inline="false"><title name="COMMENT">為何用I不用J,這是Forth有趣的特性,因為此時間點Return Stack只存在一個迴圈體</title></block></value></block></value></block></value></block></value><next><block type="math_PushNumber" notchtype="TOP_BOTTOM_RIGHT" inline="false"><title name="NUM">25</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">0</title></block></value><next><block type="control_DoLoop" notchtype="Top_Bottom_Right" inline="false"><statement name="STACK"><block type="stack_dup" notchtype="TOP_BOTTOM"><next><block type="procedures_callnoreturn" notchtype="TOP_BOTTOM_RIGHT" inline="false"><mutation name="psjObj"></mutation><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">25</title><value name="NEXTWORD"><block type="control_j" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_Multi" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="stack_rot" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="control_i" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_Add" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">20</title><value name="NEXTWORD"><block type="math_Multi" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">20</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">8</title><value name="NEXTWORD"><block type="processing_DrawRect" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="comment" notchtype="LEFT_RIGHT" inline="false"><title name="COMMENT">此I非彼I</title></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></next></block></statement><next><block type="stack_drop" notchtype="TOP_BOTTOM"></block></next></block></next></block></next></block></statement></block></next></block></statement></block><block type="procedures_callnoreturn" notchtype="LEFT_RIGHT" inline="false" x="58" y="431"><mutation name="MyHighWord"></mutation><value name="NEXTWORD"><block type="comment" notchtype="LEFT_RIGHT" inline="false"><title name="COMMENT">JimmyScratchLab Demo</title></block></value></block></xml>
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
: 3dup dup dup dup ;
: 4dup dup dup dup dup ;
: 5dup dup dup dup dup dup ;
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |
寄件者 scratchlab02 |