void setup() { //ฟังก์ชั่นหลักที่ใช้ในการกำหนดค่า และเรียกใช้สิ่งต่างๆ เป็นฟังก์ชั่นที่ไม่มีการวกกลับ
size(350, 400); //ฟังก์ชั่นที่ใช้ในการกำหนดขนาดของพื้นที่ หรือ size(width, height)
}
Button a = new Button("Joe", 50, 50); //ปุ่ม a ที่ตำแหน่งแกน X 50 แกน Y 50 กดแล้วได้คำว่า joe
Button b = new Button("Is", 200, 50); //ปุ่ม b ที่ตำแหน่งแกน X 200 แกน Y 50 กดแล้วได้คำว่า is
Button c = new Button("My", 50, 165); //ปุ่ม c ที่ตำแหน่งแกน X 50 แกน Y 165 กดแล้วได้คำว่า my
Button d = new Button("Love", 200, 165); //ปุ่ม d ที่ตำแหน่งแกน X 200 แกน Y 165 กดแล้วได้คำว่า love
Button e = new Button("Love", 50, 275); //ปุ่ม e ที่ตำแหน่งแกน X 50 แกน Y 275 กดแล้วได้คำว่า love
Button f = new Button("U", 200, 275); //ปุ่ม f ที่ตำแหน่งแกน X 200 แกน Y 275 กดแล้วได้คำว่า u
void draw() { //ฟังก์ชั่นหลักที่ใช้ในการวาด
background(#F8F8FF); //ฟังก์ชั่นที่ใช้ในการเติมสีให้กับพื้นหลัง
a.display(); //เรียกใช้ปุ่ม a
b.display(); //เรียกใช้ปุ่ม b
c.display(); //เรียกใช้ปุ่ม c
d.display(); //เรียกใช้ปุ่ม d
e.display(); //เรียกใช้ปุ่ม e
f.display(); //เรียกใช้ปุ่ม f
}
class Button { //กำหนด class ชื่อ Button
String name; //ใช้ในการเก็บชื่อ
int x; //กำหนดตัวแปรชนิดจำนวนเต็ม ตัวนี้ใช้เก็บค่าในแกน X
int y; //เก็บค่าในแกน Y
int w; //เก็บความกว้าง
int l; //เก็บความสูง
int i; //เก็บตัวนับ Array
Button(String n, int x, int y) {
this.name = n;
this.x = x;
this.y = y;
this.w = 100;
this.l = 50;
this.i = 0;
}
void display() { //กำหนดฟังก์ชั่นสำหรับแสดงปุ่ม
fill(#FF9999); //ฟังก์ชั่นที่ใช้ในการเติมสีให้กับสิ่งต่างๆ สีชมพูอ่อน
stroke(#FF99FF); //ฟังก์ชั่นที่ใช้ในการเติมสีให้กับเส้น สีชมพูอมครีม
strokeWeight(7); //ฟังก์ชั่นที่ใช้ในการเพิ่มความหนาของเส้น
rect(this.x, this.y, this.w, this.l); //ฟังก์ชั่นที่ใช้ในการวาดรูปสี่เหลี่ยม หรือ rect(x, y, width, height)
this.click();
}
void click() { //กำหนดฟังก์ชั่นที่ใช้เรียกใช้การคลิก
if (mousePressed&&mouseX>x&&mouseX<x+w&&mouseY>y&&mouseY<y+l) {
fill(#000000); //เติมสีดำ
textSize(50); //ฟังก์ชั่นที่กำหนดขนาดของข้อความ
text(name, this.x, this.y+100); //ฟังก์ชั่นที่ใช้ในการสร้างข้อความ หรือ text(data, x, y)
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น