float[][] Color = new float[8][8]; //สร้างตัวแปรอาเรย์ 2 มิติ ชนิดจำนวนเต็ม
และกำหนดจำนวนช่องของindex int[][] Xpos = new int[8][8]; void setup() { size(480, 480); background(0, 148, 22); int x = 30, i = 0, c=0; while (c<Xpos.length) { //เป็นลูปที่ใช้ในการรันอะเรย์ในมิติที่1 while (i<Xpos.length) { //เป็นลูปที่ใช้ในการรันอะเรย์ในมิติที่2
เมื่อออกจากลูปนี้ก็จะกลับไปวนลูปแรกใหม่
เป็นการเขียนแบบ ลูปซ้อนลูป Xpos[c][i] = x; //เป็นการเก็บค่าในพิกัดแกนxของแต่ละตัว Color[c][i] = random(0, 2); //เป็นการเก็บตัวเลขของแต่ละตัวซึ่งจะนำไปใช้แบ่งเป็นสีต่อไป x=x+60; i++; } x=30; c++; i=0; } } void draw() { drawTable(); //เรียกใช้ฟังก์ชันdrawTable() int j = 0, y = 30, c=0; while (j<Xpos.length) { while (c<Xpos.length) { drawCircle(Xpos[j][c], y,Color[j][c]); //เรียกใช้ฟังก์ชันdrawCircle()โดยมีการส่งค่าไป3ค่า c++; } j++; y=y+60; c=0; } } void drawTable() { int x=60; while (x<=420) { line(x, 0, x, 480); line(0, x, 480, x); x=x+60; } } void drawCircle(int X, int y,float Color) { //ใช้วาดตัวหมากโดยมีparameter X,y Color int x=30; if (Color<1) { //ใช้กำหนดสีของตัวหมาก fill(255); } else if (Color>1) { fill(0); } smooth(); noStroke(); ellipse(X, y, 45, 45); }
//อ้างอิงอธิบายเรื่องif-elseจาก lab3 http://com5630043.blogspot.com/search/label/lab3%20%3A%20Condition
และกำหนดจำนวนช่องของindex int[][] Xpos = new int[8][8]; void setup() { size(480, 480); background(0, 148, 22); int x = 30, i = 0, c=0; while (c<Xpos.length) { //เป็นลูปที่ใช้ในการรันอะเรย์ในมิติที่1 while (i<Xpos.length) { //เป็นลูปที่ใช้ในการรันอะเรย์ในมิติที่2
เมื่อออกจากลูปนี้ก็จะกลับไปวนลูปแรกใหม่
เป็นการเขียนแบบ ลูปซ้อนลูป Xpos[c][i] = x; //เป็นการเก็บค่าในพิกัดแกนxของแต่ละตัว Color[c][i] = random(0, 2); //เป็นการเก็บตัวเลขของแต่ละตัวซึ่งจะนำไปใช้แบ่งเป็นสีต่อไป x=x+60; i++; } x=30; c++; i=0; } } void draw() { drawTable(); //เรียกใช้ฟังก์ชันdrawTable() int j = 0, y = 30, c=0; while (j<Xpos.length) { while (c<Xpos.length) { drawCircle(Xpos[j][c], y,Color[j][c]); //เรียกใช้ฟังก์ชันdrawCircle()โดยมีการส่งค่าไป3ค่า c++; } j++; y=y+60; c=0; } } void drawTable() { int x=60; while (x<=420) { line(x, 0, x, 480); line(0, x, 480, x); x=x+60; } } void drawCircle(int X, int y,float Color) { //ใช้วาดตัวหมากโดยมีparameter X,y Color int x=30; if (Color<1) { //ใช้กำหนดสีของตัวหมาก fill(255); } else if (Color>1) { fill(0); } smooth(); noStroke(); ellipse(X, y, 45, 45); }
//อ้างอิงคำสั่งพื้นฐานต่างๆจาก lab1 http://com5630043.blogspot.com/search/label/lab1
//อ้างอิงอธิบายฟังก์ชันจาก lab2 http://com5630043.blogspot.com/search/label/lab2
//อ้างอิงอธิบายเรื่องif-elseจาก lab3 http://com5630043.blogspot.com/search/label/lab3%20%3A%20Condition
ไม่มีความคิดเห็น:
แสดงความคิดเห็น