11 พฤศจิกายน 2556

LED random

O.O LeD กระพริบปริ๊บๆ O.O 
~ ~ LeD ~


LeD Processing.js code

Problem 11/11/56


Problem IV 
• Write a Java method that takes an array of int values and determines if there is a pair of numbers in the array whose product is odd.
– จงสร้างเมธอดในภาษา Java (ใชชื้่ออะไรก็ได้) ที่มีพารามิเตอร์เป็นอาร์เรย์แบบ int และให้ค่ากลับคืนเป็นจริงก็ต่อเมื่อ มีเลขจำนวนสองตัวในอาร์เรย์ที่ผลคูณเป็นเลขคี่


Problem 4/11/56

Problem

31 ตุลาคม 2556

.. Game Assignment 2 ..

.. Game Assignment 2 ..


Game Snoopy Processing.js code

Background Game


//// Background ////


Life & Button


////  Life & Button  ////


Draw Girl Style


//// Draw Girl Style ////


Draw Boy Stlye


//// Draw Boy Style ////


Draw Snoopy Style


//// Draw Snoopy Style ////


Racket -- snoopy


/////// ไม้เทนนิส ของ snoopy //////

void Snoopy_style


/////////// ตำแหน่งและท่า snoopy ////////////


void Boy_style


/////// ท่าตี Boy  //////


void Boy_moveBall


/////// เดินลูกบอลที่ ten1_Boy & ten2_Boy //////


void Girl_moveBall


/////// เดินลูกบอลที่ ten1_Girl & ten2_Girl //////

void hit_Girl

การตีโต้กลับของ Girl

void miss

miss and Game over

void random_Ball

สุ่มแนวการเดินลูกบอลที่ Boy ตี 


void draw

ฟังก์ชัน draw


keyPressed function

ฟังก์ชัน KeyPressed


ฟังก์ชันและตัวแปร

ใช้  29  Function  ดังนี้

29 ตุลาคม 2556

Assignment 2_BB

..# Assignment 2_BB #.. 
~ ~ Assignment 2_B ~

 
Assignment 2_B  Processing.js code


24 ตุลาคม 2556

Assignment 2_B

..# Assignment 2_B #.. 
~ ~ Assignment 2_B ~

 
Assignment 2_B  Processing.js code


20 กันยายน 2556

Class

void setup(){
  size(400,250);
  background(111);
  Fraction f = new Fraction(2,7);
  Fraction g = new Fraction(4,9);
  f.add(3);
  text("="+f.toString(),195,140);
}

class Fraction{
  int n;
  int d;
  Fraction(int a,int b){
    n = a; //this.n = a
    d = b;
  }
  void add(int z){
    text(this.n+"/"+this.d,195,100);
    text(z,195,120);
    this.n = this.d*z+this.n;
  }
   
  String toString(){
    String s = this.n+"/"+this.d;
    return s;
  }
  void reciprocal(){
    int temp;
    temp = n;
    n = d;
    d = temp;
  }
}

Palindrome

.. Palindrome ..

~  ~ hu hu hu :')) ~  ~



Palindrome Processing.js code

Ohello and Pieces

.. Ohello ..

~  ~ hu hu hu :')) ~  ~



Ohello Processing.js code

17 กันยายน 2556

Assignment 2

void Snoopy(float x, float y) {
  noStroke();
  ellipse(x+50, y, 50, 50);
  ellipse(x+40, y+10, 60, 40);
  ellipse(x+45, y+45, 25, 30);
  ellipse(x+55, y+55, 20, 5);
  fill(0, 0, 0);
  ellipse(x+30, y+10, 10, 7);
  ellipse(x+40, y-5, 3, 7);
  ellipse(x+45, y-5, 3, 7);
  ellipse(x+70, y+10, 20, 35);
  stroke(0, 0, 0);
  fill(255);
  ellipse(x+30, y+50, 15, 25);
  ellipse(x+40, y+50, 15, 25);
  ellipse(x+55, y+50, 10, 10);
}

int sno = 300;



void setup() {
  size(600, 400);
}


void draw(){
  int i = 0;
  int j = 0;
  int h = 45;
  int l = 40;
  int x = 100;
  int y = height-140;
  int r = 20;
  background(111);
  Snoopy(width-190, sno);
  while(j<3){
    if(j==0){
      while(i<8){
      ellipse(x,y,r,2*r/3);
      x = x+l;
      y = y-h;
      h = h-7;
      i = i+1;
    }
  }
  else if(j==1){
    while(i<7){
      ellipse(x,y,r,2*r/3);
      x = x+l+10;
      y = y-h;
      h = h-13;
      i = i+1;
    }
  }else if(j==2){
    while(i<6){
      ellipse(x,y,r,2*r/3);
      x = x+l+17;
      y = y-h+10;
      h = h-20;
      i = i+1;
    }
  }
  h = 45;
  j = j+1;
  i = 0;
  x = 100;
  y = height-140;
}
  
}


     
     

void keyPressed() {
  if (keyCode == UP) {
    if (sno>100) {
      sno=sno-100;
    }
  }
  if (keyCode ==DOWN) {
    if (sno<300) {
      sno=sno+100;
    }
  }
}

 void tennis(float x, float y) {
  ellipse(x, y, 20, 20);
}

Background --> Assignment 2

.. Assignment 2..

~  ~ Background :')) ~  ~



Background Processing.js code


15 กันยายน 2556

..# Array #..

..# Array #..


Easy   P.524 /3
Write the C++ statement to declare a one-dimensional double array named rates that has five elements. Then write the code to assign the following numbers to the array: 6.5, 8.3, 4,2,and 10.5.
Answer
          double[] rate = new int[5];
                   double[] rate[0] = 6.5;
                   double[] rate[1] = 8.3;
                   double[] rate[2] = 4;
                   double[] rate[3] = 2;
                   double[] rate[4] = 10.5;
// or double[] rate = {6.5, 8.3, 4, 2, 10.5};

 
Middle   P.524 /15
Write the C++ code to add together the numbers stored in the first and second elements inclouded in a one-dimensional int array named num. Display the sum on the screen.
Answer
          int[] num = {20, 30};
                   println(num[0]+num[1]);
                   // add together the numbers stored in the first and second elements
                   // output  50

 

Hard   P.524 /20
Write the C++ cord to add together the number stored in the first row, first column of the num array, and the number stored in the second row, first column of the num array. Display the sum on the screen.
Answer
          void setup(){
                        int[][] num = {{1,2},{4,3}}; // แระกาศและกำหนดค่าอะเรย์สองมิติ num
                        int[] N = new int[num[1].length]; 
/* ประกาศและกำหนดให้ค่าอะเรย์หนึ่งมิติ  N ให้รับค่าผลบวกของ column มีความยาวเท่ากับ จำนวน column ในแถวที่ 1 */
                        int i = 0;  // ประกาศและกำหนดค่าเริ่มต้น i = 0
                         while (i < num[1].length){
                             N[i] = num[0][i]+num[1][i];

  /* add together the number stored in the first row, first column of the num array, and the number stored in the second row, first column */
                             i = i + 1; // เพิ่มค่า i จะขึ้นตำแหน่งใหม่
                        }
                        println(N);
                   }



..# Loop #..

..# Loop #..


Easy   P.351 /1
Assume a program declares an int  named evenNum and initializes it to 2. Write a C++ while loop that uses the evenNum variable to display the even integers between 1 and 9
Answer
          int evenNum = 2;  // ประกาศและกำหนดค่าตัวแปร evenNum เริ่มที่ 2
                   while (evenNum < 9) {  // สร้าง Loop ที่ evenNum น้อยกว่า 9
                        println (evenNum);  // ปริ๊นค่า evenNum ในบรรทัดใหม่
                        evenNum = evenNum + 2;  // เพิ่มค่า evenNum 2 หน่วย เพื่อที่จะเป็นจำนวนคู่
                   }  // end while


Middle   P.390 /2
Assume a program declares two int variable named firstLoop and secondLoop. Both variable are initialized to the number 1. Write the C++ code that uses these variables to display the number 1 and 3 on four lines, as follows.
1        2        3
1        2        3
1        2        3
1        2        3
Answer
          int firstLoop = 1;  // ประกาศและกำหนดค่าตัวแปร firstLoop เท่ากับ 1
                   int secondLoop = 1;  // ประกาศและกำหนดค่าตัวแปร secondLoop เท่ากับ 1
                   while (firstLoop <=4) {  // สร้าง Loop ที่ค่า firstLoop น้อยกว่าหรือเท่ากับ 4
                        while (secondLoop <= 3) {  // สร้าง Loop ที่ค่า secondLoop น้อยกว่าหรือเท่ากับ 3
                             print(secondLoop);  // ปริ๊นค่า secondLoop  ในบรรทัดเดียวเดิม
                             print("   ");  // ปริ๊น ช่องว่าง ในบรรทัดเดียวกัน
                             secondLoop = secondLoop + 1; 
                            
// เพิ่มค่า secondLoop 1 หน่วย แล้วกลับไปพิจารณาเงื่อนไขการวน loop
                        }  // end while secondLoop
                        println();  // ปริ๊นเริ่มบรรทัดใหม่
                        firstLoop = firstLoop + 1; 
                       
// ให้ firstLoop เพิ่ม 1 หน่วย กลับไปพิจารณาเงื่อนไขการวนค่า loop
                         secondLoop = 1;  // รีเซ็ตค่า secondLoop เพื่อเริ่มการวน loop ที่สองใหม่
                   }  // end while  firstLoop


Hard   P.394 /6:B
Complete the program by entering the instructions to display the following pattern of asterisks ( 9 asterisks, 8 asterisks, 7 asterisks, 6 asterisks, 5 asterisks, 4 asterisks, 3 asterisks, 2 asterisks, 1 asterisks ).
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Answer
          void setup() {
                        int i = 9;
                        while (i > 0) {
                             printV(i);  // เรียกใช้ฟังก์ชัน printV และใส่ค่า parameter ให้เท่ากับค่า i
                             println();  // ปริ๊นบรรทัดใหม่
                             i = i - 1;  // ให้ค่า I ลดลง 1 หน่วย
                        }  // end loop
                   }   // end function
                   void printV(int n) {  // สร้างฟังก์ชัน printV มี parameter n
                        int count = 0;  // ประกาศและกำหนดค่าตัวแปร count = 0
                        while (count < n) {  // สร้าง loop ให้ค่า count น้อยกว่าค่า ตัวแปร n
                             print("* ");  // ปริ๊น  “* ” ในบรรทัดเดียวกัน
                             count = count+1;  // เพิ่มค่า count 1 หน่วย แล้วกลับไปดูเงื่อนไขการวน loop
                        }  // end loop
                   }  // end function printV