วันจันทร์ที่ 23 กันยายน พ.ศ. 2556

Condition:Hard





Write a program that prompts the user to input an integer between 0 and 35. If the number is less than or equal to 9, the program should output the number; otherwise, it should output A for 10, B for 11, C for 12 . . . and Z for 35. (Hint: Use the cast operator, static_cast<char>( ), for numbers >= 10.) 
เขียนโปรแกรมที่รับค่าจำนวนเต็มตั้งแต่ 0 ถึง 35 ถ้าเลขมีค่าน้อยกว่าหรือเท่ากับ 9 ให้แสดงผลลัพธ์ออกมาเป็นตัวเลข แต่ในกรณีอื่นให้ผลลัพธ์ออกมาเป็น A สำหรับ 10, B สำหรับ 11, C สำหรับ 12 . . . และ Z สำหรับ 35
ชื่อหนังสือ : C++ Programming: From Problem Analysis to Program Design, Fifth Edition 
ชื่อผู้แต่ง : D.S. Malik  
ISBN-13: 978-0-538-79808-2 
ISBN-10: 0-538-79808-4   
หน้า : 241  
ข้อ : 3
CODE
int number = 10;          //ประกาศและกำหนดตัวแปรชื่อ number มีค่าเท่ากับ 10
String []num={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};          //ประกาศและกำหนดอาร์เรย์ชื่อ num ที่เก็บข้อมูลชนิด String ซึ่งมีข้อมูล A-Z
void setup(){
   if(number<=9){          //ถ้า number มีค่าน้อยกว่าหรือเท่ากับ 9
      println(number);          //ให้แสดงผลลัพธ์ออกมาเป็นตัวเลข
   }
   if((number>=10)&&(number<=35)){          //ถ้า number มีค่ามากกว่าหรือเท่ากับ 10 และมีค่าน้อยกว่าหรือเท่ากับ 35
     for(int i = 0;i<=num.length-1;i++){          //กำหนดให้ i มีค่าเท่ากับ 0 ถ้า i มีค่าน้อยกว่าหรือเท่ากับความยาวของอาร์เรย์ num ลบ 1 ให้ทำคำสั่งถัดมา  แล้ว i มีค่าเพิ่มขึ้น 1
        println(num[number-10] + " for " + number);         //ให้แสดงผลลัพธ์เป็นตัวอักษรตามตำแหน่งในอาร์เรย์ num
        break;          //หยุดการวนลูป
     }
  }
}

Function:Hard









Write a program that has main() call a user-defined function that takes a Celsius temperature value as an argument and then returns the equivalent Fahrenheit value. The program should request the Celsius value as input from the user and display the result, as shown in the following code:
Please enter a Celsius value: 20
20 degrees Celsius is 68 degrees Fahrenheit.
For reference, here is the formula for making the conversion:
Fahrenheit = 1.8 × degrees Celsius + 32.0

เขียนโปรแกรมที่เรียกใช้ user-defined function โดยส่งค่าองศาเซลเซียส แล้ว return value เป็นองศาฟาเรนไฮต์ โดยแสดงผลลัพธ์ดังนี้
Please enter a Celsius value: 20
20 degrees Celsius is 68 degrees Fahrenheit.

สูตร Fahrenheit = 1.8 × degrees Celsius + 32.0
ชื่อหนังสือ : C++ Primer Plus Fifth Edition 
ชื่อผู้แต่ง : Stephen Prata
ISBN: 0-672-32697-3

หน้า :64
ข้อ : 4
 CODE
float celsius = 20;          //ประกาศและกำหนดตัวแปร celsius มีค่าเท่ากับ 20
float fahrenheit;          //ประกาศตัวแปรชื่อ fahrenheit
void setup(){
  fahrenheitValue(celsius);          //สร้าง user-defined function ชื่อ fahrenheitValue ที่มี parameter คือ celsius
  println("Please enter a Celsius value: "+ celsius);          //แสดงผลลัพธ์ที่เป็นค่าในหน่วยเซลเซียส
  println(celsius + " degrees Celcius is " + fahrenheit + " degrees Fahrenheit.");          //แสดงผลลัพธ์ที่เป็นค่าในหน่วยฟาเรนไฮต์
}
float fahrenheitValue(float a){          //เรียกใช้ฟังก์ชัน fahreheitValue ที่มีการรับค่า parameter และ return value
  fahrenheit = (1.8*a)+32;         //ให้ fahrenheit มีค่าเท่ากับ (1.8*a)+32
  return fahrenheit;          //ส่งค่า fahrenheit กลับ
}

วันอาทิตย์ที่ 22 กันยายน พ.ศ. 2556

Funtion:Easy









Write a program that repeatedly asks the user to enter pairs of numbers until at least one of the pair is 0. For each pair, the program should use a function to calculate the harmonic mean of the numbers. The function should return the answer to main(), which should report the result. The harmonic mean of the numbers is the inverse of the average of the inverses and can be calculated as follows:
harmonic mean = 2.0 × x × y / (x + y)

เขียนโปรแกรมที่ให้เลขเป็นคู่ แล้วส่งไปที่ function ที่สามารถ return value ได้ โดยแสดงผลคำนวณ harmonic
ชื่อหนังสือ : C++ Primer Plus Fifth Edition 
ชื่อผู้แต่ง : Stephen Prata
ISBN: 0-672-32697-3

หน้า :334
ข้อ : 1
 CODE
float result;          //ประกาศตัวแปร result ชนิด float
void setup(){
  harmonic(1,2);          //สร้างฟังก์ชัน harmonic ที่มีการส่งค่า parameter ได้
  println("Result = "+result);          //แสดงค่าผลลัพธ์ที่ได้จากการ return value
}
float harmonic(int x,int y){          //เรียกใช้ฟังก์ชัน harmonic ที่มีการรับค่า parameter
  result=(2*x*y)/(x+y);          //ให้ result มีค่าเท่ากับ (2*x*y)/(x+y)
  return result;          //ส่งค่า result กลับ
}

Variables:Easy









Write a C++ program that displays your name and address.
เขียนโปรแกรมที่แสดงชื่อและที่อยู่
ชื่อหนังสือ : C++ Primer Plus Fifth Edition 
ชื่อผู้แต่ง : Stephen Prata
ISBN: 0-672-32697-3

หน้า :64
ข้อ : 1
 CODE
void setup(){
  String name = "JANE";
         //ประกาศและกำหนดให้ name เป็นตัวแปรชนิด String ที่มีค่าเท่ากับ JANE
  String address = "^^555";          //ประกาศและกำหนดให้ address เป็นตัวแปรชนิด String ที่มีค่าเท่ากับ ^^555
  println(name + address);          //แสดงค่า name และ address
 }

Variable:Hard









Write a short program that asks for your height in feet and inches and your weight in
pounds. (Use three variables to store the information.) Have the program report your
body mass index (BMI). To calculate the BMI, first convert your height in feet and inches to your height in inches (1 foot = 12 inches). Then, convert your height in inches to your height in meters by multiplying by 0.0254. Then, convert your weight in pounds into your mass in kilograms by dividing by 2.2. Finally, compute your BMI by dividing your mass in kilograms by the square of your height in meters. Use symbolic constants to represent the various conversion factors.

เขียนโปรแกรมที่คำนวณหาค่า BMI (ดัชนีมวลกาย) โดยเปลี่ยนส่วนสูงจากจำนวนเต็มฟุตเป็นนิ้ว นิ้วเป็นเมตร เปลี่ยน้ำหนักจากปอนด์เป็นกิโลกรัม โดยใช้ตัวแปร 3 ตัว
ชื่อหนังสือ : C++ Primer Plus Fifth Edition 
ชื่อผู้แต่ง : Stephen Prata
ISBN: 0-672-32697-3

หน้า : 107
ข้อ : 2
 CODE
void setup(){
  float BMI;         //ประกาศตัวแปรชื่อ BMI
  float heightfeet = 5.3;
         //ประกาศตัวแปรชื่อ heightfeet
  float weightpound = 132;         //ประกาศตัวแปรชื่อ weightpound
  println("Your Height = "+heightfeet+" feet");          //แสดงค่าส่วนสูงหน่วยfeet
  println("Your Height = "+(heightfeet*12)+" inches"); 
         //แสดงค่าส่วนสูงหน่วยinches
  println("Your Height = "+((heightfeet*12)*0.0254)+" meters");         //แสดงค่าส่วนสูงหน่วยmeter
  println("Your weight ="+weightpound+" pounds");         //แสดงค่าน้ำหนักหน่วยpounds
  println("Your weight ="+(weightpound/2.2)+" kilograms");         //แสดงค่าน้ำหนักหน่วยkilograms
  BMI=(weightpound/2.2)/pow(((heightfeet*12)*0.0254),2);          //คำนวณค่าดัชนีมวลกาย
  println(BMI);          //แสดงค่าดัชนีมวลกาย
  if(BMI<=18.5){          //ถ้า BMI น้อยกว่าหรือเท่ากับ 18.5
    println("Underweight");          //แสดงค่า Underweight
  }
  if((BMI>=18.5)&&(BMI<=25)){
          //ถ้า BMI น้อยกว่าหรือเท่ากับ 18.5 และมากกว่าหรือเท่ากับ 25
    println("Normal");          //แสดงค่า Normal
  }
  if(BMI>=25){
          //ถ้า BMI มากกว่าหรือเท่ากับ 25
    println("Overweight");          //แสดงค่า Overweight
  }
}

Variables:Medium









Write a short program that asks for your height in integer inches and then converts your height to feet and inches. Have the program use the underscore character to indicate
where to type the response. Also, use a const symbolic constant to represent the conversion factor.
 
เขียนโปรแกรมที่เปลี่ยนส่วนสูงจากจำนวนเต็มนิ้วเป็นฟุต
ชื่อหนังสือ : C++ Primer Plus Fifth Edition 
ชื่อผู้แต่ง : Stephen Prata
ISBN: 0-672-32697-3

หน้า : 107
ข้อ : 1
 CODE
void setup(){
  int yourheight = 64;
         //ประกาศและกำหนดให้ yourheight เป็นตัวแปรชนิด int ที่มีค่าเท่ากับ 64
  float heightfeet = yourheight/12;          //ประกาศและกำหนดให้ heightfeet เป็นตัวแปรชนิด float ที่มีค่าเท่ากับ yourheight หาร 12
  println(heightfeet);          //แสดงค่าheightfeet
 }

ฟังก์ชันคำสั่ง(System Function)ที่ใช้ในLab6.1

ฟังก์ชันคำสั่ง(System Function)ที่ใช้ในLab6.1
          size() คือ ฟังก์ชันที่กำหนดขนาดของoutput การนำไปใช้ size(ความกว้าง,ความยาว);
          background() คือ ฟังก์ชันที่กำหนดสีของพื้นหลัง การนำไปใช้ background(สี);
          fill() คือ ฟังก์ชันที่กำหนดสี การนำไปใช้ fill(สี);
          noStroke() คือ ฟังก์ชันไม่ใส่เส้นขอบ การนำไปใช้ noStorke();
          ellipse() คือ ฟังก์ชันสร้างรูปทรงวงรี การนำไปใช้ ellipse(พิกัดx,พิกัดy,เส้นผ่านศูนย์กลางด้านกว้าง,เส้นผ่านศูนย์กลางด้านยาว);
          text() คือ ฟังก์ชันตัวอักษร การนำไปใช้ text("คำที่กำหนด",พิกัดx,พิกัดy);
          textSize() คือ ฟังก์ชันขนาดตัวอักษร การนำไปใช้ text(ค่าของขนาดที่ต้องการ); ทดลองเขียนโปรแกรม http://processingjs.org/tools/processing-helper.html

วันเสาร์ที่ 21 กันยายน พ.ศ. 2556

Calculate max/min/average for your data



   
อัตราการเข้าเรียนในรูปแบบใดรูปแบบหนึ่ง ก่อนวัยเรียนของเด็กอายุ 3-4 ปี และอัตราการเข้าเรียนก่อนวัยในศูนย์เด็กเล็กของเด็กที่เข้าเรียน จำแนกตามเขตการปกครอง พ.ศ.2551 หน้า 5
ข้อมูลเพิ่มเติม http://service.nso.go.th/nso/nsopublish/service/child51/childRep51.pdf
CODE
String [] name = {"ทั่วราชอาณาจักร","ในเขตเทศบาล","นอกเขตเทศบาล"};          //ประกาศและกำหนดอาร์เรย์ 1 มิติชื่อ name ชนิด String  ที่เก็บข้อมูล={"ทั่วราชอาณาจักร","ในเขตเทศบาล","นอกเขตเทศบาล"}
float [][] data = {{72,69.6,74.5},{59.7,44.3,66.2}};          //ประกาศและกำหนดอาร์เรย์ 2 มิติชื่อ data ชนิด float  ที่เก็บข้อมูล={{72,69.6,74.5},{59.7,44.3,66.2}}
float maxs,mins,sum,sum1;          //ประกาศตัวแปรชื่อ maxs,mins,sum,sum1 ชนิดข้อมูล float void setup(){
//ข้อมูลที่ 1
     for(int j = 0; j<data[0].length;j++){          //กำหนดให้ j มีค่าเท่ากับ ถ้า j มีค่าน้อยกว่าความยาวของอารเรย์ data  ให้ทำคำสั่งถัดไป  แล้ว j มีค่าเพิ่มขึ้น 1
       if(j==0){          //ถ้าj=0
        maxs = data[0][0];          //ให้ maxs มีค่าเท่ากับ อาร์เรย์ data ที่ตำแหน่ง [0][0]
        mins = data[0][0];          //ให้ mins มีค่าเท่ากับ อาร์เรย์ data ที่ตำแหน่ง [0][0]
      }
      else if((data[0][j])>=maxs){          //ถ้าค่าภายในตำแหน่ง[0][j]ของอาร์เรย์data มากกว่าหรือเท่ากับ maxs
        maxs = data[0][j];          //maxs มีค่าเท่ากับ ค่าภายในตำแหน่ง[0][j]ของอาร์เรย์data
        println(name[j]+"MAX = "+data[0][j]);          //แสดงตัวอักษรตามข้อมูลในอาร์เรย์ name[j] ,data[0][j]
      }
     else if((data[0][j])<=mins){          //ถ้าค่าภายในตำแหน่ง[0][j]ของอาร์เรย์data น้อยกว่าหรือเท่ากับ mins
        mins = data[0][j];          //mins มีค่าเท่ากับ ค่าภายในตำแหน่ง[0][j]ของอาร์เรย์data
        println(name[j]+"MIN = "+data[0][j]);          //แสดงตัวอักษรตามข้อมูลในอาร์เรย์ name[j] ,data[0][j]
      }
      sum = sum + data[0][j];          //sumมีค่าเท่ากับsum + ข้อมูลในอาร์เรย์ data[0][j]
    }
    println("Avg1 = "+sum/(data[0].length));          //แสดงค่าเฉลี่ย
//ข้อมูลที่ 2
    for(int j = 0; j<data[1].length;j++){          //กำหนดให้ j มีค่าเท่ากับ ถ้า j มีค่าน้อยกว่าความยาวของอารเรย์ data  ให้ทำคำสั่งถัดไป  แล้ว j มีค่าเพิ่มขึ้น 1
      if(j==0){          //ถ้าj=0
        maxs = data[1][0];          //ให้ maxs มีค่าเท่ากับ อาร์เรย์ data ที่ตำแหน่ง [1][0]
        mins = data[1][0];          //ให้ mins มีค่าเท่ากับ อาร์เรย์ data ที่ตำแหน่ง [1][0]
      }
     else if((data[1][j])>=maxs){          //ถ้าค่าภายในตำแหน่ง[1][j]ของอาร์เรย์data มากกว่าหรือเท่ากับ maxs
        maxs = data[1][j];          //maxs มีค่าเท่ากับ ค่าภายในตำแหน่ง[1][j]ของอาร์เรย์data
        println(name[j]+"MAX = "+data[1][j]);          //แสดงตัวอักษรตามข้อมูลในอาร์เรย์ name[j] ,data[0][j]
     }
     else if((data[1][j])<=mins){          //ถ้าค่าภายในตำแหน่ง[1][j]ของอาร์เรย์data น้อยกว่าหรือเท่ากับ mins
        mins = data[1][j];          //mins มีค่าเท่ากับ ค่าภายในตำแหน่ง[1][j]ของอาร์เรย์data
        println(name[j]+"MIN = "+data[1][j]);          //แสดงตัวอักษรตามข้อมูลในอาร์เรย์ name[j] ,data[0][j]
      }
      sum1 = sum1 + data[1][j];          //sum1มีค่าเท่ากับsum1 + ข้อมูลในอาร์เรย์ data[1][j]
    }
    println("Avg2 = "+sum1/(data[1].length));          //แสดงค่าเฉลี่ย
}


Inheritance









CODE
void setup(){
  Emotion a = new Emotion();
  Emotion b = new happy();
  a.feel();
  b.feel();
}
class Emotion{
  void feel(){
    println(" :) ");
  }
}
class happy extends Emotion{
  void feel(){
    println(" ^^ ");
  }

LCD









CODE
void setup(){
  int n1 = 15;          //ประกาศและกำหนด n1 เท่ากับ 15
  int n2 = 36;          //ประกาศและกำหนด n2 เท่ากับ 36
  NUM a = new NUM(n1,n2);          //object ชื่อ a ที่มี parameters
  println("LCD(" +n1+"," +n2+") = " + a.lcd());           //แสดงค่าLCD
}
class NUM{
  int x;           //ประกาศ attribute ชื่อ x ชนิด int
  int y;           //ประกาศ attribute ชื่อ y ชนิด int
  int b;           //ประกาศ attribute ชื่อ b ชนิด int
  NUM(int x1,int y1){          //constructor คือ method ที่ชื่อเดียวกับ class
    this.x=x1;           //กำหนดให้ x มีค่าเท่ากับ x1
    this.y=y1;           //กำหนดให้ y มีค่าเท่ากับ y1
  }
  int gcd (){            //method ชื่อ gcd
    if(x==0){            //ถ้า x มีค่าเท่ากับ 0
      return this.y;          //ให้ส่งค่า y
     }
    if(y==0){            //ถ้า y มีค่าเท่ากับ 0
      return this.x;          //ให้ส่งค่า x
    }
    if(x>y){          //ถ้า x มากกว่า y
      b = x;           //กำหนดให้ b มีค่าเท่ากับ x
      x = y;           //กำหนดให้ x มีค่าเท่ากับ y
      y = b;           //กำหนดให้ y มีค่าเท่ากับ b
      y = y%x;           //กำหนดให้ y มีค่าเท่ากับ y%x
      return gcd();          //ให้ส่งค่า gcd()
    }
    else {          //กรณีอื่น
      y = y%x;           //กำหนดให้ y มีค่าเท่ากับ y%x
      return gcd();          //ให้ส่งค่า gcd()
    }
  }
  int lcd(){          //method ชื่อ lcd
    b = x*y;           //กำหนดให้ b มีค่าเท่ากับ x*y
    b = b/gcd();           //กำหนดให้ b มีค่าเท่ากับ b/gcd()
    return this.b;          //ให้ส่งค่า b
  }
}

GCD









CODE
void setup(){
  int n1= 15;          //ประกาศและกำหนด n1 เท่ากับ 15
  int n2= 36;          //ประกาศและกำหนด n2 เท่ากับ 36
  NUM a = new NUM(n1,n2);          //object ชื่อ a ที่มี parameters
  println("GCD(" +n1+","+n2+") = " + a.gcd());           //แสดงค่าGCD
}
class NUM{
  int x;           //ประกาศ attribute ชื่อ x ชนิด int
  int y;           //ประกาศ attribute ชื่อ y ชนิด int
  NUM(int x1,int y1){          //constructor คือ method ที่ชื่อเดียวกับ class
    this.x=x1;           //กำหนดให้ x มีค่าเท่ากับ x1
    this.y=y1;           //กำหนดให้ y มีค่าเท่ากับ y1
  }
  int gcd (){            //method ชื่อ gcd
    if(x==0){            //ถ้า x มีค่าเท่ากับ 0
      return this.y;          //ให้ส่งค่า y
     }
    if(y==0){            //ถ้า y มีค่าเท่ากับ 0
      return this.x;          //ให้ส่งค่า x
    }
    if(x>y){          //ถ้า x มากกว่า y
      int b = x;           //กำหนดให้ b มีค่าเท่ากับ x
      x = y;           //กำหนดให้ x มีค่าเท่ากับ y
      y = b%y;           //กำหนดให้ y มีค่าเท่ากับ b%y
      return gcd();          //ให้ส่งค่า gcd()
    }
    else {          //กรณีอื่น
      y = y%x;           //กำหนดให้ y มีค่าเท่ากับ y%x
      return gcd();          //ให้ส่งค่า gcd()
    }
  }
}

LimitedUFO




*เมื่อ UFO เคลื่อนที่ครบ 3 รอบ จะหายไป

UFO
  int x;
  int y;
  int r1;
  int r11;
  int r2;
  int r21;
  int a;
  int b;   int i;
  UFO(int  x1,int  y1,int  ru1,int  ru11,int  ru2,int  ru21,int i1)
  showUFO()
  CODE
int xx=0;        //ประกาศและกำหนดให้ xx เท่ากับ 0
void setup (){
   size(250,250);          //ขนาดเอาต์พุต กว้างและยาว 250
}
UFO u = new UFO (50,30,33,31,80,20,0);          //สร้าง object ชื่อ u ที่มี parameters คือ (50,30,33,31,80,20) 
void draw(){   background(0);          //สีพื้นหลังสีดำ
    u.showUFO();          //object ชื่อ u เรียกใช้ method ชื่อ showUFO
}
class UFO{
   int x;          //ประกาศ attribute ชื่อ x ชนิด int
   int y;          //ประกาศ attribute ชื่อ y ชนิด int
   int r1;          //ประกาศ attribute ชื่อ r1 ชนิด int
   int r11;          //ประกาศ attribute ชื่อ r11 ชนิด int
   int r2;          //ประกาศ attribute ชื่อ r2 ชนิด int
   int r21;          //ประกาศ attribute ชื่อ r21 ชนิด int
   int a;          //ประกาศ attribute ชื่อ a ชนิด int
   int b;          //ประกาศ attribute ชื่อ b ชนิด int
   int i;          //ประกาศ attribute ชื่อ i ชนิด int
   UFO(int x1,int y1,int ru1,int ru11,int ru2,int ru21,int i1){          //constructor คือ method ที่ชื่อเดียวกับ class
     this.x=x1;          //กำหนดให้ x มีค่าเท่ากับ x1
     this.y=y1;          //กำหนดให้ y มีค่าเท่ากับ y1
     this.r1=ru1;          //กำหนดให้ r1 มีค่าเท่ากับ ru1
     this.r11=ru11;          //กำหนดให้ r11 มีค่าเท่ากับ ru11
     this.r2=ru2;          //กำหนดให้ r2 มีค่าเท่ากับ ru2
     this.r21=ru21;          //กำหนดให้ r21 มีค่าเท่ากับ ru21
     this.i=i1;          //กำหนดให้ i มีค่าเท่ากับ i1
   }
   void showUFO(){            //method ชื่อ showUFO
       if((x>=50)&&(x<=200)&&(xx==0)&&(y==30)&&(i<=2)){          //ถ้า x มีค่ามากกว่าหรือเท่ากับ 50 และ น้อยกว่าหรือเท่ากับ 200  และ xx มีค่าเท่ากับ และ y มีค่าเท่ากับ 30 และ i มีค่าน้อยกว่าหรือเท่ากับ 2
          x++;           //กำหนดให้ x มีค่าเพิ่มขึ้น 1
          fill(random(255),random(255),random(255));               //สุ่มสี
          ellipse(x, y, r1, r11);              //วงกลมที่พิกัดx,y  ขนาด ความกว้าง=r1 ความยาว=r11
          fill(173,169,169);              //สีเทา                            
          ellipse(x, y+3, r2, r21);              //วงกลมที่พิกัดx,y  ขนาด ความกว้าง=r2 ความยาว=r21        }
       else if((xx==0)&&(i<=2)){          //ถ้า xx มีค่าเท่ากับ 0 และ i มีค่าน้อยกว่าหรือเท่ากับ 2
          y++;           //กำหนดให้ y มีค่าเพิ่มขึ้น 1
          fill(random(255),random(255),random(255));               //สุ่มสี 
          ellipse(x, y, r1, r11);              //วงกลมที่พิกัดx,y  ขนาด ความกว้าง=r1 ความยาว=r11
          fill(173,169,169);              //สีเทา                                  
          ellipse(x, y+3, r2, r21);              //วงกลมที่พิกัดx,y  ขนาด ความกว้าง=r2 ความยาว=r21
          if(y==220){          //ถ้า y มีค่าเท่ากับ 220
            xx=1;           //กำหนดให้ xx มีค่าเท่ากับ 1
          }
       }
       else if((y==220)&&(xx==1)&&(i<=2)){          //ถ้า y มีค่าเทากับ 220 และ xx มีค่าเท่ากับ 1 และ i มีค่าน้อยกว่าหรือเท่ากับ 2
          x--;           //กำหนดให้ x มีค่าลดลง 1
          fill(random(255),random(255),random(255));               //สุ่มสี
          ellipse(x, y, r1, r11);              //วงกลมที่พิกัดx,y  ขนาด ความกว้าง=r1 ความยาว=r11
          fill(173,169,169);              //สีเทา
          ellipse(x, y+3, r2, r21);              //วงกลมที่พิกัดx,y  ขนาด ความกว้าง=r2 ความยาว=r21
          if(x==50){           //ถ้า x มีค่าเท่ากับ 50
            xx=2;           //กำหนดให้ xx มีค่าเท่ากับ 2
          }
       }
       else if((x==50)&&(xx==2)&&(i<=2)){          //ถ้า x มีค่าเทากับ 50 และ xx มีค่าเท่ากับ 2 และ i มีค่าน้อยกว่าหรือเท่ากับ 2
          y--;           //กำหนดให้ y มีค่าลดลง 1
          fill(random(255),random(255),random(255));               //สุ่มสี
          ellipse(x, y, r1, r11);              //วงกลมที่พิกัดx,y  ขนาด ความกว้าง=r1 ความยาว=r11
          fill(173,169,169);              //สีเทา
          ellipse(x, y+3, r2, r21);              //วงกลมที่พิกัดx,y  ขนาด ความกว้าง=r2 ความยาว=r21
          if(y==30){           //ถ้า y มีค่าเท่ากับ 30
             xx=0;           //กำหนดให้ xx มีค่าเท่ากับ 0
             i++;          //iมีค่าเพิ่มขึ้น1
         }
      }
   }
}