Due: 9pm, Tuesday, 03/19
"function setup()" 在網頁 load 進來的一開始執行一次,用來設定頁面的背景、一些元素的初始值等
"function draw()" 之後 1/60 每秒執行一次 (頻率可調),你可以把一些動畫的邏輯設計在這裡
一些內建的 event listeners, 像是 keyPressed(), mouseDragged()… 等,讓你可以直接把 event 對應的動作寫在這邊
完整的 reference: https://p5js.org/reference/
Online editor: https://editor.p5js.org/
畫一個三角形:triangle(x1, y1, x2, y2, x3, y3)
Constant horizontal move: x += vx;
自由落體: vy += ay, y += vy;
學鳥飛:When key/mouse is pressed, vy = -upY;
下載 p5-practice.tgz, 解壓縮後打開 index.html 看看!
把前面練習的 code copy 過來~
讓它旋轉:rotate(radian)
translate(x, y): 把原點移至 (x, y)
The push() function saves the current drawing style settings and transformations, while pop() restores these settings.
let bgImg = loadImage("assets/sprites/background-day.png");
let baseImg = loadImage("assets/sprites/base.png");
image(bgImg, x, y);
image(baseImg, x, y);
基於安全性考量,程式碼所發出的跨來源 HTTP 請求會受到限制,因此,如 XMLHttpRequest 及 Fetch 都必須要遵守同源政策(same-origin policy)。
當網頁 (i.e. HTTP protocol) 試著存取電腦中的檔案 (i.e. FILE protocol) 時,會被視為是「跨來源」需求,而必須要有一個支援 CORS 的伺服器服務才行
./run.sh // 開啟 server, default port: 80
打開瀏覽器 (為了避免開發時錯誤留下後遺症,建議開無痕),鍵入 "localhost"
(hint) 圖太小/太大?
// Do this in preload()
var soundObj = loadSound(url);
// Do this on the event!
soundObj.play();
亂數產生高度
跟背景一起橫向移動
Game over
Restart game
Any of YOUR IDEAS are very welcome!