This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 從 Brython 程式庫中的 browser 模組導入 document 類別, 並以簡寫設定為 doc | |
from browser import document as doc | |
# 從 browser 模組導入 html 類別, 主要用於建立 CANVAS 標註物件, 並插入頁面中 | |
# 用於定時執行特定函式 | |
import browser.timer | |
# 使用者可以透過 window 當作介面使用其他 Javascript 功能 | |
from browser import html, window | |
import random | |
canvas = html.CANVAS(width = 750, height = 750) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>W11</h2> | |
<h4>Examples</h4> | |
<p><a href="/downloads/w11_notes.txt">w11_notes.txt</a></p> | |
<p><a href="/downloads/w11_1b_p261.txt">w11_1b_p261.txt</a></p> | |
<p>以下為 <a href="https://mde.tw/cp2021_hw/content/W11.html">https://mde.tw/cp2021_hw/content/W11.html</a> 按鈕範例.</p> | |
<p>這個頁面 demo 如何在同一頁面下納入多個線上 Ace 編輯器與執行按鈕. (本動態頁面檔案 <a href="/downloads/Examples.txt">Examples.txt</a>)</p> | |
<p>1. 從 1 累加到 100 (以下列 button 呈現).</p> | |
<p>2. 教科書 (<a href="https://link.springer.com/book/10.1007/978-981-10-3277-6">Programming with Python</a>) 2.6 Exercises, 共有三個題目, 請分別將程式製作為按鈕 (button).</p> | |
<p>3. 請利用 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API">Canvas</a> 繪製 Fig. 3.7 的流程圖 (Flow Chart).</p> | |
<p>4. 請利用 Canvas 繪製你所編寫"從 1 累加到 10"程式的流程圖 (Flow Chart).</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 從 browser 導入 document 並設為 doc | |
from browser import document as doc | |
# 使用者可以透過 window 當作介面使用其他 Javascript 功能 | |
from browser import html, window | |
# 用於定時執行特定函式 | |
import browser.timer | |
# 導入數學模組 | |
import math | |
# 導入亂數模組 | |
from random import random, randint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 這個程式用於 demo 以 canvas 畫線以及寫字 | |
# 從 Brython 程式庫中的 browser 模組導入 document 類別, 並以簡寫設定為 doc | |
from browser import document as doc | |
# 從 browser 模組導入 html 類別, 主要用於建立 CANVAS 標註物件, 並插入頁面中 | |
from browser import html | |
import browser.timer | |
import random | |
# 利用 html 建立一個 CANVAS 標註物件, 與變數 canvas 對應 | |
canvas = html.CANVAS(width = 750, height = 750) | |
# 將 canvas 標註的 id 設為 "canvas" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 這個程式用於 demo 以 canvas 畫線以及寫字 | |
# 從 Brython 程式庫中的 browser 模組導入 document 類別, 並以簡寫設定為 doc | |
from browser import document as doc | |
# 從 browser 模組導入 html 類別, 主要用於建立 CANVAS 標註物件, 並插入頁面中 | |
from browser import html | |
# 利用 html 建立一個 CANVAS 標註物件, 與變數 canvas 對應 | |
canvas = html.CANVAS(width = 750, height = 750) | |
# 將 canvas 標註的 id 設為 "canvas" | |
canvas.id = "canvas" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 從 browser 導入 document 並設為 doc | |
from browser import document as doc | |
# 使用者可以透過 window 當作介面使用其他 Javascript 功能 | |
from browser import html, window | |
# 用於定時執行特定函式 | |
import browser.timer | |
# 導入數學模組 | |
import math | |
# 導入亂數模組 | |
from random import random, randint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 從 browser 導入 document 並設為 doc | |
from browser import document as doc | |
# 使用者可以透過 window 當作介面使用其他 Javascript 功能 | |
from browser import html, window | |
# 用於定時執行特定函式 | |
import browser.timer | |
# 導入數學模組 | |
import math | |
# 導入亂數模組 | |
from random import random, randint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 導入 brython 程式庫 --> | |
<script src="/static/brython.js"></script> | |
<script src="/static/brython_stdlib.js"></script> | |
<!-- 啟動 Brython --> | |
<script>// <![CDATA[ | |
window.onload=function(){ | |
brython({debug:1, pythonpath:['/static/','./../downloads/py/']}); | |
} | |
// ]]></script> | |
<p><!-- 導入 FileSaver 與 filereader --></p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
n=10 | |
for i in range(1,n+1): | |
r=random.randint(1,18) | |
t=random.randint(1,18) | |
print("第"+str(i)+"個紅色方塊座標為("+str(r)+","+str(t)+")") |