2017 01 06 - s40523107/2016fallcp_hw GitHub Wiki

#單線旋轉動畫

<!-- 導入 Brython 標準程式庫 -->
<script type="text/javascript" src="https://cdn.rawgit.com/brython-dev/brython/master/www/src/brython_dist.js">
</script>
 
<!-- 啟動 Brython -->
<script>
window.onload=function(){
brython(1);
}
</script>
 
<!-- 以下可以執行  Brython 程式 -->
<canvas id="onebar" width="400" height="400"></canvas>
<script type="text/python3">
from browser import document
from browser import window
from browser import timer
import math
canvas = document["onebar"]
ctx = canvas.getContext("2d")
 
# 畫圓函式
def circle(x,y,r):
    ctx.beginPath()
    ctx.arc(x, y, r, 0, math.pi*2, True)
    ctx.fill()
    ctx.closePath()
 
# 以下可以利用 ctx 物件進行畫圖
# 先畫一條直線
ctx.beginPath()
# 設定線的寬度為 1 個單位
ctx.lineWidth = 1
# 將畫筆移動到 (200, 200) 座標點
ctx.moveTo(200, 200)
# 然後畫直線到 (200, 300) 座標點
ctx.lineTo(200, 300)
# 設定顏色為藍色, 也可以使用 "rgb(0, 0, 255)" 字串設定顏色值
ctx.strokeStyle = "blue"
# 實際執行畫線
ctx.stroke()
ctx.closePath()
 
circle(200, 200, 5)
</script>
⚠️ **GitHub.com Fallback** ⚠️