ตัวอย่าง 4.1 การพิมพ์ตัวอักษรทีตำแหน่ง สี และ ขนาดแบบต่างๆ
void setup()
{
size(300, 300); // Display window Size x(Horizontal), Size y(Vertical)
background(204); // Background color
textSize(14); //ขนาด
text("word_1", 15, 30); //ข้อความและตำแหน่ง
textSize(20); //ขนาด
fill(0, 102, 153); //Color R G B
text("word_2", 15, 60); //ข้อความและตำแหน่ง
textSize(30); //ขนาด
fill(255, 0, 0, 120); //Color R G B และความทึบแสง
text("word_3", 15, 100); //ข้อความและตำแหน่ง
}
void draw()
{
}
--------------------------------------------------------------------------------------------------------------
ตัวอย่าง 4.2 พิมพ์คำว่า "WORD" เมื่อคลิกเมาส์ ที่ตำแหน่งเมาส์
void setup()
{
size(300, 300); // Display window Size x(Horizontal), Size y(Vertical)
background(204); // Background color
}
void draw()
{
textSize(30); //ขนาด
fill(255, 0, 0, 120); //Color R G B และความทึบแสง
}
void mouseClicked()
{
text("word", mouseX, mouseY); //ข้อความและตำแหน่ง
}
--------------------------------------------------------------------------------------------------------------
ตัวอย่าง 4.3 เมื่อคลิกเมาส์ พิมพ์คำว่า "X = " ตำแหน่ง x และ "Y = " ตำแหน่ง y
String s;
void setup()
{
size(300, 300); // Display window Size x(Horizontal), Size y(Vertical)
background(204); // Background color
}
void draw()
{
textSize(15); //ขนาด
fill(0, 0, 255); //Color R G B และความทึบแสง
}
void mouseClicked()
{
s = "X = " + str(mouseX) + " Y = " + str(mouseY);
text(s, mouseX, mouseY); //ข้อความและตำแหน่ง
}
--------------------------------------------------------------------------------------------------------------
อ้างอิง