Assignment 2
https://www.youtube.com/watch?v=PaVoRsUDegw&feature=youtu.be
วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558
วันอังคารที่ 24 พฤศจิกายน พ.ศ. 2558
class Student:
def __init__(self,Name,ID,score):
self.name=Name
self.id=ID
self.score=score
def display(self):
print(' '+self.name+' ',self.id,'',self.score)
def get_score(self):
return self.score
def set_score(self,s):
self.score=s
def findGrade(std):
grade=''
score=std.get_score()
if(score >= 80):
grade='A'
elif(score >= 70):
grade='B'
elif(score >= 60):
grade='C'
elif(score >= 50):
grade='D'
else:
grade='F'
return grade
def countGrade(grade,std):
count=0
i=0
while(i<len(std)):
if(findGrade(std[i])== grade):
count+=1
i+=1
return count
def showallgrade(std):
i=0
while(i<len(std)):
std[i].display()
print(findGrade(std[i]))
i+=1
def setup():
std = [Student('top',1,58),
Student('tape',2,80),
Student('tar',3,70),
Student('Q',4,85),
Student('bass',5,50)]
'''std[0].display()'''
findGrade(std[0])
print('countGrade',countGrade('A',std))
print()
showallgrade(std)
setup()
def __init__(self,Name,ID,score):
self.name=Name
self.id=ID
self.score=score
def display(self):
print(' '+self.name+' ',self.id,'',self.score)
def get_score(self):
return self.score
def set_score(self,s):
self.score=s
def findGrade(std):
grade=''
score=std.get_score()
if(score >= 80):
grade='A'
elif(score >= 70):
grade='B'
elif(score >= 60):
grade='C'
elif(score >= 50):
grade='D'
else:
grade='F'
return grade
def countGrade(grade,std):
count=0
i=0
while(i<len(std)):
if(findGrade(std[i])== grade):
count+=1
i+=1
return count
def showallgrade(std):
i=0
while(i<len(std)):
std[i].display()
print(findGrade(std[i]))
i+=1
def setup():
std = [Student('top',1,58),
Student('tape',2,80),
Student('tar',3,70),
Student('Q',4,85),
Student('bass',5,50)]
'''std[0].display()'''
findGrade(std[0])
print('countGrade',countGrade('A',std))
print()
showallgrade(std)
setup()
ลอง run A1 on web but ไม่ทำงาน
scartch it easy to learn programing
scartch it easy to learn programing
วันอาทิตย์ที่ 15 พฤศจิกายน พ.ศ. 2558
Lab 8 - JAVA
public class Letter {
private String[] T={"######"," # "," # "," # "," # "," # "};
private String[] O={"######","# #","# #","# #","# #","######"};
private String[] P={"######","# #","######","# ","# ","# "};
private String[][] data={T,O,P};
private String word;
private char cha;
public Letter(String word,char cha){
this.word=word;
this.cha=cha;
this.data=data;
}
public void changcha(){
int i=0;
while(i<data.length){
int j=0;
while(j<data[0].length){
data[i][j]=data[i][j].replace('#',cha);
j+=1;
}
i+=1;
}
}
public void display(){
int i=0;
while(i<6){
int j=0;
while(j<word.length()){
if(word.charAt(j)=='T'){
System.out.print(this.data[0][i]);
System.out.print(" ");
}else if(word.charAt(j)=='O'){
System.out.print(this.data[1][i]);
System.out.print(" ");
}else if(word.charAt(j)=='P'){
System.out.print(this.data[2][i]);
System.out.print(" ");
}
j+=1;
}
System.out.println("");
i+=1;
}
}
public static void main(String[] args) {
//String[] word=;
Letter a=new Letter("TOP",'@');
a.changcha();
a.display();
//a.display();
}
}
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
package fffff;
public class Student{
private String name;
private int id;
private int age;
private float weight;
private float height;
private float bmi;
public Student(String name,int id,int age ,float weight,float height){
this.name=name;
this.id=id;
this.age=age;
this.weight=weight;
this.height=height;
}
public void display(){
System.out.print(" "+this.name);
System.out.print(" "+this.id);
System.out.print(" "+this.age);
System.out.print(" "+this.weight);
System.out.println(" "+this.height);
}
public float bmi_st(){
bmi=cal_bmi(weight,height);
this.bmi=bmi;
return bmi;
}
public String get_name(){
return this.name;
}public int get_id(){
return this.id;
}public int get_age(){
return this.age;
}public float get_weight(){
return this.weight;
}public float get_height(){
return this.height;
}public float get_bmi(){
return this.bmi;
}
public static void main(String arg[]){
Student[] std={new Student("top",91,21,80,178),
new Student("tape",32,32,50,175),
new Student("tar",55,18,30,175)};
display(std);
std_bmi(std);
int indexbmi=25;
int countbmi=bmi_morethan(std,indexbmi);
System.out.println(countbmi);
System.out.print(average_st(std));
int indexage=30;
int countage=age_lessthan(std,indexage);
System.out.println(countage);
float mini=minimum_weight(std);
System.out.println(mini);
int indexweight=50;
int countweight=weight_lessthan(std,indexweight);
System.out.println(countweight);
displaylessthan(std,indexweight);
}
public static void display(Student[] s){
int i=0;
while(i<s.length){
s[i].display();
i+=1;
}
}
public static void std_bmi(Student[] s){
int i=0;
while(i<s.length){
s[i].bmi_st();
i+=1;
}
}
public static float cal_bmi(float w,float h){
float bmi=0;
h=h/100;
bmi=w/(h*h);
return bmi;
}
public static int bmi_morethan(Student[] s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_bmi()>max){
s[i].display();
count+=1;
}
i+=1;
}
return count;
}
public static int average_st(Student[] s){
int i=0;
int sum=0;
while(i<s.length){
sum=sum+s[i].get_age();
i+=1;
}
sum=sum/s.length;
return sum;
}
public static int age_lessthan(Student[]s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_age()<max){
count+=1;
}
i+=1;
}
return count;
}
public static float minimum_weight(Student[] s){
int i=1;
float mini=s[0].get_weight();
while(i<s.length){
if(s[i].get_weight()<mini){
mini=s[i].get_weight();
}
i+=1;
}
return mini;
}
public static int weight_lessthan(Student[] s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_weight()<max){
count+=1;
}
i+=1;
}
return count;
}
public static void displaylessthan(Student[] s,int max){
int i=0;
while(i<s.length){
if(s[i].get_weight()<max){
s[i].display();
}
i+=1;
}
}}
private String[] T={"######"," # "," # "," # "," # "," # "};
private String[] O={"######","# #","# #","# #","# #","######"};
private String[] P={"######","# #","######","# ","# ","# "};
private String[][] data={T,O,P};
private String word;
private char cha;
public Letter(String word,char cha){
this.word=word;
this.cha=cha;
this.data=data;
}
public void changcha(){
int i=0;
while(i<data.length){
int j=0;
while(j<data[0].length){
data[i][j]=data[i][j].replace('#',cha);
j+=1;
}
i+=1;
}
}
public void display(){
int i=0;
while(i<6){
int j=0;
while(j<word.length()){
if(word.charAt(j)=='T'){
System.out.print(this.data[0][i]);
System.out.print(" ");
}else if(word.charAt(j)=='O'){
System.out.print(this.data[1][i]);
System.out.print(" ");
}else if(word.charAt(j)=='P'){
System.out.print(this.data[2][i]);
System.out.print(" ");
}
j+=1;
}
System.out.println("");
i+=1;
}
}
public static void main(String[] args) {
//String[] word=;
Letter a=new Letter("TOP",'@');
a.changcha();
a.display();
//a.display();
}
}
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
package fffff;
public class Student{
private String name;
private int id;
private int age;
private float weight;
private float height;
private float bmi;
public Student(String name,int id,int age ,float weight,float height){
this.name=name;
this.id=id;
this.age=age;
this.weight=weight;
this.height=height;
}
public void display(){
System.out.print(" "+this.name);
System.out.print(" "+this.id);
System.out.print(" "+this.age);
System.out.print(" "+this.weight);
System.out.println(" "+this.height);
}
public float bmi_st(){
bmi=cal_bmi(weight,height);
this.bmi=bmi;
return bmi;
}
public String get_name(){
return this.name;
}public int get_id(){
return this.id;
}public int get_age(){
return this.age;
}public float get_weight(){
return this.weight;
}public float get_height(){
return this.height;
}public float get_bmi(){
return this.bmi;
}
public static void main(String arg[]){
Student[] std={new Student("top",91,21,80,178),
new Student("tape",32,32,50,175),
new Student("tar",55,18,30,175)};
display(std);
std_bmi(std);
int indexbmi=25;
int countbmi=bmi_morethan(std,indexbmi);
System.out.println(countbmi);
System.out.print(average_st(std));
int indexage=30;
int countage=age_lessthan(std,indexage);
System.out.println(countage);
float mini=minimum_weight(std);
System.out.println(mini);
int indexweight=50;
int countweight=weight_lessthan(std,indexweight);
System.out.println(countweight);
displaylessthan(std,indexweight);
}
public static void display(Student[] s){
int i=0;
while(i<s.length){
s[i].display();
i+=1;
}
}
public static void std_bmi(Student[] s){
int i=0;
while(i<s.length){
s[i].bmi_st();
i+=1;
}
}
public static float cal_bmi(float w,float h){
float bmi=0;
h=h/100;
bmi=w/(h*h);
return bmi;
}
public static int bmi_morethan(Student[] s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_bmi()>max){
s[i].display();
count+=1;
}
i+=1;
}
return count;
}
public static int average_st(Student[] s){
int i=0;
int sum=0;
while(i<s.length){
sum=sum+s[i].get_age();
i+=1;
}
sum=sum/s.length;
return sum;
}
public static int age_lessthan(Student[]s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_age()<max){
count+=1;
}
i+=1;
}
return count;
}
public static float minimum_weight(Student[] s){
int i=1;
float mini=s[0].get_weight();
while(i<s.length){
if(s[i].get_weight()<mini){
mini=s[i].get_weight();
}
i+=1;
}
return mini;
}
public static int weight_lessthan(Student[] s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_weight()<max){
count+=1;
}
i+=1;
}
return count;
}
public static void displaylessthan(Student[] s,int max){
int i=0;
while(i<s.length){
if(s[i].get_weight()<max){
s[i].display();
}
i+=1;
}
}}
วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558
Lab 7 studen
class Student:
def __init__(self,name,id,age,weight,height,bmi):
self.name=name
self.id=id
self.age=age
self.weight=weight
self.height=height
self.bmi=bmi
def display(self):
print("Name:",self.name,end=" ")
print("ID:",self.id,end=" ")
print("Age:",self.age,end=" ")
print("Weight:",self.weight,end=" ")
print("Height:",self.height,end=" ")
def bmi_st(self):
bmi=cal_bmi(self.weight,self.height)
self.bmi=bmi
return bmi
def get_name(self):
return self.name
def get_id(self):
return self.id
def get_age(self):
return self.age
def get_weight(self):
return self.weight
def get_height(self):
return self.height
def get_bmi(self):
return self.bmi
def set_bmi(self,bmi):
self.bmi=bmi
def setup():
std=[Student('top',91,21,30,178,0),
Student('tape',32,32,50,175,0),
Student('tar',55,18,49,175,0)]
#display(std)
#std_bmi(std)
#indexbmi=25
#countbmi=bmi_morethan(std,indexbmi)
#print(countbmi)
#average_st(std)
#indexage=30
#countage=age_lessthan(std,indexage)
#print(countage)
#mini=minimum_weight(std)
#print(mini)
#ndexweight=50
#countweight=weight_lessthan(std,indexweight)
#print(countweight)
#displaylessthan(std,indexweight)
def display(s):
i=0
while(i<len(s)):
s[i].display()
print("")
i+=1
def std_bmi(s):
i=0
while(i<len(s)):
s[i].bmi_st()
i+=1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def bmi_morethan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_bmi()>max):
print(s[i].get_name())
count+=1
i+=1
return count
def average_st(s):
i=0
sum=0
while(i<len(s)):
sum=sum+s[i].get_age()
i+=1
sum=sum/len(s)
return sum
def age_lessthan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_age()<max):
count+=1
i+=1
return count
def minimum_weight(s):
i=1
mini=s[0].get_weight()
while(i<len(s)):
if(s[i].get_weight()<mini):
mini=s[i].get_weight()
i+=1
return mini
def weight_lessthan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_weight()<max):
count+=1
i+=1
return count
def displaylessthan(s,max):
i=0
while(i<len(s)):
if(s[i].get_weight()<max):
print(s[i].get_name())
i+=1
setup()
def __init__(self,name,id,age,weight,height,bmi):
self.name=name
self.id=id
self.age=age
self.weight=weight
self.height=height
self.bmi=bmi
def display(self):
print("Name:",self.name,end=" ")
print("ID:",self.id,end=" ")
print("Age:",self.age,end=" ")
print("Weight:",self.weight,end=" ")
print("Height:",self.height,end=" ")
def bmi_st(self):
bmi=cal_bmi(self.weight,self.height)
self.bmi=bmi
return bmi
def get_name(self):
return self.name
def get_id(self):
return self.id
def get_age(self):
return self.age
def get_weight(self):
return self.weight
def get_height(self):
return self.height
def get_bmi(self):
return self.bmi
def set_bmi(self,bmi):
self.bmi=bmi
def setup():
std=[Student('top',91,21,30,178,0),
Student('tape',32,32,50,175,0),
Student('tar',55,18,49,175,0)]
#display(std)
#std_bmi(std)
#indexbmi=25
#countbmi=bmi_morethan(std,indexbmi)
#print(countbmi)
#average_st(std)
#indexage=30
#countage=age_lessthan(std,indexage)
#print(countage)
#mini=minimum_weight(std)
#print(mini)
#ndexweight=50
#countweight=weight_lessthan(std,indexweight)
#print(countweight)
#displaylessthan(std,indexweight)
def display(s):
i=0
while(i<len(s)):
s[i].display()
print("")
i+=1
def std_bmi(s):
i=0
while(i<len(s)):
s[i].bmi_st()
i+=1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def bmi_morethan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_bmi()>max):
print(s[i].get_name())
count+=1
i+=1
return count
def average_st(s):
i=0
sum=0
while(i<len(s)):
sum=sum+s[i].get_age()
i+=1
sum=sum/len(s)
return sum
def age_lessthan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_age()<max):
count+=1
i+=1
return count
def minimum_weight(s):
i=1
mini=s[0].get_weight()
while(i<len(s)):
if(s[i].get_weight()<mini):
mini=s[i].get_weight()
i+=1
return mini
def weight_lessthan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_weight()<max):
count+=1
i+=1
return count
def displaylessthan(s,max):
i=0
while(i<len(s)):
if(s[i].get_weight()<max):
print(s[i].get_name())
i+=1
setup()
Lab 7 letter
class Letter:
def __init__(self,word,data,char):
self.word=word
self.data=data
self.char=char
def display(self):
i=0
while(i<6):
j=0
while(j<len(self.word)):
if(self.word[j]=='T'):
print(self.data[0][i],end=" ")
elif(self.word[j]=='O'):
print(self.data[1][i],end=" ")
elif(self.word[j]=='P'):
print(self.data[2][i],end=" ")
j+=1
print(" ")
i+=1
def setup():
T=['######',' # ',' # ',' # ',' # ',' # ']
O=['######','# #','# #','# #','# #','######']
P=['######','# #','######','# ','# ','# ']
data=[T,O,P]
word='TPO'
showLetter= Letter(word,data,'*')
showLetter.display()
setup()
def __init__(self,word,data,char):
self.word=word
self.data=data
self.char=char
def display(self):
i=0
while(i<6):
j=0
while(j<len(self.word)):
if(self.word[j]=='T'):
print(self.data[0][i],end=" ")
elif(self.word[j]=='O'):
print(self.data[1][i],end=" ")
elif(self.word[j]=='P'):
print(self.data[2][i],end=" ")
j+=1
print(" ")
i+=1
def setup():
T=['######',' # ',' # ',' # ',' # ',' # ']
O=['######','# #','# #','# #','# #','######']
P=['######','# #','######','# ','# ','# ']
data=[T,O,P]
word='TPO'
showLetter= Letter(word,data,'*')
showLetter.display()
setup()
วันจันทร์ที่ 19 ตุลาคม พ.ศ. 2558
lab6
def setup():
name=['top','tape','bass']
st_id=[15,16,17]
age=[17,18,18]
weight=[83,93,69]
height=[178,175,175]
bmi=[None]*3
bmical(weight,height,bmi)
display(name,st_id,age,weight,height,bmi)
print("-----------------------")
countBmi=find_BmiHeight25(bmi)
print("Bmi > 25 : ",countBmi)
def find_BmiHeight25(bmi):
i=0
count=0
maximum=25;
while(i<len(bmi)):
if(bmi[i]>maximum):
maximum=bmi[i]
#height25[i]=
count=count+1
i=i+1
return count
def bmical(w,h,bmi):
i=0
while(i<len(bmi)):
bmi[i]=cal_bmi(w[i],h[i])
i=i+1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def display(n,st_id,a,w,h,bmi):
i=0
while(i<len(n)):
print("Name ",n[i]," St_id ",st_id[i]," Age ",a[i]," Weight ",w[i]," height ",h[i]," Bmi ",bmi[i])
i=i+1
setup()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
def setup():
name=['top','tape','bass']
st_id=[15,16,17]
age=[17,18,18]
weight=[83,93,69]
height=[178,175,175]
bmi=[None]*3
bmical(weight,height,bmi)
display(name,st_id,age,weight,height,bmi)
print("-----------------------")
#countBmi=find_BmiHeight25(bmi)
print("Bmi > 25 : ",find_BmiHeight25(bmi,name))
def find_BmiHeight25(bmi,n):
i=0
count=0
maximum=25;
while(i<len(bmi)):
if(bmi[i]>maximum):
maximum=bmi[i]
print("Name ",n[i])
count=count+1
i=i+1
return count
def bmical(w,h,bmi):
i=0
while(i<len(bmi)):
bmi[i]=cal_bmi(w[i],h[i])
i=i+1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def display(n,st_id,a,w,h,bmi):
i=0
while(i<len(n)):
print("Name ",n[i]," St_id ",st_id[i]," Age ",a[i]," Weight ",w[i]," height ",h[i]," Bmi ",bmi[i])
i=i+1
setup()
name=['top','tape','bass']
st_id=[15,16,17]
age=[17,18,18]
weight=[83,93,69]
height=[178,175,175]
bmi=[None]*3
bmical(weight,height,bmi)
display(name,st_id,age,weight,height,bmi)
print("-----------------------")
countBmi=find_BmiHeight25(bmi)
print("Bmi > 25 : ",countBmi)
def find_BmiHeight25(bmi):
i=0
count=0
maximum=25;
while(i<len(bmi)):
if(bmi[i]>maximum):
maximum=bmi[i]
#height25[i]=
count=count+1
i=i+1
return count
def bmical(w,h,bmi):
i=0
while(i<len(bmi)):
bmi[i]=cal_bmi(w[i],h[i])
i=i+1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def display(n,st_id,a,w,h,bmi):
i=0
while(i<len(n)):
print("Name ",n[i]," St_id ",st_id[i]," Age ",a[i]," Weight ",w[i]," height ",h[i]," Bmi ",bmi[i])
i=i+1
setup()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
def setup():
name=['top','tape','bass']
st_id=[15,16,17]
age=[17,18,18]
weight=[83,93,69]
height=[178,175,175]
bmi=[None]*3
bmical(weight,height,bmi)
display(name,st_id,age,weight,height,bmi)
print("-----------------------")
#countBmi=find_BmiHeight25(bmi)
print("Bmi > 25 : ",find_BmiHeight25(bmi,name))
def find_BmiHeight25(bmi,n):
i=0
count=0
maximum=25;
while(i<len(bmi)):
if(bmi[i]>maximum):
maximum=bmi[i]
print("Name ",n[i])
count=count+1
i=i+1
return count
def bmical(w,h,bmi):
i=0
while(i<len(bmi)):
bmi[i]=cal_bmi(w[i],h[i])
i=i+1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def display(n,st_id,a,w,h,bmi):
i=0
while(i<len(n)):
print("Name ",n[i]," St_id ",st_id[i]," Age ",a[i]," Weight ",w[i]," height ",h[i]," Bmi ",bmi[i])
i=i+1
setup()
วันจันทร์ที่ 28 กันยายน พ.ศ. 2558
binary
def binary():
n=18
c=0
b=""
s=""
while(n>0):
b=n%2
c=n%2
if(b==1):
b="1"
elif(b==0):
b="0"
s=b+s
n=(n-c)/2
return s
binary()
print(binary())
n=18
c=0
b=""
s=""
while(n>0):
b=n%2
c=n%2
if(b==1):
b="1"
elif(b==0):
b="0"
s=b+s
n=(n-c)/2
return s
binary()
print(binary())
วันอาทิตย์ที่ 20 กันยายน พ.ศ. 2558
HELLO PYTHON
###################### BMI ##########################1
ef displayBMI():
weight=84
height=184
bmi=cal(weight,height)
print(bmi)
def cal(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
displayBMI()
######################## Area and Circum #########################2
def display():
diameter = 10
circum=calCircum(diameter)
area=calArea(diameter)
print("Circumference is ",circum)
print("Area is ",area)
def calCircum(d):
c=0
c=(22/7)*d
return c
def calArea(d):
r=0
a=0
r=d/2
a=(22/7)*(r*r)
return a
display()
##################### power_of_ten ########################3
def display():
value=12;
power=power_of_ten(value)
print("10 ^",value," is ",power)
def power_of_ten(v):#v is value
if(v==6):
s="Million"
return s
elif(v==9):
s="Billion"
return s
elif(v==12):
s="Trillion"
return s
elif(v==15):
s="Quadrillion"
return s
elif(v==18):
s="Quintillion"
return s
elif(v==21):
s="Sextillion"
return s
elif(v==30):
s="Nonillion"
return s
elif(v==100):
s="Googol"
return s
display()
#################### Grade ############################4
def display():
value=50;
grade=cal_grade(value)
print("grade is ",grade)
def cal_grade(v):#v is value
if(v>=80):
s="A"
return s
elif(v>=70):
s="B"
return s
elif(v>=60):
s="C"
return s
elif(v>=50):
s="D"
return s
else:
s="F"
return s
display()
#####################################################5
###########main############
def display_leapyear():
year=1600
leapYear=cal_leapYear(year)
print(year," is ",leapYear)
###########main############
def cal_leapYear(year):
value=0
value=year%400
if(value==0):
s="leap year"
return s
else:
value=year%100
if(value==0):
s="don't leap year"
return s
else:
value=year%4
if(value==0):
s="leap year"
return s
else:
s="don't leap year"
return s
display_leapyear()
############### multiplication_table ################6
def display():
multiplication_table=table(3)
def table(num):
count=1
while(count<=12):
print(num," * ",count," = ",num*count)
count=count+1
####################################################
display()
#################### Sum of number #######################7
def displaySum():
sum=cal_sum(50)
print(sum)
def cal_sum(n):
sum1=0
count=0
while(count<n):
count=count+1
sum1=sum1+count
return sum1
################################
displaySum()
#################### PrimeOfNum ###################8
def displayPrimeOfNum():
prime=cal_prime(20)#(n)
def cal_prime(n):
count=1
while(count<n):
count=count+1
if(prime1(count) == "true"):
print(count," ")
def prime1(count):
count1=2
while(count1<count):
if(count%count1==0):
x="false"
return x
count1=count1+1
x="true"
return x
x="true"
return x
#######################################
displayPrimeOfNum()
#################### Loan_payment ######################9
def display():
interest_rate = 12
loan_month = 5000
total_of_payments = 12
calJ = cal_j(interest_rate,total_of_payments)
cal_1 = cals1(calJ,total_of_payments)
calM = cals2(calJ,cal_1)
payment = calM*loan_month
begin_ba=loan_month
displayMain(begin_ba,calJ,payment,total_of_payments)
def cal_j(interest_rate,total_of_payments):
j = 0;
j = (interest_rate/100)/total_of_payments
return j
def cals1(calJ,total_of_payments):
cals01=0
cals01 = pow((1+calJ),-total_of_payments)
return cals01
def cals2(calJ,cal_1):
cals02=0
cals02=calJ/(1-cal_1)
return cals02
def displayMain(begin_ba,calJ,payment,total_of_payments):
print("No. Beginning Balance interest principal Ending balance")
count=1
while(count<=total_of_payments):
interest = calJ*begin_ba
pricipal = payment-interest
End_ba = begin_ba-pricipal
print(count," ",begin_ba," ",interest," ",pricipal," ",End_ba," ")
begin_ba = End_ba
count=count+1
display()
ef displayBMI():
weight=84
height=184
bmi=cal(weight,height)
print(bmi)
def cal(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
displayBMI()
######################## Area and Circum #########################2
def display():
diameter = 10
circum=calCircum(diameter)
area=calArea(diameter)
print("Circumference is ",circum)
print("Area is ",area)
def calCircum(d):
c=0
c=(22/7)*d
return c
def calArea(d):
r=0
a=0
r=d/2
a=(22/7)*(r*r)
return a
display()
##################### power_of_ten ########################3
def display():
value=12;
power=power_of_ten(value)
print("10 ^",value," is ",power)
def power_of_ten(v):#v is value
if(v==6):
s="Million"
return s
elif(v==9):
s="Billion"
return s
elif(v==12):
s="Trillion"
return s
elif(v==15):
s="Quadrillion"
return s
elif(v==18):
s="Quintillion"
return s
elif(v==21):
s="Sextillion"
return s
elif(v==30):
s="Nonillion"
return s
elif(v==100):
s="Googol"
return s
display()
#################### Grade ############################4
def display():
value=50;
grade=cal_grade(value)
print("grade is ",grade)
def cal_grade(v):#v is value
if(v>=80):
s="A"
return s
elif(v>=70):
s="B"
return s
elif(v>=60):
s="C"
return s
elif(v>=50):
s="D"
return s
else:
s="F"
return s
display()
#####################################################5
###########main############
def display_leapyear():
year=1600
leapYear=cal_leapYear(year)
print(year," is ",leapYear)
###########main############
def cal_leapYear(year):
value=0
value=year%400
if(value==0):
s="leap year"
return s
else:
value=year%100
if(value==0):
s="don't leap year"
return s
else:
value=year%4
if(value==0):
s="leap year"
return s
else:
s="don't leap year"
return s
display_leapyear()
############### multiplication_table ################6
def display():
multiplication_table=table(3)
def table(num):
count=1
while(count<=12):
print(num," * ",count," = ",num*count)
count=count+1
####################################################
display()
#################### Sum of number #######################7
def displaySum():
sum=cal_sum(50)
print(sum)
def cal_sum(n):
sum1=0
count=0
while(count<n):
count=count+1
sum1=sum1+count
return sum1
################################
displaySum()
#################### PrimeOfNum ###################8
def displayPrimeOfNum():
prime=cal_prime(20)#(n)
def cal_prime(n):
count=1
while(count<n):
count=count+1
if(prime1(count) == "true"):
print(count," ")
def prime1(count):
count1=2
while(count1<count):
if(count%count1==0):
x="false"
return x
count1=count1+1
x="true"
return x
x="true"
return x
#######################################
displayPrimeOfNum()
#################### Loan_payment ######################9
def display():
interest_rate = 12
loan_month = 5000
total_of_payments = 12
calJ = cal_j(interest_rate,total_of_payments)
cal_1 = cals1(calJ,total_of_payments)
calM = cals2(calJ,cal_1)
payment = calM*loan_month
begin_ba=loan_month
displayMain(begin_ba,calJ,payment,total_of_payments)
def cal_j(interest_rate,total_of_payments):
j = 0;
j = (interest_rate/100)/total_of_payments
return j
def cals1(calJ,total_of_payments):
cals01=0
cals01 = pow((1+calJ),-total_of_payments)
return cals01
def cals2(calJ,cal_1):
cals02=0
cals02=calJ/(1-cal_1)
return cals02
def displayMain(begin_ba,calJ,payment,total_of_payments):
print("No. Beginning Balance interest principal Ending balance")
count=1
while(count<=total_of_payments):
interest = calJ*begin_ba
pricipal = payment-interest
End_ba = begin_ba-pricipal
print(count," ",begin_ba," ",interest," ",pricipal," ",End_ba," ")
begin_ba = End_ba
count=count+1
display()
book_lab4
int moveY;
int cout;
void setup(){
size(1100,700);
}
void draw(){
int count=0;
int n=2;
int pos=0;
while(count<n){
book(pos);
pos=pos+550;
count++;
// fill(#000000);
// rect(10,50,50,50);
}
//book();
if(cout < 20){
moveY++;
cout++;
}else if(cout > 0){
moveY--;
if(moveY == -20){
cout=-20;
}
}
println(moveY);
print("..................");
println(cout);
}
void book(int pos){
int posy=50;
//moveY=(moveY+1)%(100);
fill(#D8BABA);
rect(pos+0, 0, 549, 699);
fill(#FFFFFF);
rect(pos+0, 0, 55, 699);
textSize(40);
fill(#000000);
text("1",pos+15,50);
textSize(20);
text("45B",pos+8,660);
fill(#FF9966);
rect(pos+60, 5, 485, 450);
//////////////////Body/////////////////
fill(#000000);
strokeWeight(4);
ellipse(pos+300, posy+250-moveY, 240, 250);//face back
fill(#FFFFFF);
rect(pos+165, posy+251-moveY, 30, 40);//left ear
rect(pos+405, posy+251-moveY, 30, 40);//right ear
ellipse(pos+300, posy+254-moveY, 238, 245);
fill(#FDFF40);//face front
ellipse(pos+360, posy+245-moveY, 70, 80);//right eye
ellipse(pos+240, posy+245-moveY, 70, 80);//left eye
strokeWeight(2);
fill(#000000);
triangle(pos+300, posy+275-moveY, pos+285,posy+100-moveY, pos+315, posy+100-moveY); //crest
textSize(70);
fill(#000000);
text("The",pos+100,530);
textSize(60);
text("Ultraman",pos+250,530);
textSize(40);
text("Original",pos+380,580);
/*
println("My faverite book is ");
println ("ultranma");
println(-moveY);*/
}
movie_lab4
int resize;
int move;
int cout;
void setup(){
size(600, 600);
}
void draw(){
background(#778899);
int count=1;
int n=4;
int pos=0;
while(count<=n){
fill (#ADABBC);
textSize(50);
text("Joker",pos-20,50);
text("Joker",pos+40,150);
text("Joker",pos-20,250);
text("Joker",pos+40,350);
text("Joker",pos-20,450);
text("Joker",pos+40,550);
pos=pos+180;
count++;
}
movie(400);
if (cout < 30){
move++;
cout++;
}else if(cout > 0){
move--;
if(move==0){
cout =0;}
}
println(move);
println("..................");
println(cout);
}
void movie(int x){
int posx=50;
resize=(resize+1)%20;
fill(#FAEBD7);
stroke(#000000);
strokeWeight(5);
ellipse(300, 300, 300, 400); //face
stroke(#000000);
strokeWeight(5);
line(300, 98, 300, 50); //hair 1
line(295, 98, 280, 60); //hair 2
line(305, 98, 320, 60); //hair 3
//Nose
fill(#CC0000);
strokeWeight(5);
ellipse(x, 350, 70+resize, 65+resize); //nose
fill(#FF0000);
stroke(#FF0000);
strokeWeight(1);
ellipse(x, 350, 59+resize, 55+resize); //nose red
fill(#FF4500);
stroke(#FF4500);
strokeWeight(1);
ellipse(x, 350, 48+resize, 45+resize); //nose orange
fill(#FFA500);
stroke(#FFA500);
strokeWeight(1);
ellipse(x, 350, 37+resize, 35+resize); //nose yellow
fill(#000000);
stroke(#000000);
quad(posx+210, 250, posx+230, 200, posx+250, 250, posx+230, 300); //left tatto
fill(#F8F8FF);
strokeWeight(2);
ellipse(posx+230, 250, 80+resize, 30+resize); //left eye
ellipse(posx+370, 250, 80+resize, 30+resize); //right eye
fill(#CC0000);
stroke(#CC0000);
strokeWeight(1);
ellipse(posx+230+move, 250, 10+resize, 26+resize); //left small eye
ellipse(posx+370+move, 250, 10+resize, 26+resize); //right small eye
fill(#FF0000);
stroke(#FF0000);
strokeWeight(1);
ellipse(posx+230+move, 250, 2+resize, 2+resize); //left very small eye
ellipse(posx+370+move, 250, 2+resize, 2+resize); //right very small eye
println("My Movie is Batman");
println("This is JOKER");
println(resize);
}
music_lab4
int moveX;
int moveY;
void setup(){
size(500,550);
}
void draw(){
int count=0;
int n=3;
int pos=0;
background(#F5F5F5);
while(count<n){
fill (#FFDEDE);
textSize(60);
text("Girl's",pos+50,80);
text("Girl's",pos-50,160);
text("Girl's",pos+50,240);
text("Girl's",pos-50,320);
text("Girl's",pos+50,400);
text("Girl's",pos-50,480);
text("Girl's",pos+50,560);
pos+=220;
count++;
}
music(pos);
}
void music(int pos){
int posx=25;
int posy=7;
moveX=(moveX+1)%4;
moveY=(moveY+1)%4;
//rect(0, 0, 499, 549);
//left heart
stroke(#000000);
strokeWeight(10);
line(246-posx+moveX, 85-posy, 190-posx+moveX, 15-posy); //1
line(190-posx+moveX, 15-posy, 90-posx+moveX, 130-posy); //2
line(90-posx+moveX, 130-posy, 246-posx+moveX, 321-posy); //3
line(246-posx+moveX, 321-posy, 246-posx+moveX, 150-posy); //4
line(246-posx+moveX, 150-posy, 155-posx+moveX, 150-posy); //5
stroke(#F23383);
strokeWeight(7.5);
line(246, 85+moveY, 190, 15+moveY); //1
line(190, 15+moveY, 90, 130+moveY); //2
line(90, 130+moveY, 246, 321+moveY); //3
line(246, 321+moveY, 246, 150+moveY); //4
line(246, 150+moveY, 155, 150+moveY); //5
//right heart
stroke(#000000);
strokeWeight(10);
line(262+posx+moveX, 85-posy,318+posx+moveX, 15-posy); //1
line(318+posx+moveX, 15-posy, 418+posx+moveX, 130-posy); //2
line(418+posx+moveX, 130-posy, 262+posx+moveX, 321-posy); //3
line(262+posx+moveX, 321-posy, 262+posx+moveX, 150-posy); //4
line(262+posx+moveX, 150-posy, 353+posx+moveX, 150-posy); //5
stroke(#F23383);
strokeWeight(7.5);
line(262, 85+moveY,318, 15+moveY); //1
line(318, 15+moveY, 418, 130+moveY); //2
line(418, 130+moveY, 262, 321+moveY); //3
line(262, 321+moveY, 262, 150+moveY); //4
line(262, 150+moveY, 353, 150+moveY); //5
//Heart WAVE
strokeWeight(1);
line(150, 370+moveY, 185, 370+moveY);
line(185, 370+moveY, 202, 344+moveY);
line(202, 345+moveY, 202, 370+moveY);
line(202, 370+moveY, 217, 344+moveY);
line(217, 345+moveY, 217, 385+moveY);
line(217, 385+moveY, 234, 357+moveY);
line(234, 357+moveY, 244, 357+moveY);
line(244, 357+moveY, 244, 370+moveY);
line(244, 370+moveY, 259, 370+moveY);
line(259, 370+moveY, 276, 344+moveY);
line(276, 344+moveY, 276, 370+moveY);
line(276, 370+moveY, 292, 344+moveY);
line(292, 344+moveY, 292, 384+moveY);
line(292, 384+moveY, 309, 357+moveY);
line(309, 357+moveY, 319, 357+moveY);
line(319, 357+moveY, 319, 370+moveY);
line(319, 370+moveY, 354, 370+moveY);
fill(#F23383);
ellipse(354, 370+moveY, 3, 3);
if(mousePressed == true){
textSize(90);
fill(#000000);
text("G",130+moveX,478+moveY);
}
else{
textSize(90);
fill(#F23383);
text("G",130+moveX,478+moveY);
}
if (keyPressed == false){
fill(#FFA5CB);
textSize(40);
text("irls",191,445);
textSize(40);
text("eneration",189,478);
}
else{
fill(#ED0707);
textSize(40);
text("irls",191,445);
textSize(40);
text("eneration",189,478);
}
fill(#FFFFFF);
println("My faverite Music is ");
println ("Girlsgeneration");
println(moveX);
}
loan_payment_lab4
void setup() {
size();
////////// INPUT /////////////
float interest_rate = 12;
float loan_month = 5000 ;
float total_of_payments = 12;
///////// PROCESS ///////////
int count=1;
float calJ;
float cal_1;
float calM;
float total_in;
//float cal_inter;
calJ = cal_j(interest_rate,total_of_payments);
cal_1 = cals1(calJ,total_of_payments);
calM = cals2(calJ,cal_1);
println("cal2 "+calJ);
float payment = calM*loan_month;
//println("calpayment "+(payment);
///////////////////////Display////////////////////////
println("No. Beginning Balance interest principal Ending balance");
float begin_ba=loan_month;
float interest;
float pricipal;
float End_ba;
while(count<=total_of_payments){
interest = calJ*begin_ba;
pricipal = payment-interest;
End_ba = begin_ba-pricipal;
println(count+" "+begin_ba+" "+interest+" "+pricipal+" "+End_ba+" ");
begin_ba = End_ba ;
count++;
}
///////////////////////Display////////////////////////
}
float cal_j(float interest_rate,float total_of_payments){
float j = 0;
j = (interest_rate/100)/total_of_payments;
return j;
}
float cals1(float calJ,float total_of_payments){
float cals01;
cals01 = pow((1+calJ),-total_of_payments);
return cals01;
}
float cals2(float calJ,float cal_1){
float cals02;
cals02=calJ/(1-cal_1);
return cals02 ;
}
วันเสาร์ที่ 19 กันยายน พ.ศ. 2558
bird_lab4
int movey=0;
float movex=0;
int count=0;
void setup() {
size(600, 600);
}
void draw() {
background(255-mouseY);
////////////////////////While////////////////////////
int count1=0;
int n=2;
int posx=0;
while (count1<n){
bird(posx+mouseX, mouseY, 30, 30);
bird(mouseX, mouseY-posx, 30, 30);
bird(mouseX, mouseY+posx, 30, 30);
bird(mouseX-posx, mouseY, 30, 30);
posx=posx+100;
count1++;
println(posx);
}
////////////////////////While////////////////////////
println("count"+count);
println("moveY"+movey);
println("moveX"+movex);
}
void bird(int x, int y, int w, int h) {
//w= width
//h= hight
if(count<120){
movey++;
count++;
}
else if(count>=0){
movey--;
if(movey==0){
count=0;
}
}
strokeWeight(5);
fill(#FFFFFF);
line(x+15, y, x+80-movex, y+60-movey);//right
line(x-15, y, x-80, y+60-movey); //left
ellipse(x, y, w, h);
fill(#F21616);
strokeWeight(1);
ellipse(x+7, y, w-22, h-15);//left eye
ellipse(x-7, y, w-22, h-15);//right eye
fill(#E08B22);
triangle(x-6,y+9,x+6,y+9,x,y+18);//mouth
}
วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558
prime_fo_num_lab4
void setup(){
sum_of_integers(100);
}
void sum_of_integers(int n){
int sum=0;
int count=0;
while(count<n){
count++;
sum=sum+count;
}
println("Sum is "+sum);
}
prime_of_number_lab4
void setup(){
int n=150;//1 to n=N
prime_of_num(n);
}
void prime_of_num(int n){
int count1=1;
while(count1<n){
count1++;
if(prime(count1)== true){
print(count1+" ");
}
}
}
boolean prime(int n){
int count=2;
while(count<n){
if(n%count==0){
return false;
}
count++;
}
return true;
}
multiplication_table_lab4
void setup(){
multiplication_table(2);
}
void multiplication_table(int num){
int count=0;
while(count<12){
count++;
println(num+" * "+count+" = "+num*count);
}
}
balloon_lab4
void setup(){
size(500, 500);
}
void draw(){
background(#FFFFFF);
int y=mouseY;
if(y>400){
fill(#04D605);//green
background(#7C7C7C);//gray
}
else if(y<100){
fill(#EDE202);//yellow
background(#E517E5);//pink
}
else{
fill(#ED1A1A);//red
background(#3C17E5);//blue
}
draw_balloon(width/2,y,2);
}
void draw_balloon(int x,int y,int n){
int r=100;
int string_length=200;
int count=1,count1=0;
//int n=2;
int l=(r/2)+20;
int l1=0;
while(count<=n){
line(x-count1,l1+y,x,y+string_length);//left rope
line(count1+x,l1+y,x,y+string_length);
ellipse(x-count1,l1+y,r,r);//left balloon
ellipse(count1+x,y+l1,r,r);
l1=l1+20;
count1=count1+l;
count++;
}
}
วันจันทร์ที่ 7 กันยายน พ.ศ. 2558
Delivery_lab3
float price;
int Package,Service;
int weight;
void setup(){
size(200,200);
//1=letter
//2=box
PackageType(1);
SeviceType(2);
weight=10;
calculate(Package,Service,weight);
}
void PackageType(int PackageType_1){
if(PackageType_1==1)
println("Package is Letter");
else if(PackageType_1==2)
println("Package is Box");
else
println("Error and try again");
Package=PackageType_1;
}
void SeviceType(int SeviceType_1){
if(SeviceType_1==1)
println("Next Day Priority");
else if(SeviceType_1==2)
println("Next Day Standard");
else if(SeviceType_1==3)
println("2-Day");
else
println("Error and try again");
Service=SeviceType_1;
}
void calculate(int Package,int Service,int weight){
/////////////Letter//////////////
if(Package==1 && Service==1){
if((weight%8)==0 || weight<=8)
price=12;
else if((weight%8)!= 0){
price=12*(int(weight/8)+1);
}
}
else if(Package==1 && Service==2){
if((weight%8)==0 || weight<=8)
price=10.5;
else if((weight%8)!= 0){
price=10.5*(int(weight/8)+1);
}
}
else if(Package==1 && Service==3)
println("not avariable");
//////////////Box////////////////
else if (Package==2&&Service==1){
if(weight==1)
price=15.75;
else if(weight != 1){
price=15.75+((weight-1)*1.25);
}
}
else if (Package==2&&Service==2){
if(weight==1)
price=13.75;
else if(weight != 1){
price=13.75+((weight-1)*1.00);
}
}
else if (Package==2&&Service==3){
if(weight==1){
price=7;
}
else if(weight != 1){
price=7+((weight-1)*0.5);
}
}
println("weight is "+weight);
println("price is "+price);
}
วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558
Logo_lab3
int moveX;
int moveY;
void setup(){
size(500,550);
}
void draw(){
music();
}
void music(){
int posx=25;
int posy=7;
moveX=(moveX+1)%4;
moveY=(moveY+1)%4;
rect(0, 0, 499, 549);
//left heart
stroke(#000000);
strokeWeight(10);
line(246-posx+moveX, 85-posy, 190-posx+moveX, 15-posy); //1
line(190-posx+moveX, 15-posy, 90-posx+moveX, 130-posy); //2
line(90-posx+moveX, 130-posy, 246-posx+moveX, 321-posy); //3
line(246-posx+moveX, 321-posy, 246-posx+moveX, 150-posy); //4
line(246-posx+moveX, 150-posy, 155-posx+moveX, 150-posy); //5
stroke(#F23383);
strokeWeight(7.5);
line(246, 85+moveY, 190, 15+moveY); //1
line(190, 15+moveY, 90, 130+moveY); //2
line(90, 130+moveY, 246, 321+moveY); //3
line(246, 321+moveY, 246, 150+moveY); //4
line(246, 150+moveY, 155, 150+moveY); //5
//right heart
stroke(#000000);
strokeWeight(10);
line(262+posx+moveX, 85-posy,318+posx+moveX, 15-posy); //1
line(318+posx+moveX, 15-posy, 418+posx+moveX, 130-posy); //2
line(418+posx+moveX, 130-posy, 262+posx+moveX, 321-posy); //3
line(262+posx+moveX, 321-posy, 262+posx+moveX, 150-posy); //4
line(262+posx+moveX, 150-posy, 353+posx+moveX, 150-posy); //5
stroke(#F23383);
strokeWeight(7.5);
line(262, 85+moveY,318, 15+moveY); //1
line(318, 15+moveY, 418, 130+moveY); //2
line(418, 130+moveY, 262, 321+moveY); //3
line(262, 321+moveY, 262, 150+moveY); //4
line(262, 150+moveY, 353, 150+moveY); //5
//Heart WAVE
strokeWeight(1);
line(150, 370+moveY,185, 370+moveY);
line(185, 370+moveY, 202, 344+moveY);
line(202, 345+moveY, 202, 370+moveY);
line(202, 370+moveY, 217, 344+moveY);
line(217, 345+moveY, 217, 385+moveY);
line(217, 385+moveY, 234, 357+moveY);
line(234, 357+moveY, 244, 357+moveY);
line(244, 357+moveY, 244, 370+moveY);
line(244, 370+moveY, 259, 370+moveY);
line(259, 370+moveY, 276, 344+moveY);
line(276, 344+moveY, 276, 370+moveY);
line(276, 370+moveY, 292, 344+moveY);
line(292, 344+moveY, 292, 384+moveY);
line(292, 384+moveY, 309, 357+moveY);
line(309, 357+moveY, 319, 357+moveY);
line(319, 357+moveY, 319, 370+moveY);
line(319, 370+moveY, 354, 370+moveY);
fill(#F23383);
ellipse(354, 370+moveY, 3, 3);
if(mousePressed == true){
textSize(90);
fill(#000000);
text("G",130+moveX,478+moveY);
}
else{
textSize(90);
fill(#F23383);
text("G",130+moveX,478+moveY);
}
if (keyPressed == false){
fill(#FFA5CB);
textSize(40);
text("irls",191,445);
textSize(40);
text("eneration",189,478);
}
else{
fill(#ED0707);
textSize(40);
text("irls",191,445);
textSize(40);
text("eneration",189,478);
}
fill(#FFFFFF);
println("My faverite Music is ");
println ("Girlsgeneration");
println(moveX);
}
Power_of_ten_lab3
void setup(){
size();
int value=0;
println("10e"+value);
power_of_ten(value);
}
void power_of_ten(int value){
if (value==6){
println("Million");
}
else if(value==9){
println("Billion");
}
else if(value==12){
println("Trillion");
}
else if(value==15){
println("Quadrillion");
}
else if(value==18){
println("Quintillion");
}
else if(value==21){
println("Sextillion");
}
else if(value==30){
println("Nonillion");
}
else if(value==100){
println("Googol");
}
else{
println("Error");
}
}
Movie_lab_3
int resize;
int move;
int cout;
void setup(){
size(600, 600);
}
void draw(){
movie(400);
if (cout < 30){
move++;
cout++;
}else if(cout > 0){
move--;
if(move==0){
cout =0;}
}
println(move);
println("..................");
println(cout);
}
void movie(int x){
int posx=50;
resize=(resize+1)%20;
background(#778899);
fill(#FAEBD7);
stroke(#000000);
strokeWeight(5);
ellipse(300, 300, 300, 400); //face
stroke(#000000);
strokeWeight(5);
line(300, 98, 300, 50); //hair 1
line(295, 98, 280, 60); //hair 2
line(305, 98, 320, 60); //hair 3
//Nose
fill(#CC0000);
strokeWeight(5);
ellipse(x, 350, 70+resize, 65+resize); //nose
fill(#FF0000);
stroke(#FF0000);
strokeWeight(1);
ellipse(x, 350, 59+resize, 55+resize); //nose red
fill(#FF4500);
stroke(#FF4500);
strokeWeight(1);
ellipse(x, 350, 48+resize, 45+resize); //nose orange
fill(#FFA500);
stroke(#FFA500);
strokeWeight(1);
ellipse(x, 350, 37+resize, 35+resize); //nose yellow
fill(#000000);
stroke(#000000);
quad(posx+210, 250, posx+230, 200, posx+250, 250, posx+230, 300); //left tatto
fill(#F8F8FF);
strokeWeight(2);
ellipse(posx+230, 250, 80+resize, 30+resize); //left eye
ellipse(posx+370, 250, 80+resize, 30+resize); //right eye
fill(#CC0000);
stroke(#CC0000);
strokeWeight(1);
ellipse(posx+230+move, 250, 10+resize, 26+resize); //left small eye
ellipse(posx+370+move, 250, 10+resize, 26+resize); //right small eye
fill(#FF0000);
stroke(#FF0000);
strokeWeight(1);
ellipse(posx+230+move, 250, 2+resize, 2+resize); //left very small eye
ellipse(posx+370+move, 250, 2+resize, 2+resize); //right very small eye
println("My Movie is Batman");
println("This is JOKER");
println(resize);
}
leap_year_lab3
void setup(){
size();
leap_year(2016);
}
void leap_year(int year){
float value;
value=year%400;
if(value==0){
println("(r1)leap year 29 days");
}
else{
value=year%100;
if(value==0){
println("(r2)dont leap year 28 day");
}
else{
value=year%4;
if(value==0){
println("(r3)leap year 29 days");
}
else{
println("dont Leave year 28 day");
}
}
}
}
cal_GPA_lab3
void setup(){
size();
cal_GPA(45);
}
void cal_GPA(int score)
{
if(score<0){
println("Error");
}
else if(score<50){
println("F");
}
else if(score<60){
println("D");
}
else if(score<70){
println("C");
}
else if(score<80){
println("B");
}
else if(score<=100){
println("A");
}
else{
println("Error");
}
}
book_lab_3
int moveY;
int cout;
void setup(){
size(550,700);
}
void draw(){
book();
if(cout < 20){
moveY++;
cout++;
}else if(cout > 0){
moveY--;
if(moveY == -20){
cout=-20;
}
}
println(moveY);
print("..................");
println(cout);
}
void book(){
int posy=50;
//moveY=(moveY+1)%(100);
fill(#D8BABA);
rect(0, 0, 549, 699);
fill(#FFFFFF);
rect(0, 0, 55, 699);
textSize(40);
fill(#000000);
text("1",15,50);
textSize(20);
text("45B",8,660);
fill(#FF9966);
rect(60, 5, 485, 450);
//////////////////Body/////////////////
fill(#000000);
strokeWeight(4);
ellipse(300, posy+250-moveY, 240, 250);//face back
fill(#FFFFFF);
rect(165, posy+251-moveY, 30, 40);//left ear
rect(405, posy+251-moveY, 30, 40);//right ear
ellipse(300, posy+254-moveY, 238, 245);
fill(#FDFF40);//face front
ellipse(360, posy+245-moveY, 70, 80);//right eye
ellipse(240, posy+245-moveY, 70, 80);//left eye
strokeWeight(2);
fill(#000000);
triangle(300, posy+275-moveY, 285,posy+100-moveY, 315, posy+100-moveY); //crest
textSize(70);
fill(#000000);
text("The",100,530);
textSize(60);
text("Ultraman",250,530);
textSize(40);
text("Original",380,580);
/*
println("My faverite book is ");
println ("ultranma");
println(-moveY);*/
}
bird_lab3
int movey=0;
float movex=0;
int count=0;
void setup() {
size(600, 600);
}
void draw() {
background(255-mouseY);
bird(mouseX, mouseY, 30, 30);
println("count"+count);
println("moveY"+movey);
println("moveX"+movex);
}
void bird(int x, int y, int w, int h) {
//w= width
//h= hight
if(count<120){
movey++;
count++;
}
else if(count>=0){
movey--;
if(movey==0){
count=0;
}
}
strokeWeight(5);
fill(#FFFFFF);
line(x+15, y, x+80-movex, y+60-movey);//right
line(x-15, y, x-80, y+60-movey); //left
ellipse(x, y, w, h);
fill(#F21616);
strokeWeight(1);
ellipse(x+7, y, w-22, h-15);//left eye
ellipse(x-7, y, w-22, h-15);//right eye
fill(#E08B22);
triangle(x-6,y+9,x+6,y+9,x,y+18);//mouth
}
battery_lab3
int resize;
int countL;
int countD;
int a;
void setup() {
size(600, 450);
}
void draw() {
background(#EAE49C);
draw_battery(220, 175, 200, 75);
//draw_positionSign(15, 3);
//draw_negativeSign(260);
println(resize);
println(mouseX);
println("CountL"+countL);
println("CountD"+countD);
println("Press"+mousePressed);
}
void draw_battery(int x,int y,int w,int h) {
fill(#EAE49C);
stroke(#384D12);
strokeWeight(5);
rect(x, y, w, h, 7); //case
fill(#384D12);
//depolarized
rect(x-10, y+15, w-190, h-30, 2);
//in case
resize=(resize+3)%180;
rect(((x+191)-resize), y+9, resize, h-17, 1);
////////// POS /////////////
fill(#ED0C0C);
stroke(#ED0C0C);
rect(x-45, y+34, w-185, h-72);//horizontal
rect(x-39, y+28, w-197, h-60);//vertical
//////////// NEG //////////
fill(#ED0C0C);
stroke(#ED0C0C);
rect(x+215, y+34, w-185, h-72);//horizontal
if (mouseX<100 || mouseX>500) {
rect(x+172, y+9, w-181, h-17, 1);
resize=0;
textSize(50);
text("Low Battery", x-45, y+135);
countL++;
if(countL>20){//50
countD++;
fill(#EAE49C);
stroke(#EAE49C);
strokeWeight(5);
rect(x+172, y+9, w-181, h-17, 1);
if(countD>20){
countL=0;
countD=0;
}
}
}
}
balloon_lab3
void setup(){
size(300, 500);
}
void draw(){
background(#FFFFFF);
int y=mouseY;
if(y>400){
fill(#04D605);//green
background(#7C7C7C);//gray
}
else if(y<100){
fill(#EDE202);//yello
background(#E517E5);//pink
}
else{
fill(#ED1A1A);//red
background(#3C17E5);//blue
}
draw_balloon(150,y);
}
void draw_balloon(int x,int y){
int r=100;
int string_length=200;
line(x,y,x,y+string_length);
ellipse(x,y,r,r);
}
วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558
Syntax error
Syntax error
ปัญหา : functionชื่อไม่ตรงกัน
วิธีแก้ : เช็คชื่อ function ให้ตรงกัน
ปัญหา : ไม่มีเครื่องหมาย semicolon(;)
วิธีแก้ : ใส่เครื่องหมาย (;)
ปัญหา : ไม่มีปีกกา ({_})
วิธีแก้ : ใส่ปีกกาปิด (})
ปัญหา : ชื่อตัวแปรไม่ ตรงกัน
วิธีแก้ : เช็คชื่อตัวแปรให้ตรงกัน
วันเสาร์ที่ 29 สิงหาคม พ.ศ. 2558
Lab2-calCA
void setup(){
size(600,100);
int diameter=10;
fill(#690181);
textSize(40);
text("Circumference is "+circumference(diameter),20,50);
text("Area is "+Area(diameter),20,100);
}
float circumference(float d){
//Method C=Pi*d//
float c;
c=PI*d;
return c;
}
float Area(float d){
//Area=PI*r//
float a;
d=d/2;
a=PI*d;
return a;
}
วันพุธที่ 26 สิงหาคม พ.ศ. 2558
Lab2-Digital Clock
void setup(){
size(400,250);
}
void draw() {
background(204);
fill(0,0,0);
rect(0,0,400,250,15);
fill(255);
rect(20,20,360,210,8);
fill(0,0,0);
textSize(100);
text(":",120,125);
text(":",240,125);
textSize(80);
text(second(),265,127);
text(minute(),145,127);
text(hour(),25,127);
textSize(25);
text("Date",120,200);
text("/",230,200);
text("/",270,200);
textSize(15);
text(year(),190,200);
text(month(),250,200);
text(day(),285,200);
}
สมัครสมาชิก:
บทความ (Atom)