วันอังคารที่ 22 กันยายน พ.ศ. 2558

[LAB5-Draft] Average of value in array

def sum_of_value(value):
   count = 0
   sum = 0
   while(count < len(value)):
      if(value[count] >= 0):
         sum = sum + value[count]
      count = count + 1
   return sum

def average(value):
   average = sum_of_value(value) / len(value)
   return average
       
def setup():
   value = [23,25,25,23]
   print(average(value))
 
setup()

[LAB5-Draft] Find of positive value

def show_positive_value(value):
   count = 0
   posNumber = 0
   while(count < len(value)):
      if(value[count] >= 0):
         posNumber = value[count]
         print(posNumber)
      count = count + 1
   return posNumber
     
def setup():
   value = [1,-2,3,4,-5]
   show_positive_value(value)
 
setup()

[LAB5-Draft] Sum of value (Positive)

def sum_of_value(value):
   count = 0
   sum = 0
   while(count < len(value)):
      if(value[count] >= 0):
         sum = sum + value[count]
      count = count + 1
   return sum
     
def setup():
   value = [1,2,3,-4,-5]
   print(sum_of_value(value))
 
setup()

[LAB5-Draft] Sum of value in array

def sum_of_value(value):
   count = 0
   sum = 0
   while(count < len(value)):
      sum = sum + value[count]
      count = count + 1
   return sum
     
def setup():
   value = [1,2,3,4,5]
   print(sum_of_value(value))
 
setup()

[LAB5-Draft] MAXVALUE (LAST)

def find_max_value_index(number):
    count = 0
    Max_Value = 0
    Index_Value = 0
    while(count < len(number)):
        if(number[count] > Max_Value):
            Max_Value = number[count]
        if(number[count] == Max_Value):
            Index_Value = count
        count = count + 1
    return Index_Value
           
def setup():
    number = [-2,6,5,6,3,-5,8,3,5,8]
    print(find_max_value_index(number))

setup()

[LAB5-Draft] MAXVALUE (FIRST)

def find_max_value_index(number):
    count = 0
    Max_Value = 0
    Index_Value = 0
    while(count < len(number)):
        if(number[count] > Max_Value):
            Max_Value = number[count]
        #if(number[count] == Max_Value):
            Index_Value = count
        count = count + 1
    return Index_Value
           
def setup():
    number = [-2,6,5,6,3,-5,8,3,5,8]
    print(find_max_value_index(number))

setup()

[LAB5-Draft] MAXVALUE

def find_max_value(number):
    count = 0
    Max_Value = 0
    while(count < len(number)):
        if(number[count] > Max_Value):
            Max_Value = number[count]
        count = count + 1
    return Max_Value
           
def setup():
    number = [6,5,5,6,5]
    print(find_max_value(number))

setup()

[LAB5-Draft] Display element of array and index

def setup():
    n = [5,8,7,5,3,2,9]
    print(n)
    print("First   =",n[0])
    print("Second  =",n[1])
    print("Third   =",n[2])
    print("Fourth  =",n[3])
    print("Fifth   =",n[4])
    print("sixth   =",n[5])
    print("seventh =",n[6])  

setup()

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

[LAB4X] Sum of integers

def setup():
   display()

def display():
   countNumber = 1
   ansNumber = 0
   maxNumber = 3
   while(countNumber <= maxNumber):
      ansNumber += countNumber
      print("+",countNumber,"   =  ",ansNumber)
      countNumber = countNumber + 1
 
setup()

[LAB4X] GRADE

def setup():
   valScore = 87
   if(valScore >= 80):
      print("Grade A")
   elif(valScore >= 70):
         print("Grade B")
   elif(valScore >= 60):
         print("Grade C")
   elif(valScore >= 50):
         print("Grade D")
   else:
         print("Grade F")
 
setup()

[LAB4X] BMI

def setup():
   weight = 50.0
   height_CM = 180.0
   height_M = 0.0
   main_height = 0.0
   bmi = 0.0
   height_M = height_CM / 100.00
   main_height = height_M * height_M
   bmi = weight / main_height
   print (weight)
   print (height_CM)
   print (height_M)
   print (bmi)
 
setup()

[LAB4X] Sum of prime number

def setup():
   display_sum_prime()

def display_sum_prime():
   countNumber = 0
   primeNumber = countNumber
   maxNumber = 9
   sumNumber = 0
   while(primeNumber <= maxNumber):
      if(check_primeNumber(primeNumber)):
         sumNumber += primeNumber
         print("+",primeNumber,"   =  ",sumNumber)
      primeNumber = primeNumber + 1
 
def check_primeNumber(maxNumber):
   start = 2
   while(start <= maxNumber):
      if(start == maxNumber):
         return True
      if(maxNumber%start == 0):
         return False
      start = start + 1
   return False

setup()

[LAB4X] Multi-table

def setup():
   display_multitable(4)
 
def display_multitable(myNumber):
   startCount = 1
   limitCount = 12
   ansNumber = 0
   while(startCount <= limitCount):
      ansNumber = myNumber * startCount
      print(myNumber,"  X  ",startCount,"  =  ",ansNumber)
      startCount = startCount + 1
     
setup()

[LAB4X] Calculate circumference and area of a circle

import math
def setup():
   rad = 7
   cir = 0
   cir = 2 * math.pi * rad
   A = math.pi * rad * rad
   print(rad)
   print(cir)
   print(A)
 
setup()

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

[LAB 4] SYNTAX ERROR

1.
ERROR!
- This method must return a resuly of type boolean
Cause of Problem
- ลืมกำหนดค่า Return type boolean
FIXED
- ใส่ค่า Return (Boolean)

2.
ERROR!
- Found one too many { character withotua } to match it.
Cause of Problem
- ลืมใส่วง {} อีกขั้นหนึ่ง
FIXED
- ใส่วง {} ให้ถูกต้องงงง

[LAB 4] Loan payment

void setup()
{
  size(600,700);
  loan_Payment(1);
}

float loan_Payment(int year)
{
  background(0);
  int mouth = year*12;
  float money = 5000;
  float percent = 0.12/mouth;
  float interest = percent * money;
  float principal = 0;
  float total_Interest = 0;
  int startMouth = 1;
  float remain_money = money;
  float remain_principal ;
  text("NO"+"       "+"Interest"+"       "+"Principal"+"       "+"Unpaid Balance"+"       "+"total interest to date",width/6,height/14);
  principal = money * (percent/(1-pow(1+percent,-mouth))) ;
  remain_principal = principal;
  while(startMouth <= mouth)
  {
    total_Interest += interest ;
    remain_principal = principal - interest ;
    remain_money -= remain_principal ;
    interest = remain_money * percent ;
    text(nf(startMouth,2)+"          "+nf(interest,2,2)+"         "+nf(remain_principal,3,2)+"               "+nf(remain_money,4,2)+"                     "+nf(total_Interest,3,2),width/6,(startMouth*50)+height/14);
    startMouth++;
  }
    if(remain_money <= 0)
    {
      remain_money = 0;
    }
    return total_Interest;
}

[LAB 4] Sum of prime numbers (Use Boolean Function)

void setup()
{
  size(500,500);
}

int countNumber = 0;
int maxNumber = 56;
int primeNumber = countNumber;
int count =0;
int sumNumber = 0;
void draw()
{
  background(0);
  while(primeNumber <= maxNumber)
  {
  if(check_primeNumber(primeNumber))
    {
      sumNumber += primeNumber;
    }
      primeNumber++;
  }
  textSize(25);
  text(countNumber,width/4,height/4);
  text(maxNumber,width/4,3*(height/4));
  textSize(60);
  text(sumNumber,3*(width/5),height/2);
}

boolean check_primeNumber(int maxNumber)
{
  int start = 2;
  while(start <= maxNumber)
    {
      if(start == maxNumber)
      {
        return true;
      }
      if(maxNumber%start == 0)
      {
        return false;
      }
      start++;
    }
    return false;
}

[LAB 4] Display multiplication table

void setup()
{
  size(500,700);
}

void draw()
{
  background(0);
  show_display();
}


void show_display()
{
  int myNumber = 3;
  int startCount = 1;
  int maxCount = 12;
  int ansNumber = 0;
  while(startCount <= maxCount)
  {
    ansNumber = myNumber * startCount ;
    text(myNumber+"   X   "+startCount+"   =   "+ansNumber,50,startCount*50);
    startCount++;
  }
}

[LAB 4] Calculate Sum of integers

void setup()
{
  size(500,500);
  frameRate(0.7);
}

void draw()
{
  background(0);
  display_Addition();
}

void display_Addition()
{
  int countNumber = 1;
  int ansNumber = 0;
  int maxNumber = frameCount;
  int text_plus = 3*(width/4);
  while(countNumber <= maxNumber)
  {
    ansNumber += countNumber ;
    countNumber++;
  }
  textSize(40);
  text("+"+maxNumber,text_plus,text_plus);
  text("ANSWER : "+ansNumber,width/4,height/2);
}

[LAB 4] METRO

void setup()
{
  size(500,500);
  frameRate(30);
}

void draw()
{
  background(255);
  float count = 1;
  float moveX = 0;
  float moveY = 0;
  float picSize = 300;
  while(count < 4)
  {
    moveX = mouseX+(count*140)-175;
    moveY = random(50)+(count*90)-100;
    draw_Logo(moveX ,moveY ,picSize );
    count++;
  }
}

void draw_Logo(float posX ,float posY ,float picSize )
{
  float scale = picSize / 500 ;
  strokeWeight(scale * 15);
  noFill();
  ellipse(scale * 250+posX,scale * 300+posY,scale * 100,scale * 100);
  fill(255);
  stroke(255);
  rect(scale * 0+posX,scale * 249+posY,scale * 500,scale * 18);
  stroke(0);
  line(scale * 200+posX,scale * 230+posY,scale * 235+posX,scale * 180+posY); // MLeft
  line(scale * 200+posX,scale * 230+posY,scale * 160+posX,scale * 175+posY);
  line(scale * 159+posX,scale * 175+posY,scale * 159+posX,scale * 300+posY);
  line(scale * 265+posX,scale * 180+posY,scale * 300+posX,scale * 230+posY); // MRight
  line(scale * 300+posX,scale * 230+posY,scale * 340+posX,scale * 175+posY);
  line(scale * 340+posX,scale * 175+posY,scale * 340+posX,scale * 300+posY);
  stroke(#FF0000);
  line(scale * 240+posX,scale * 300+posY,scale * 240+posX,scale * 100+posY); //line Left
  line(scale * 260+posX,scale * 300+posY,scale * 260+posX,scale * 100+posY); //line Right
  line(scale * 240+posX,scale * 100+posY,scale * 215+posX,scale * 80+posY); //Head
  line(scale * 215+posX,scale * 80+posY,scale * 240+posX,scale * 50+posY);
  strokeWeight(scale * 6);
  point(scale * 230+posX,scale * 45+posY);
  point(scale * 225+posX,scale * 50+posY);
  point(scale * 221+posX,scale * 55+posY);
}

[LAB 4] PLAYBOY

void setup()
{
  size(500,500);
  frameRate(30);
}


void draw()
{
  background(255);
  int startCount = 0;
  int endCount = 2;
  int moveX = 0;
  int moveY = 0;
  float picSize = 200;
  while(startCount <= endCount)
  {
    moveX = startCount*150;
    draw_rabbit(moveX,moveY,picSize,random(255));
    startCount++;
  }
}

void draw_rabbit(int posX ,int posY ,float picSize , float random_color )
{
  float scale = picSize / 500;
  noStroke();
  fill(random_color);
  ellipse(scale * 270+posX,scale * 300+posY,scale * 250,scale * 180); //Face
  ellipse(scale * 320+posX,scale * 430+posY,scale * 250,scale * 200); //Throat
  //fill(255);
  //triangle(scale * 500,scale * -750,scale * 500,scale * 500,scale * 350,scale * 500); //blockbackground
  fill(random_color);                             //ribbon
  stroke(255);                        //ribbon
  strokeWeight(5);                  //ribbon
  triangle(scale * 180+posX,scale * 480+posY,scale * 250+posX,scale * 440+posY,scale * 240+posX,scale * 500+posY); //ribbon
  //line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 350+posY);              //ribbon
  //line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 390+posY);              //ribbon
  noStroke();
  triangle(scale * 230+posX,scale * 480+posY,scale * 175+posX,scale * 450+posY,scale * 175+posX,scale * 490+posY);   //ribbon
  fill(255);
  ellipse(scale * 240+posX,scale * 260+posY,scale * 50,scale * 50); //Eye
  fill(random_color);
  ellipse(scale * 360+posX,scale * 200+posY,scale * 50,scale * 300); //EarLeft
  ellipse(scale * 320+posX,scale * 200+posY,scale * 50,scale * 300); //EarRight
}

[LAB 4] Pirate

void setup()
{
size(500,500);
frameRate(27);
}

void draw_Pirate(int posX,int posY ,float picSize)
{
float scale = picSize / 500 ;
noStroke();
fill(255);
rect(scale * 50+posX,scale * 50+posY,scale * 400,scale * 400); //Face
strokeWeight(5);
stroke(0);
line(scale * 50+posX,scale * 300+posY,scale * 250+posX,scale * 50+posY); //Blindfolds
strokeWeight(1);
fill(0);
rect(scale * 120+posX,scale * 125+posY,scale * 80,scale * 80); //EyeLeft
rect(scale * 300+posX,scale * 125+posY,scale * 80,scale * 80); //EyeRight
fill(255);
ellipse(scale * 340+posX,scale * 165.5+posY,scale * 30,scale * 30);
fill(0);
rect(scale * 220+posX,scale * 200+posY,scale * 50,scale * 100); //Nose
rect(scale * 120+posX,scale * 350+posY,scale * 250,scale * 50); //Mouth
fill(255);
rect(scale * 120+posX,scale * 350+posY,scale * 25,scale * 25);//Teeth
rect(scale * 145+posX,scale * 350+posY,scale * 25,scale * 25); //Teeth
rect(scale * 195+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 345+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 120+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 145+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 170+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 270+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 375+posY,scale * 25,scale * 25); //teeth
}


void draw()
{
  background(#DF013A);
  int startUnit = 0;
  int endUnit = 10;
  int posX =250;
  int posY =200;
  int scale = 75;
  while(startUnit <= endUnit)
  {
    posX = (mouseX/4)*startUnit;
    draw_Pirate(posX,posY,scale);
    startUnit++;
  }
}

[LAB 4] Flocks of Birds

int flying_bird;
void setup()
{
  size(500,500);
}

void draw()
{
  int countBird = 0;
  int unitBird = 3;
  int xContral = mouseX;
  int yContral = mouseY;
  background(255);
  if(frameCount%10 < 5)
  {
    flying_bird = 30;
  }
  else
  {
    flying_bird = -30;
  }
  while(countBird < unitBird)
  {
    xContral = mouseX+(countBird*100)+100;
    yContral = (countBird*150)+100;
    draw_BodyBird(xContral,yContral);
    countBird++;
  }
}

void draw_BodyBird(int xContral ,int yContral)
{
  int sizeBody = 100;
  int xMouth1 = 0;
  int yMouth1 = 55;
  int xMouth2 = -25;
  int yMouth2 = 5;
  int xMouth3 = 25;
  int yMouth3 = 5;
  int xEyeL = -25;
  int yEyeL = -25;
  int xEyeR = 25;
  int yEyeR = -25;
  int sizeEye =50;
  int length_Fly = 100;
  line(xContral,yContral,xContral +length_Fly ,flying_bird+yContral);
  line(xContral,yContral,xContral -length_Fly ,flying_bird+yContral);
  strokeWeight(1);
  fill(0);
  ellipse(xContral,yContral,sizeBody,sizeBody);
  fill(#FFF92C);
  triangle(xContral,yMouth1+yContral,xMouth2+xContral,yMouth2+yContral,xMouth3+xContral,yMouth3+yContral);
  fill(255);
  ellipse(xEyeL+xContral,yEyeL+yContral,sizeEye,sizeEye);
  fill(255);
  ellipse(xEyeR+xContral,yEyeR+yContral,sizeEye,sizeEye);
  strokeWeight(5);
  point(xEyeL+xContral,yEyeL+yContral);
  point(xEyeR+xContral,yEyeR+yContral);
}

[LAB 4] Balloons

void setup()
{
  size(300,300);
  frameRate(27);
}

void draw()
{
  background(255);
  int posX = mouseX;
  int posY = mouseY;
  int countBalloon = 0;
  int unitBalloon = 3;
  int range = 1;
  if(mouseButton == LEFT)
  {
  while(countBalloon < unitBalloon)
  {
    posX = countBalloon*75+50;
    draw_ballon(posX ,posY ,75);
    countBalloon++;
  }
  }
  if(mouseButton == RIGHT)
  {
    while(countBalloon < unitBalloon)
    {
      int moveY = frameCount;
      posX = (countBalloon*75)+50;
      posY = mouseY+(-moveY);
      if(posY < 0)
      {
        posY = 0;
      }
      draw_ballon(posX ,posY ,75);
      countBalloon++;
    }
  }
}
void draw_ballon(int posX ,int posY ,int radius )
{
  fill(#FC0000);
  line(posX,posY,posX,100+posY);
  ellipse(posX,posY,radius,radius);
}

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

[LAB3] DeliveryCharge

void setup()
{
  size(300,300);
  background(0);
  boolean type_Package = true;
  int day_Priority = 1;
  int day_Standard = 2;
  int twoDay = 3;
  int choiceDay = twoDay;
  float charge = 0;
  float weight =8;
  if(type_Package)
  {
    if(choiceDay == day_Priority)
    {
      if(weight >= 8)
      {
        charge = 12;
      }
    }
    else if(choiceDay == day_Standard)
    {
      if(weight >= 8)
      {
        charge = 10.50;
      }
    }
    else if(choiceDay == twoDay)
    {
      textSize(24);
      text("Not Available",width/3,height-20);
      textSize(12);
    }
  }
  else
  {
    if(choiceDay == day_Priority)
    {
      charge = AddPriority(weight);
    }
    else if(choiceDay == day_Standard)
    {
      charge = AddStandard(weight);
    }
    else if(choiceDay == twoDay)
    {
      charge = AddtwoDay(weight);
    }
  }

  if(type_Package)
  {
    text("Your Package type is LETTER",width/3,height/4);
  }
  else
  {
    text("Your Package type is BOX",width/3,height/4);
  }

  if(choiceDay == day_Priority)
  {
    text("Next Day Priority",width/3,height/2);
  }
  else if(choiceDay == day_Standard)
  {
    text("Next Day Standard",width/3,height/2);
  }
  else if(choiceDay == twoDay)
  {
    text("2-DAY",width/3,height/2);
  }
  text("Charge = $"+charge,width/3,height*0.75);
}

float AddPriority(float weight)
{
  float Pcharge = 15.75 ;
  if(weight > 1.00)
  {
    float weightTrue = weight - 1 ;
    float add = weightTrue * 1.25 ;
    Pcharge = Pcharge + add ;
  }
  return Pcharge ;
}

float AddStandard(float weight)
{
  float Scharge = 13.75 ;
  if(weight > 1.00)
  {
    float weightTrue = weight - 1 ;
    float add = weightTrue * 1.00 ;
    Scharge = Scharge + add ;
  }
  return Scharge ;
}

float AddtwoDay(float weight)
{
  float TDcharge = 7.00;
  if(weight > 1.00)
  {
    float weightTrue = weight - 1 ;
    float add = weightTrue * 1.00 ;
    TDcharge = TDcharge + add ;
  }
  return TDcharge ;
}

[LAB 3] Syntex ERROR ~!

1.
ERROR!
           Found one too many { characters without a } to match it.

Cause of problems
           ใส่ { } ไม่ถูกต้อง

How you fixed it
           แก้ใส่ {} ให้ถูกต้อง

2.
ERROR!
            The method value_leapyear(int) int the type [namefile] is not applicable for the arguments()

Cause of problems
            ไม่ได้กำหนดตัวแปรของค่า int

How you fixed it
            แก้ไข เรากำหนดตัวแปรเป็นค่า int เอง



วันศุกร์ที่ 4 กันยายน พ.ศ. 2558

[LAB3] METROMUSIC

void setup()
{
  size(500,500);
  frameRate(30);
}

void draw()
{
  int posX = 0;
  int posY = 0;
  if(key == 'a')
  {
    posX = posX - 100;
  }
  else if(key == 'd')
  {
    posX = posX + 100;
  }
  else if(key == 'w')
  {
    posY = posY - 100;
  }
  else if(key == 's')
  {
    posY = posY + 100;
  }
  draw_Logo(posX,posY,300);
}
void draw_Logo(int posX ,int posY ,float picSize )
{
  float scale = picSize / 500 ;
  background(255);
  strokeWeight(scale * 15);
  noFill();
  ellipse(scale * 250+posX,scale * 300+posY,scale * 100,scale * 100);
  fill(255);
  stroke(255);
  rect(scale * 0+posX,scale * 249+posY,scale * 500,scale * 18);
  stroke(0);
  line(scale * 200+posX,scale * 230+posY,scale * 235+posX,scale * 180+posY); // MLeft
  line(scale * 200+posX,scale * 230+posY,scale * 160+posX,scale * 175+posY);
  line(scale * 159+posX,scale * 175+posY,scale * 159+posX,scale * 300+posY);
  line(scale * 265+posX,scale * 180+posY,scale * 300+posX,scale * 230+posY); // MRight
  line(scale * 300+posX,scale * 230+posY,scale * 340+posX,scale * 175+posY);
  line(scale * 340+posX,scale * 175+posY,scale * 340+posX,scale * 300+posY);
  stroke(#FF0000);
  line(scale * 240+posX,scale * 300+posY,scale * 240+posX,scale * 100+posY); //line Left
  line(scale * 260+posX,scale * 300+posY,scale * 260+posX,scale * 100+posY); //line Right
  line(scale * 240+posX,scale * 100+posY,scale * 215+posX,scale * 80+posY); //Head
  line(scale * 215+posX,scale * 80+posY,scale * 240+posX,scale * 50+posY);
  strokeWeight(scale * 6);
  point(scale * 230+posX,scale * 45+posY);
  point(scale * 225+posX,scale * 50+posY);
  point(scale * 221+posX,scale * 55+posY);
  println("METROMUSICCENTER");
}

[LAB3] PLAYBOY

void setup()
{
  size(500,500);
  frameRate(30);
}


void draw()
{
  int posX = 1;
  if(keyCode == RIGHT)
  {
    posX = posX + 100;
  }
  if(keyCode == LEFT)
  {
    posX = posX - 100;
  }
  draw_rabbit(posX,0,300);
}

void draw_rabbit(int posX ,int posY ,float picSize )
{
  float scale = picSize / 500;
  background(255);
  noStroke();
  fill(0);
  ellipse(scale * 270+posX,scale * 300+posY,scale * 250,scale * 180); //Face
  ellipse(scale * 320+posX,scale * 430+posY,scale * 250,scale * 200); //Throat
  fill(255);
  //triangle(scale * 500,scale * -750,scale * 500,scale * 500,scale * 350,scale * 500); //blockbackground
  fill(0);                             //ribbon
  stroke(255);                        //ribbon
  strokeWeight(5);                  //ribbon
  triangle(scale * 180+posX,scale * 480+posY,scale * 250+posX,scale * 440+posY,scale * 240+posX,scale * 500+posY); //ribbon
  //line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 350+posY);              //ribbon
  //line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 390+posY);              //ribbon
  noStroke();
  triangle(scale * 230+posX,scale * 480+posY,scale * 175+posX,scale * 450+posY,scale * 175+posX,scale * 490+posY);   //ribbon
  fill(255);
  ellipse(scale * 240+posX,scale * 260+posY,scale * 50,scale * 50); //Eye
  fill(0);
  ellipse(scale * 360+posX,scale * 200+posY,scale * 50,scale * 300); //EarLeft
  ellipse(scale * 320+posX,scale * 200+posY,scale * 50,scale * 300); //EarRight
}

[LAB3] PIRATE

void setup()
{
size(500,500);
frameRate(27);
}

void draw_Pirate(int posX,int posY ,float picSize)
{
float scale = picSize / 500 ;
noStroke();
background(#DF013A);
fill(255);
rect(scale * 50+posX,scale * 50+posY,scale * 400,scale * 400); //Face
strokeWeight(5);
stroke(0);
line(scale * 50+posX,scale * 300+posY,scale * 250+posX,scale * 50+posY); //Blindfolds
strokeWeight(1);
fill(0);
rect(scale * 120+posX,scale * 125+posY,scale * 80,scale * 80); //EyeLeft
rect(scale * 300+posX,scale * 125+posY,scale * 80,scale * 80); //EyeRight
fill(255);
ellipse(scale * 340+posX,scale * 165.5+posY,scale * 30,scale * 30);
fill(0);
rect(scale * 220+posX,scale * 200+posY,scale * 50,scale * 100); //Nose
rect(scale * 120+posX,scale * 350+posY,scale * 250,scale * 50); //Mouth
fill(255);
rect(scale * 120+posX,scale * 350+posY,scale * 25,scale * 25);//Teeth
rect(scale * 145+posX,scale * 350+posY,scale * 25,scale * 25); //Teeth
rect(scale * 195+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 345+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 120+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 145+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 170+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 270+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 375+posY,scale * 25,scale * 25); //teeth
}

float setSize = 1;
void draw()
{
  draw_Pirate(mouseX,mouseY,setSize);
  if(mouseButton == LEFT)
  {
    setSize++ ;
  }
  else if(mouseButton == RIGHT)
  {
    setSize-- ;
  }
  text(setSize,width*0.9,height*0.9);
}



[LAB3] LEAPYEAR

void setup()
{
  size(500,500);
  background(0);
  textSize(30);
  value_leapYear(1800);
}

void value_leapYear(int year)
{
  text("Year = "+year,width/3,height/3);
  if(year%4 == 0 && year%100 != 0)
  {
    text("LEAPYEA!",width/3,height/2);
  }
  else
  {
    text("NOT LEAPYEAR !",width/3,height/2);
  }
}

[LAB3] POWER OF 10

void setup()
{
  size(500,500);
  background(0);
  textSize(20);
  valuePower(10);
}

void valuePower(int number_Exponent)
{
  text("Power of 10 = "+number_Exponent,width/3,height/3);
  if(number_Exponent == 6)
  {
    text("Word Number is Million",width/3,height/2);
  }
  else if(number_Exponent == 9)
  {
    text("Word Number is Billion",width/3,height/2);
  }
  else if(number_Exponent == 12)
  {
    text("Word Number is Trillion",width/3,height/2);
  }
  else if(number_Exponent == 15)
  {
    text("Word Number is Quadrillion",width/3,height/2);
  }
  else if(number_Exponent == 18)
  {
    text("Word Number is Quintillion",width/3,height/2);
  }
  else if(number_Exponent == 21)
  {
    text("Word Number is Sextillion",width/3,height/2);
  }
  else if(number_Exponent == 30)
  {
    text("Word Number is Nonillion",width/3,height/2);
  }
  else if(number_Exponent == 100)
  {
    text("Word Number is googol",width/3,height/2);
  }
  else
  {
    text("ERROR!",width/3,height/2);
  }
}

วันพุธที่ 2 กันยายน พ.ศ. 2558

[LAB3] FlyingBird

int flying_bird;
void setup()
{
  size(500,500);
}

void draw()
{
  background(255);
  if(frameCount%10 < 5)
  {
    flying_bird = 30;
  }
  else
  {
    flying_bird = -30;
  }
  draw_BodyBird(mouseX,mouseY);
}

void draw_BodyBird(int xContral ,int yContral)
{
  int sizeBody = 100;
  int xMouth1 = 0;
  int yMouth1 = 55;
  int xMouth2 = -25;
  int yMouth2 = 5;
  int xMouth3 = 25;
  int yMouth3 = 5;
  int xEyeL = -25;
  int yEyeL = -25;
  int xEyeR = 25;
  int yEyeR = -25;
  int sizeEye =50;
  int length_Fly = 100;
  line(xContral,yContral,xContral +length_Fly ,flying_bird+mouseY);
  line(xContral,yContral,xContral -length_Fly ,flying_bird+mouseY);
  strokeWeight(1);
  fill(0);
  ellipse(xContral,yContral,sizeBody,sizeBody);
  fill(#FFF92C);
  triangle(xContral,yMouth1+yContral,xMouth2+xContral,yMouth2+yContral,xMouth3+xContral,yMouth3+yContral);
  fill(255);
  ellipse(xEyeL+xContral,yEyeL+yContral,sizeEye,sizeEye);
  fill(255);
  ellipse(xEyeR+xContral,yEyeR+yContral,sizeEye,sizeEye);
  strokeWeight(5);
  point(xEyeL+xContral,yEyeL+yContral);
  point(xEyeR+xContral,yEyeR+yContral);
}

วันอังคารที่ 1 กันยายน พ.ศ. 2558

[LAB3] Battery Charge/Discharge

void setup()
{
  size(500,500);
  frameRate(15);
  background(0);
}

void draw_Electrode(int posX , int posY)
{
int xAnode = 380;
int yAnode = 235;
int xAnode2 = 370;
int yAnode2 = 245;
int xCathode = 100;
int yCathode = 245;
int xSizeanode = 10;
int ySizeanode = 30;
int xSizenode =30;
int ySizenode =10;
  noStroke(); //noline
  fill(#FF0000); //red
  rect(xAnode+posX,yAnode+posY, xSizeanode,ySizeanode); //anode
  rect(xAnode2+posX,yAnode2+posY,xSizenode,ySizenode);
  rect(xCathode+posX,yCathode+posY,xSizenode,ySizenode); //cathode
}

void draw_battery (int posX , int posY)
{
int xBig = 100;
int yBig = 200;
int xSizebig = 300;
int ySizebig = 100;
int xSmall = 400;
int ySmall = 240;
int Sizesmall =20;
  stroke(255); //linewrite
  strokeWeight(4);
  fill(#D8D8D8);
  rect(xBig+posX,yBig+posY,xSizebig,ySizebig); //rect BIG
  fill(#D8D8D8);
  rect(xSmall+posX,ySmall+posY,Sizesmall,Sizesmall); // rect SMALL
}

void draw_energy(int incX , int incY)
{
int xEnergy = 100;
int yEnergy = 200;
  fill(#FE2E2E);
  rect(xEnergy,yEnergy,incX,incY);
}

int incX=0;
void draw()
{
int xText = 250;
int yText = 350;

  draw_battery(0,0);
  draw_energy(incX,100);
  if(key == 'a')
  {
    incX = incX+7;
    text("Charge",xText,yText);
    if(incX > 300)
    {
      incX = 300;
    }
  }
  else if(key == 'b')
  {
    incX = incX-7;
    text("Discharge",xText,yText);
    if(incX < 0)
    incX = 0;
  }
  draw_Electrode(0,0);
}