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
| # Cango 24v3 版本 Bezier 繪圖 | |
| from browser import window, html | |
| from browser import document as doc | |
| canvas = html.CANVAS(width = 600, height = 400) | |
| canvas.id = "canvas" | |
| brython_div = doc["brython_div"] | |
| brython_div <= canvas | |
| # Javascript 物件 | |
| cango = window.Cango.new | |
| path = window.Path.new |
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
| # based on https://mde.tw/cd2021/content/W14-W15.html | |
| # for acos, atan2 and sin | |
| import math | |
| import sys | |
| # radian to degree | |
| deg = 180/math.pi | |
| # link 1 length | |
| a1 = 10 | |
| # link 2 length |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Brython Snake</title> | |
| <!-- 導入 brython javascript 程式庫 --> | |
| <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.8.9/brython.min.js"> | |
| </script> |
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
| # clock1 in Brython - 這是單行註解 | |
| # 以下則是多行註解 | |
| '''Code for the clock''' | |
| # Line drawing | |
| # 導入 doc | |
| from browser import document as doc # 從模組 browser 導入 document 並且命名為 doc | |
| from browser import html # 導入 html | |
| import math # 導入數學模組 | |
| import time # 導入時間模組 | |
| import browser.timer # 導入用來製作 animation 動態模擬用的計時器 |
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
| pypyjs.exec( | |
| `for i in range(5): | |
| print("test");` | |
| ); |
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
| function reqListener () { | |
| document.getElementById("html").innerHTML = this.responseText; | |
| console.log(this.responseText); | |
| } | |
| var oReq = new XMLHttpRequest(); | |
| oReq.addEventListener("load", reqListener); | |
| oReq.open("GET", "https://mde.tw/wcmj2020/downloads/2020spring_wcmj_1a_list.txt"); | |
| oReq.send(); |
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
| void main() { | |
| for (int i = 0; i < 5; i++) { | |
| print('hello ${i + 1}'); | |
| print("hello ${i + 1}"); | |
| } | |
| } |
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
| // 因為要應用 html 表單以及 canvas 繪圖物件因此要導入 dart:html 程式庫 | |
| import 'dart:html'; | |
| // 因為需要用到三角函式以及 pi 來執行運算求點座標, 因此要導入 dart:math 程式庫 | |
| // 而對於初學者而言, 將所導入的數學程式庫, 特別又命名為 Math, 目的在讓使用者了解那些函式來自 math 程式庫 | |
| import 'dart:math' as Math; | |
| // 這裡將 canvas 與 ctx 變數設計為全域變數, 表示有效範圍擴及整個程式 | |
| // 在 Dart 程式中宣告完變數後, 直接賦予初始值, 也可以分兩段式賦值 | |
| // 但是若宣告與複製分兩段且位於同一 block 區段, 就會產生重複宣告變數的錯誤, 所以這裡採宣告後直接賦值 | |
| CanvasElement canvas = querySelector('#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
| // 因為要應用 html 表單以及 canvas 繪圖物件因此要導入 dart:html 程式庫 | |
| import 'dart:html'; | |
| // 因為需要用到三角函式以及 pi 來執行運算求點座標, 因此要導入 dart:math 程式庫 | |
| // 而對於初學者而言, 將所導入的數學程式庫, 特別又命名為 Math, 目的在讓使用者了解那些函式來自 math 程式庫 | |
| import 'dart:math' as Math; | |
| // 這裡將 canvas 與 ctx 變數設計為全域變數, 表示有效範圍擴及整個程式 | |
| // 在 Dart 程式中宣告完變數後, 直接賦予初始值, 也可以分兩段式賦值 | |
| // 但是若宣告與複製分兩段且位於同一 block 區段, 就會產生重複宣告變數的錯誤, 所以這裡採宣告後直接賦值 | |
| CanvasElement canvas = querySelector('#canvas'); |