Skip to content

Instantly share code, notes, and snippets.

@ayugioh2003
Last active October 29, 2016 13:44
Show Gist options
  • Save ayugioh2003/481f5975747ceaf6f72e09a2a6ad02ef to your computer and use it in GitHub Desktop.
Save ayugioh2003/481f5975747ceaf6f72e09a2a6ad02ef to your computer and use it in GitHub Desktop.
color c1 = color(255, 0, 0); // 宣告顏色
color c2 = color(0, 127, 0);
color c3 = color(0, 0, 255);
color c4 = color(255, 255, 0);
color c5 = color(255, 0, 255);
color c7 = color(255); // 橡皮擦顏色
color c_pen = c1; // 宣告畫筆顏色初始值
int w = 5; // 筆畫粗細
void setup() {
size(800, 600);
background(255);
smooth();
}
void draw() {
// 繪圖工具版
noStroke();
fill(c7);
rect(0, 0, 60, 600);
// 繪圖工具版上的顏色
fill(c1);
rect(0, 0, 60, 60);
fill(c2);
rect(0, 60, 60, 60);
fill(c3);
rect(0, 120, 60, 60);
fill(c4);
rect(0, 180, 60, 60);
fill(c5);
rect(0, 240, 60, 60);
// 橡皮擦
fill(c7);
rect(0, 540, 60, 60);
// 繪圖工具板的筆刷區
fill(255);
fill(0);
strokeWeight(1);
stroke(0);
line(0, 360, 60, 360);
line(0, 420, 60, 420);
line(0, 480, 60, 480);
line(0, 540, 60, 540);
line(60, 0, 60, 600);
// 繪圖工具板的功能區
text("Clear", 15, 335);
text("Save", 16, 515);
text("Eraser", 13, 575);
// 筆刷
fill(c_pen);
ellipse(30, 390, 5, 5);
ellipse(30, 450, 10, 10);
// 繪圖區
if ((mousePressed == true) && (mouseX & gt; 60)) { // 如果滑鼠在繪圖區壓下去
if (mouseButton == LEFT) { // 按的是左鍵
stroke(c_pen); // 畫筆顏色初始值
strokeWeight(w);
line(pmouseX, pmouseY, mouseX, mouseY); // 畫線 (前一個滑鼠 X 座標, 前一個滑鼠 Y 座標, 連到 現在的滑鼠 X 座標, 滑鼠 Y 座標)
} else { // 簡便橡皮擦
noStroke();
fill(255);
ellipse(mouseX, mouseY, 30, 30);
}
}
// 選擇顏色
if ((mousePressed == true) && (mouseX & lt; = 60) && (mouseY & lt; = 300)) { // 如果畫筆點到繪圖工具版的顏色
c_pen = get(mouseX, mouseY); // 顏色變成點到位置的顏色
} else if ((mousePressed == true) && (mouseX & lt; = 60) && (mouseY & gt; = 540) && (mouseY & lt; = 600)) { //Eraser
c_pen = c7;
} else if ((mousePressed == true) && (mouseX & lt; = 60) && (mouseY & gt; = 300) && (mouseY & lt; = 360)) { //Clear
background(255);
}
// 更換筆刷大小
if ((mousePressed == true) && (mouseX & lt; = 60) && (mouseY & gt; = 360) && (mouseY & lt; = 420)) { // 如果畫筆點到繪圖工具版的筆刷區
w = 5; // 筆刷大小改變
} else if ((mousePressed == true) && (mouseX & lt; = 60) && (mouseY & gt; = 420) && (mouseY & lt; = 480)) {
w = 10; // 筆刷大小改變
}
// 儲存圖 Save
if ((mousePressed == true) && (mouseX & lt; = 60) && (mouseY & gt; = 480) && (mouseY & lt; = 540)) {
stroke(255);
fill(255);
rect(0, 0, 60, 600); // 矩形 (起始 X 座標, 起始 Y 座標, 拉到 X 座標, 拉到 Y 座標)// 把旁邊繪圖工具區蓋成白色
save("frame.png"); // 儲存畫面
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment