第 2 章 【 基礎繪製與色彩 】程式框架 - p5.js 開發入門
Date:2022/11/30
使用 open processing 平台
初始設定 setup()
不斷繪製 draw()
把想畫的程式碼放在這段中,放置在 draw 中的程式碼都會不斷的繪製疊加上去
畫布設定
createCanvas(寬, 高);
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
設定畫布 寬 高基本圖案
填色
fill(顏色數值)
背景色
background(顏色數值);
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
顏色類別:
- 單一數值 (100)
- RGB 數值 (255,200,0)
- 數值, 透明度 (100, 20)
- 色碼 ("#FFD48E"),要用引號包住
補充:
background() 可以放在 setup() 或是 draw() 區域中
放在 setup()
成為最一開始的畫布底色
放在 draw()
單一顏色
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
不會有滑鼠軌跡顏色,設定透明度
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
有滑鼠軌跡,但是有被透明背景覆蓋(變黯淡)變動數值
滑鼠左側和上面距離
要讓圖案某數值隨著滑鼠位置變化,使用 mouseX、mouseY
例如:讓橢圓的位置跟著滑鼠變動
frameCount 幀數
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
執行後總共畫了幾次
用 print() 來看目前frameCount 次數框線
stroke(顏色數值)
strokeWeight(框線粗度)
偵測滑鼠行為
滑鼠有無被點按
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
mouseIsPressed實際應用範例
cheatSheet
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
快捷鍵
Mac:將 ctrl 代換成 ⌘ cmd 即可
功能 |
快捷鍵 |
關鍵字搜尋 |
Ctrl + F |
多重選取關鍵字 |
Ctrl + D |
往左 or 右移動一個單字 |
Alt + 左右 |
往左 or 右刪除一個單字 |
Alt + Delete / Backspace |
移動到句首 or 句尾 |
Ctrl + 左右 |
往左 or 右刪除一整行 |
Ctrl + Delete / Backspace |
增加 / 減少縮排 |
Tab / Shift + Tab |
執行 Code |
Ctrl + enter |
VS Code plugin 擴充套件