วันอังคารที่ 27 สิงหาคม พ.ศ. 2556

Button.




void setup(){
  size(200, 200); //หน้าจอแสดงผลขนาด 200x200
  background(0); //พื้นหลังสีดำ
}

Button Name =new Button("Annt"); //ประกาศ object Name =new Button( ) ขึ้นมาเป็นButton (ซึ่งเป็นclassที่สร้างไว้) เป็นตัวแปรแบบ Local Variable
Button Hello = new Button ();

void draw(){
  Name.display(); //เป็นการเรียกใช้ method ภายในฟังชันโดยกำหนด object ที่ต้างการใช้ไว้ข้างหน้า method
  Hello.display();
}

void mousePressed(){
  Name.click(); //เป็นการเรียกใช้ method ภายในฟังชันโดยกำหนด object ที่ต้างการใช้ไว้ข้างหน้า method
  Hello.click(); 
}

class Button {
  String name;
  int x; //ประกาศ Attribute x ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Local Variable
  int y; //ประกาศ Attribute y ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Local Variable
  int z; //ประกาศ Attribute z ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Local Variable
  Button (String n ){
    this.name=n;  
    this.x=50;
    this.y=50;
    this.z=50;
  }
  Button (){
    this.name="Hello";  
    this.x=120;
    this.y=50;
    this.z=40;
  }

  void display() { //method ที่ใช้ในการแสดงภาพขึ้นCanvas
    strokeWeight(3); 
    if (this.x==50){
      fill(255, 20, 147);
    }
    else{
      fill(0, 191, 255);
    }
    rect(this.x, this.y, this.z, this.z);
  }

  void click() {
    if (mouseX>=this.x&&mouseX<=this.x+this.z&&mouseY>=this.y&&mouseY<=this.y+this.z){
      println(this.name);
    }
  }

}

วันอังคารที่ 20 สิงหาคม พ.ศ. 2556

Palindrome & Reverse.

  void setup() {
  String s = "Computer"; //เป็นการประกาศตัวแปรชนิด String หรือข้อความ
  if (isPalindrome(s)) { 
    println(s + " is a palindrome"); //เป็นการแสดงค่าออกมาทางหน้าจอ
  } 
  else { 
    println(s + " is not a palindrome");
  } 
  print(reverseString("Computer"));
}

boolean isPalindrome(String s) {  //เป็นการสร้าง function โดยกำหนดให้มีการ return ค่าเป็น true หรือ false 
  String t=reverseString(s);
  int i, sum=0;
  for (i=0;i<s.length();i++) { //for(กำหนดค่าให้ตัวแปร,เงื่อนไขในการวน,เพิ่มค่าให้ตัวแปรทุกครั้งที่มีการวนลูป)
    if (t.charAt(i)==s.charAt(i)) {
      sum++;
    }
  }
  if (sum==s.length()) return true;
  else return false;
}
String reverseString(String A) {
  String B = "";
  int i;
  for (i=0;i<A.length();i++) { 
    B=B+(A.charAt(A.length()-1-i));
  }
  return B;
}

out put
Computer is not palindrome
retupmoC



Game&Watch : Egg


Nintendo Game & Watch EGG หรือ ที่เด็กไทยสมัยก่อนเรียกติดปากว่า เกมส์หมาป่ารับไข่ วิธีการเล่นก็ง่ายๆ คือ เราต้องบังคับตัวละครที่เป็นหมาป่าที่กำลังถือตระกร้าอยู่ให้รับไข่ที่จะค่อยๆตกลงมาจากเล้าไก่ทั้ง 4 ด้าน 

สร้างฟังก์ชัน BG() เพื่อเป็นการรวมฉากหลังภายในเกม โดยภายในฟังชันนี้มีการรวมไว้4ฟังก์ชัน  คือ
drawTree(); วาดต้นไม้
drawChute();วาดราง
drawBush();วาดพุ่มไม้
drawChicken();วาดไก่
ซึ่งทั้ง4ฟังก์ชันนี้ไม่มี parameters และการ return ค่า


สร้างฟังก์ชัน Body() เพื่อทำตัวหมาป่า ให้รับไข่ที่ร่วงลงมา
ภายในฟังชันนี้มีฟังก์ชัน drawArms (); วาดแขนของหมาป่าใช้รับไข่ การทำงานของฟังก์ชันแขนคือ ช่วยวาดแขนเมื่อเรากดปุ่มตามที่กำหนด ทำให้ไม่ต้องวาดซ้ำหลายรอบ ซึ่งฟังชันนี้มี parameter เอาไว้เก็บค่าที่ใช้ในคำสั่งวาดมือ quad


การใช้มือรับไข่ของหมาป่า ควบคุมโดยคีย์บอร์ด ปุ่ม Q คือซ้ายบน E คือขวาบน  Z คือซ้ายล่าง C คือขวาล่าง

สร้างฟังก์ชัน setEgg() เพื่อใช้ในการกำหนดตำแหน่งของไข่ไว้ก่อนตั้งแต่แรก
โดยการกำหนดตำแหน่งของไข่ จะทำโดยการ random

สร้างฟังก์ชัน breakEgg(int x) เพื่อทำไข่แตก เมื่อตัวหมาป่ารับไข่ไม่ได้ ซึ่งฟังก์ชันนี้มี parameter แต่ไม่มีการ return ค่า ค่าที่รับมาคือ ค่าในพิกัดแกน X และส่งค่าเข้าไปยังคำสั่งต่างๆภายในฟังก์ชัน





reference : http://www.youtube.com/watch?v=huPKkZlYJDY


class Fraction.

class Fraction { //สร้างClass ขึ้นมาเพื่อเก็บData & Method ทำให้สะดวกในการใช้งานต่อไปในภายหลัง
  int n; //ประกาศ Attribute n ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Local Variable
  int d;
  Fraction (int a, int b) { //Constructor ใช้ในการกำหนด Object
    n = a; 
    d = b;
  }
  void add (int z) { //Method เกี่ยวกับการบวกเศษส่วน Overloading
    this.n = this.d*z+this.n;
  }
  String toString() {
    String s = this.n+"/"+this.d;
    return s;
  }
  void reciprocal() { //Method เกี่ยวกับการสลับเศษและส่วน
    int tmp;
    tmp = n;
    n = d;
    d = tmp;
  }
}
  void setup() {
    Fraction f = new Fraction (2, 7);
    f.add (3); //ใส่ค่า บวก 3
    println (f.toString());
  }

out put
23/7

วันอาทิตย์ที่ 18 สิงหาคม พ.ศ. 2556

Matrix Calculation.




void setup() {
  int[][] Mt1 = {  //เป็นการสร้างตัวแปร Array 2 มิติ ชนิดจำนวนเต็ม
    {
      1, 2, 3
    }
    , {
      3, 5, 1
    }
    , {
      5, 8, 4
    }
  };
  int[][] Mt2 = {
    {
      1, 3, 5
    }
    , {
      1, 6, 2
    }
    , {
      3, 4, 2
    }
  };
  int[][] sum = new int[3][3]; //เป็นการกำหนดค่าความกว้างของ Array แต่ละมิติโดยช่องแรกกำหนดความกว้างของ index และช่องที่  2 กำหนดว่าข้างในของแต่ละ index จะมีความกว้างเท่าไร
  int y=20, x;
  int i, j;
  for (i=0;i<Mt1.length;i++) { //for(กำหนดค่าให้ตัวแปร,เงื่อนไขในการวน,เพิ่มค่าให้ตัวแปทุกๆครั้งที่มีการวนลูป)
    x=10;
    for (j=0;j<Mt1[i].length;j++) {
      sum[i][j] = Mt1[i][j]+Mt2[i][j];
      fill(0);
      text(" "+sum[i][j],x,y); //คำสั่งแสดงข้อความโดยกำหนดดังนี้("ข้อความ"+ค่าที่ต้องการแสดง,ตำแน่งแกนx,ตำแหน่งแกนy)
      x=x+20;
    }
    y=y+20;
  }



วันศุกร์ที่ 16 สิงหาคม พ.ศ. 2556

Chess.




  void setup() {
  size(400, 400); //หน้าจอแสดงผลขนาด 400x400
  int x; //ประกาศตัวแปร x ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Global Variable
  int y; //ประกาศตัวแปร y ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Global Variable
  int i; //ประกาศตัวแปร i ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Global Variable
  int j; //ประกาศตัวแปร j ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Global Variable

//Array คือ รูปแบบการก็บข้อมูลหลายๆตัวที่มีชนิดของข้อมูลเหมือนกันไว้ด้วยกันเป็นชุด โดยเข้าถึงข้อมูลแต่ละตัวใน Array ได้โดยใช้ index เริ่มต้นที่0
  int[][] Chess= { //สร้างตัวแปร Array 2มิติ ชนิดจำนวนเต็ม และกำหนดค่า
    {
      1, 2, 3, 4, 5, 3, 2, 1
    }
    , {
      6, 6, 6, 6, 6, 6, 6, 6
    }
    , {
      0, 0, 0, 0, 0, 0, 0, 0
    }
    , {
      0, 0, 0, 0, 0, 0, 0, 0
    }
    , {
      0, 0, 0, 0, 0, 0, 0, 0
    }
    , {
      0, 0, 0, 0, 0, 0, 0, 0
    }
    , {
      6, 6, 6, 6, 6, 6, 6, 6
    }
    , {
      1, 2, 3, 4, 5, 3, 2, 1
    }
  };

  strokeWeight(2);
  for (y=0,i=0;Chess.length>i;i++,y+=50) { //for(กำหนดค่าให้ตัวแปร,เงื่อนไขในการวน, เพิ่มค่าให้ตัวแปรทุกครั้งที่มีการวนลูป)
    for (x=0,j=0;Chess[0].length>j;j++,x+=50) {
      if ((j+i)%2==0) { //เป็นการกำหนดเงื่อนไขการใส่สีของตาราง
        fill(255, 0, 0);
      }
      else {
        fill(0); //Black color
      }
      rect(x, y, 100, 100); //วาดสี่เหลี่ยมเป็นตาราง
    }
  }

  for (x=25,y=25,i=0;Chess.length>i;i++,y+=50) {
    for (x=25,j=0;Chess[i].length>j;j++,x+=50) {
      if (y<200) {
        fill(255, 20, 147);
        stroke(255, 255, 0);
      }
      else if (y>200) {
        fill(0, 255, 255);
        stroke(255, 255, 0);
      }

      strokeWeight(3);

      if (Chess[i][j]==1) {
        rook(x, y);
      }
      else if (Chess[i][j]==2) {
        knight(x, y);
      }
      else if (Chess[i][j]==3) {
        bishop(x, y);
      }
      else if (Chess[i][j]==4) {
        queen(x, y);
      }
      else if (Chess[i][j]==5) {
        king(x, y);
      }
      else if (Chess[i][j]==6) {
        if (y<200) {

          stroke(255);
        }
        else if (y>200) {

          stroke(255);
        }
        strokeWeight(5);
        prawn(x, y);
      }
    }
  }
}

void rook(int x, int y) { //ฟังก์ชันที่ใช้วาดเรือ
  ellipse(x, y, 45, 45);
  if (y<200) {
    fill(255);
  }
  else if (y>200) {
    fill(0);
  }

  text("rook", x-12, y+3);
}

void knight(int x, int y) { //ฟังก์ชันที่ใช้วาดม้า

  ellipse(x, y, 45, 45);
  if (y<200) {
    fill(255);
  }
  else if (y>200) {
    fill(0);
  }
  text("knight", x-16, y+3);
}

void bishop(int x, int y) { //ฟังก์ชันที่ใช้วาดบิชอป
  ellipse(x, y, 45, 45);
  if (y<200) {
    fill(255);
  }
  else if (y>200) {
    fill(0);
  }
  text("bishop", x-17, y+3);
}
void queen(int x, int y) { //ฟังก์ชันที่ใช้วาดควีน

  ellipse(x, y, 45, 45);
  if (y<200) {
    fill(255);
  }
  else if (y>200) {
    fill(0);
  }
  text("queen", x-15, y+3);
}
void king(int x, int y) { //ฟังก์ชันที่ใช้วาดคิง
  ellipse(x, y, 45, 45);
  if (y<200) {
    fill(255);
  }
  else if (y>200) {
    fill(0);
  }
  text("king", x-10, y+3);
}
void prawn(int x, int y) { //ฟังก์ชันที่ใช้วาดตัวเบี้ย
  ellipse(x, y, 40, 40);
}

อ้างอิงอธิบายคำสั่งจาก  http://com5630264.blogspot.com/search/label/Lab%201
                               http://com5630264.blogspot.com/search/label/Lab%202
                               http://com5630264.blogspot.com/search/label/Lab%203

วันพุธที่ 14 สิงหาคม พ.ศ. 2556

Othello





int x=50; //ประกาศตัวแปร x=50 เป็นการประกาศแบบ Global Variable
int y=50; //ประกาศตัวแปร y=50 เป็นการประกาศแบบ Global Variable

void setup() {
  int i; //ประกาศตัวแปร i ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Local Variable
  int j; //ประกาศตัวแปร j ขึ้นมาเป็นจำนวนเต็ม ซึ่งเป็นตัวแปรแบบ Local Variable

//Array คือ รูปแบบการก็บข้อมูลหลายๆตัวที่มีชนิดของข้อมูลเหมือนกันไว้ด้วยกันเป็นชุด โดยเข้าถึงข้อมูลแต่ละตัวใน Array ได้โดยใช้ index เริ่มต้นที่0
  int[][] Othello=new int[8][8] ; //สร้างตัวแปร Arra y2มิติ ชนิดจำนวนเต็ม และกำหนดค่า
  size(400, 400); //หน้าจอแสดงผลขนาด 400x400
  background(12, 144, 90); //ใส่สีเขียวให้กับพื้นหลัง
  for (i=0;i<Othello.length;i++)
  { 
    for (j=0;j<Othello[0].length;j++) //for(กำหนดค่าให้ตัวแปร,เงื่อนไขในการวน,เพิ่มค่าให้ตัวแปรทุกครั้งที่มีการวนลูป)
    {
      Othello[i][j]=int(random(0, 200));
    }
  }

  drawSchedule(); //เรียกใช้ ฟังก์ชัน drawSchedule();

  noStroke(); //ไม่มีเส้น
  for (i=0,  y=25;i<Othello.length;i++,y+=50) 
  {
    for (j=0, x=25;j<Othello[0].length;j++) 
    {
      if (Othello[i][j]%2==0) 
      {
        fill(0);
      }
      else 
      {
        fill(255); //white color
      }
      ellipse(x, y, 40, 40);
      x+=50;
    }
  }
}

void drawSchedule() { //สร้างฟังก์ชันวาดตารางบนกระดาน
  while (x<400) {
    strokeWeight(2);
    line(x, 0, x, 400);
    x=x+50; //x จะมีค่าเพิ่มขึ้น 50  ทุกๆครั้งที่มีการวนลูป
  }
  while (y<400) {
    line(0, y, 400, y);
    y=y+50; //y จะมีค่าเพิ่มขึ้น 50  ทุกๆครั้งที่มีการวนลูป
  }
}

อ้างอิงอธิบายคำสั่งจาก  http://com5630264.blogspot.com/search/label/Lab%201
                               http://com5630264.blogspot.com/search/label/Lab%202
                               http://com5630264.blogspot.com/search/label/Lab%203

วันอังคารที่ 13 สิงหาคม พ.ศ. 2556

Tic-tac-toe (OX)




int x = 100; //ประกาศตัวแปร x=100 เป็นการประกาศแบบ Global Variable
int y = 100; //ประกาศตัวแปร y=100 เป็นการประกาศแบบ Global Variable
//Array คือ รูปแบบการก็บข้อมูลหลายๆตัวที่มีชนิดของข้อมูลเหมือนกันไว้ด้วยกันเป็นชุด โดยเข้าถึงข้อมูลแต่ละตัวใน Array ได้โดยใช้ index เริ่มต้นที่0
int[][] ox= { //สร้างตัวแปร Array 2มิติ ชนิดจำนวนเต็ม และกำหนดค่า 
  {
    0, 1, 1
  }
  , {
    1, 1, 0
  }
  , {
    0, 0, 1
  }
};
int a = 0; 
int b = 0;
void setup() {
  size(300, 300); //หน้าจอแสดงผลขนาด 300x300
  background(0); //black color
  drawSchedule(); //เรียกใช้ ฟังก์ชัน drawSchedule();
  drawOX(); //เรียกใช้ ฟังก์ชัน OX();
}
void drawSchedule() { //สร้างฟังก์ชันในการวาดกระดาน
  while (x<300) { 
    stroke(255, 255, 0); //ใส่สีเหลืองให้กับเส้นวาดตาราง
    strokeWeight(10); //ใส่ความหนาของเส้นเท่ากับ 10
    line(x, 20, x, 280);
    x=x+100;  //x จะมีค่าเพิ่มขึ้น 100  ทุกๆครั้งที่มีการวนลูป
  }
  while (y<300) {
    line(20, y, 280, y);
    y=y+100; //y จะมีค่าเพิ่มขึ้น 100  ทุกๆครั้งที่มีการวนลูป
  }
}
void drawOX() { //สร้างฟังก์ชันในการวาดOX
  x = 50;
  y = 50;
  while (a<ox.length) {
    while (b<ox[a].length) {
      if (ox[a][b]==1) {
        strokeWeight(5);
        stroke(255, 20, 147); //เส้นสีชมพู
        line(x-20, y-20, x+20, y+20);
        line(x-20, y+20, x+20, y-20);
      }
      else if (ox[a][b]==0) {
        strokeWeight(5); //ใส่ความหนาของเส้นเท่ากับ 5
        stroke(0, 255, 255); //เส้นสีชมพู
        noFill(); //ไม่มีสี
        ellipse(x, y, 50, 50); //วาดวงกลม
      }
      b=b+1;
      x=x+100;
    }
    x=50;
    y=y+100;
    b=0;
    a=a+1;
  }
}

อ้างอิงอธิบายคำสั่งจาก  http://com5630264.blogspot.com/search/label/Lab%201
                               http://com5630264.blogspot.com/search/label/Lab%202
                               http://com5630264.blogspot.com/search/label/Lab%203

วันศุกร์ที่ 9 สิงหาคม พ.ศ. 2556

Barchart.

Percentage of population aged 6 years and over used computer/ Internet by length
of access last week.



//Array คือ รูปแบบการก็บข้อมูลหลายๆตัวที่มีชนิดของข้อมูลเหมือนกันไว้ด้วยกันเป็นชุด โดยเข้าถึงข้อมูลแต่ละตัวใน Array ได้โดยใช้ index เริ่มต้นที่0
float [][]p= { //สร้างตัวแปร Array 2 มิติ ชนิดจำนวนทศนิยม และกำหนดค่า
  {
    5.7, 21.2, 36.6, 23.1, 13.4
  }
  , {
    6.7, 24.7, 37.3, 21.7, 9.6
  }
};

String[]a= {  
  "Not used", "<1 hours", "1-2 hours", "2-4 hours", "Moe than 4 hours"
}; //เป็นการประกาศตัวแปรเป็น Array ชนิดข้อความ ชื่อ a ซึ่งตัวแปรชนิดนี้จะเก็บค่าได้หลายตัวโดยมีตำแหน่ง index เป็นตัวกำกับ

float average=0; //ตัวแปรที่ใช้ในการเก็บค่าเฉลี่ย
int count =0;
int x=40;
int y =350;
int i=0;
float max= p[0][0]; //ตัวแปรที่ใช้ในการเก็บค่า max
float min= p[0][0]; //ตัวแปรที่ใช้ในการเก็บค่า min

void setup() { //เป็นฟังก์ชันแรกที่ถูกกำหนดไว้แล้วให้ถูกเรียกใช้งานเมื่อโปรแกรมเริ่มทำงาน ภายในมีคำสั่งต่างๆโดยเราสามารถใส่เข้าไปเองได้ใน { } จะถูกเรียกใช้โดยอัตโนมัติและเพียงครั้งเดียว
  size(500, 500);
  background(0); //ใส่สีดำให้กับพื้นหลัง
  stroke(255); //stroke คือ การใส่สีให้กับเส้น กำหนดค่าได้ดังนี้ (แดง,เขียว,น้ำเงิน) จากตัวอย่าง stroke(255); จะได้สีขาว
  line(x, y, x+420, y);
  while (count<a.length) {
    if (p[i][count]<min) {
      min=p[i][count];
    }
    if (p[i][count]>max) {
      max=p[i][count];
    }
    if (count==a.length) {
      i=i+1;
    }
    average = average+p[i][count];

    fill(0, 255, 127); //green color
    rect(x+10, y, 30, -p[i][count]*5);
    text(p[0][count], x, (y-p[0][count]*5)-10);
    fill(255, 20, 147); //pink color
    rect(x+45, y, 30, -p[i+1][count]*5);
    text(p[i+1][count], x+40, (y-p[i+1][count]*5)-10);
    fill(255);
    text(a[count], x+20, y+20);
    x=x+80; 
    count=count+1;
  }
  fill(255, 0, 0); //red color
  rect(50, 50, 110, 70);
  fill(255);
  text("Max is"+" "+max, 60, 70); //แสดงข้อความออกมาทางCanvas
  text("Min is"+" "+min, 60, 90);
  text("Average is"+" "+average/a.length, 60, 110);
  
  fill(255); //white color
  text("Computer", 380, 410);
  text("Internet", 380, 430);
  fill(0, 255, 127); //green color
  rect(360, 400, 10, 10);
  fill(255, 20, 147); //pink color
  rect(360, 420, 10, 10);
}

วันพฤหัสบดีที่ 8 สิงหาคม พ.ศ. 2556

Solar System.




//Array คือ รูปแบบการก็บข้อมูลหลายๆตัวที่มีชนิดของข้อมูลเหมือนกันไว้ด้วยกันเป็นชุด โดยเข้าถึงข้อมูลแต่ละตัวใน Array ได้โดยใช้ index เริ่มต้นที่ 0
float[][] planets = { //สร้างตัวแปร array 2มิติ ชนิดจำนวนทศนิยม และกำหนดค่า
{0.35, 2439.7, 0}, //Mercury
{0.7, 6051.9, 0}, //Venus
{1, 6372.8, 1}, //Earth
{1.55, 3402.5, 2}, //Mars
{5.15, 68366, 66}, //Jupiter
{9.5, 60268, 22}, //Saturn
{19.2, 25559, 27}, //Uranus
{30.55, 24622, 13} //Neptune
};
String[]s = {
  "Mercury", "Venus", "The Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"
};
void setup() {
  size(570, 300); // หน้าจอแสงดผลขนาด570x300
  background(0); //พื้นหลังสีดำ
}
void draw(){
  smooth();
  fill(random(200,255),0,0);
  ellipse(-320,145,700,670);
  
  int x=120;
  int i=0;
  fill(255);
  while (i<4) { //while คือ การทำงานในลักษณะวนซ้ำหรือที่เรามักจะได้ยินกันบ่อยๆว่าการ วนลูป ซึ่งการทำงานซ้ำในแต่ละรอบนั้นจะประมวลผลกลุ่มคำสั่งเดิมที่อยู่ภายใต้ ประโยคwhile ซึ่งรอบของการวนซ้ำจะนานเท่าไรนั้นก็ขึ้นอยู่กับว่าผ่านเงื่อนไขการทดสอบว่า เป็นเท็จหรือไม่ ถ้าเป็นเท็จจริงจึงจะหลุดจากการทำงาน
    ellipse(x*planets[i][0], 150, planets[i][1]/250, planets[i][1]/250);
    drawmoon((x*planets[i][0]),planets[i][1]/250 ,planets[i][2] );
    i=i+1;
  }
  i=4;
  x=350;
  while (i<5) {
    ellipse(x*planets[i][0]/6.5, 150, planets[i][1]/1000, planets[i][1]/1000);
    drawmoon((x*planets[i][0]/6.5),planets[i][1]/1000 ,planets[i][2] );
    i=i+1;
  }
  while(i<6){
     ellipse(x*planets[i][0]/9, 150, planets[i][1]/1000, planets[i][1]/1000);
     drawmoon((x*planets[i][0]/9),planets[i][1]/1000 ,planets[i][2] );
     i=i+1;
  }
  while (i<7) {
    ellipse(x*planets[i][0]/15, 150, planets[i][1]/1000, planets[i][1]/1000);
    drawmoon((x*planets[i][0]/15),planets[i][1]/1000 ,planets[i][2] );
    i=i+1;
  }
   while (i<8) {
    ellipse(x*planets[i][0]/20, 150, planets[i][1]/1000, planets[i][1]/1000);
    drawmoon((x*planets[i][0]/20),planets[i][1]/1000 ,planets[i][2] );
    i=i+1;
  }


   
void drawmoon(float x, float rad, float n) { //ฟังก์ชันที่ใช้ในการวาดพระจันทร์โดยมี x rad c]t n เป็นparameter
  int i=0;
  while (i<n) {
    fill(255);
    ellipse(x+rad*0.6*sin(i), 150+(cos(i)*rad*0.6), 3, 3);
    i=i+1;
  }
}