int [][] Bor= { //ประกาศ+กำหนด array ชนิด integer
{
0, 0, 0, 0, 1, 1, 1, 1
}
, {
1, 1, 1, 1, 0, 0, 0, 0
}
, {
1, 0, 1, 0, 0, 1, 1, 1
}
, {
0, 1, 0, 0, 0, 0, 1, 0
}
, {
1, 0, 1, 0, 0, 1, 1, 1
}
, {
1, 1, 1, 1, 0, 0, 0, 1
}
, {
0, 0, 0, 0, 1, 1, 1, 0
}
, {
1, 1, 1, 1, 0, 0, 0, 1
}
};
void setup() {
size(400, 400);
background(#0F6F21);
drawtable(); //เรียกใช้ ฟังก์ชั่นที่วาดตาราง drawtable()
drawBody(); //เรียกใช้ฟังชั่นที่วาดลูกหมาก drawBody()
}
void drawtable() {
int a = 0;
float hightX = 0;
float x = width/8;
float highY = 0;
float y = height/8;
stroke (#11481B);
strokeWeight(3);
while (a < 9) {
line(hightX+x, 0, hightX+x, height);
line(0, highY+y, width, highY+y);
hightX = hightX+x;
highY =highY+y;
a = a+1;
}
}
void drawBody() {
int i ;
int j ;
float b = width/16;
float q = width/8;
float c = height/16;
float e = height/8;
for (i=0;i < Bor.length;i++) { // ใช้ for loop ในการวนลูป โดย มีการทำงาน คือ for(กำหนดค่าเริ่มต้นของตัวแปล;เงื่อนไขที่วนลูป;เพิ่มค่าตัวแปลที่กำหนดเมื่อครบรอบ)
for (j=0;j < Bor[i].length;j++) {
if (Bor[i][j] == 1) { //เงื่อนไขที่ใช้ในการวาด ลูกหมาก คือ ถ้า array ที่เก็บค่า มีค่าที่เก็บใน อินเด็ซ เท่ากับ 1 ให้ทำ ตาม statement
noStroke();
fill(255);
ellipse(b, c, width/10, width/10);
}
if (Bor[i][j] == 0) { //เงื่อนไขที่ใช้ในการวาด ลูกหมาก คือ ถ้า array ที่เก็บค่า มีค่าที่เก็บใน อินเด็ซ เท่ากับ 0 ให้ทำ ตาม statement
noStroke();
fill(0);
ellipse(b, c, width/10, width/10);
}
b = b+q;
}
b = width/16;
c = c+e;
j = 0;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น