2019年2月26日 星期二

程式

# flag02
# 畫中德國國旗
# 導入 doc
from browser import document as doc
from browser import html
import math
canvas = html.CANVAS(width = 300, height = 200)
canvas.style = {"width": "100%"}
canvas.id = "taiwan_flag"
brython_div = doc["brython_div"]
brython_div <= canvas

# 準備繪圖畫布
canvas = doc["flag02"]
ctx = canvas.getContext("2d")
# 進行座標轉換, x 軸不變, y 軸反向且移動 canvas.height 單位光點
# ctx.setTransform(1, 0, 0, -1, 0, canvas.height)
# 以下採用 canvas 原始座標繪圖
flag_w = canvas.width
flag_h = canvas.height
circle_x = flag_w/4
circle_y = flag_h/4
# 先畫滿地紅
ctx.fillStyle='rgb(255, 0, 0)'
ctx.fillRect(0,0,flag_w,flag_h)
# 先畫滿地黑
ctx.fillStyle='rgb(0, 0, 0)'
ctx.fillRect(0,0,flag_w,flag_h/3)
# 先畫滿地黃
ctx.fillStyle='rgb(255, 255, 0)'
ctx.fillRect(0,135,flag_w,flag_h/3)

沒有留言:

張貼留言

程式

# flag02 # 畫中德國國旗 # 導入 doc from browser import document as doc from browser import html import math canvas = html.CANVAS(width = 300, heigh...