วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558
วันเสาร์ที่ 14 พฤศจิกายน พ.ศ. 2558
Lab8_Find_>_25
public class Student {
private String name;
private int idNO;
private int age;
private int weight;
private int height;
public Student(String name,int idNO,int age,int weight,int height){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public int get_age(){
return this.age;
}
public void display(){
System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}
public static void main(String[] arg){
Student[] a = {new Student("James",58001,13,177,90),
new Student("Jane",58002,15,140,60),
new Student("John",58003,17,156,54),
new Student("Jonas",58004,20,188,70)};
int i =0;
while(i<a.length){
a[i].display();
System.out.println("this "+find_more_25(a,i)+" older than 25");
i=i+1;
}
}
public static String find_more_25(Student[] a,int i){
String n="";
if(a[i].get_age()>25){
n=("one");
}else{
n=("one not");
}
return n ;
}
}
Lab8_Avg_age
public class Student {
private String name;
private int idNO;
private int age;
private int weight;
private int height;
public Student(String name,int idNO,int age,int weight,int height){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public int get_age(){
return this.age;
}
public void display(){
System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}
public static void main(String[] arg){
Student[] a = {new Student("James",58001,13,177,90),
new Student("Jane",58002,15,140,60),
new Student("John",58003,17,156,54),
new Student("Jonas",58004,20,188,70)};
int i =0;
while(i<a.length){
a[i].display();
i=i+1;
}
System.out.print("the avg. age is "+cal_avg_age(a));
}
public static float cal_avg_age(Student[] a){
int i = 0;
int sums = 0 ;
float avg = 0 ;
while(i<a.length){
int age=a[i].get_age();
sums = sums+age;
avg = sums/a.length;
i=i+1;
}
return avg;
}
}
Lab8_Student_Find_More_BMI(25)
public class Student {
private String name;
private int idNO;
private int age;
private float weight;
private float height;
public Student(String name,int idNO,int age,float height,float weight){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public float get_height(){
return this.height;
}
public float get_weight(){
return this.weight;
}
public void display(){
System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}
public static void main(String[] args){
Student[] a = {new Student("James",58001,13,177,90),
new Student("Jane",58002,15,140,60),
new Student("John",58003,17,156,54),
new Student("Jonas",58004,20,188,70)};
int i =0;
while(i<a.length){
a[i].display();
System.out.println("BMI : "+String.format("%.2f",cal_bmi(a, i)));
System.out.println("this "+find_more_BMI(a,i)+" has > 25");
i=i+1;
}
}
public static float cal_bmi(Student[] a,int i){
float bmi = 0;
float w = a[i].get_weight();
float h = a[i].get_height();
bmi=w/((h/100)*(h/100));
return bmi;
}
public static String find_more_BMI(Student[] a,int i){
String n ="";
if(cal_bmi(a,i)>25){
n =("one");
}else{
n=("one not");}
return n;
}
}
วันศุกร์ที่ 13 พฤศจิกายน พ.ศ. 2558
Lab8_Student_BMI
public class Student {
private String name;
private int idNO;
private int age;
private float weight;
private float height;
public Student(String name,int idNO,int age,float height,float weight){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public float get_height(){
return this.height;
}
public float get_weight(){
return this.weight;
}
public void display(){
System.out.println("Name :"+this.name+"ID NO :"+this.idNO+"Age : "+this.age+"Weight : "+this.weight+"Height : "+this.height);
}
public static void main(String[] args){
Student[] a = {new Student("James",58001,13,177,90),
new Student("Jane",58002,15,140,60),
new Student("John",58003,17,156,54),
new Student("Jonas",58004,20,188,70)};
int i =0;
while(i<a.length){
a[i].display();
System.out.println("BMI : "+String.format("%.2f",cal_bmi(a, i)));
i=i+1;
}
}
public static float cal_bmi(Student[] a,int i){
float bmi = 0;
float w = a[i].get_weight();
float h = a[i].get_height();
bmi=w/((h/100)*(h/100));
return bmi;
}
}
Lab8_Student_Display
public class Student {
private String name;
private int idNO;
private int age;
private int weight;
private int height;
public Student(String name,int idNO,int age,int weight,int height){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public void display(){
System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}
public static void main(String[] arg){
Student[] a = {new Student("James",58001,13,177,90),
new Student("Jane",58002,15,140,60),
new Student("John",58003,17,156,54),
new Student("Jonas",58004,20,188,70)};
int i =0;
while(i<a.length){
a[i].display();
i=i+1;
}
}
}
วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558
Lab7_Data_AGE
class student:
def __init__(self,names,idno,ages,he ,we ):
self.names = names
self.idNo = idno
self.age = ages
self.weight = we
self.height = he
def display(self):
print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
def get_age(self):
return self.age
def get_names(self):
return self.names
def setup():
a= [student('James',58001,13,177,90),
student('Jane',58002,35,140,60),
student('John',58003,17,156,54),
student('Jonas',58004,40,188,70)]
i=0
while(i<len(a)):
a[i].display()
print()
i=i+1
print('the avg of age is',cal_avgAge(a))
findLess30(a)
def cal_avgAge(a):
sums=0
i=0
while(i<len(a)):
ages=a[i].get_age()
sums=sums+ages
avg=sums/len(a)
i=i+1
return avg
def findLess30(a):
i=0
n=0
while(i<len(a)):
ages=a[i].get_age()
names=a[i].get_names()
if(ages<30):
n=n+1
print(names,'is younger than 30')
i=i+1
print('there are ',n,'students < 30')
setup()
def __init__(self,names,idno,ages,he ,we ):
self.names = names
self.idNo = idno
self.age = ages
self.weight = we
self.height = he
def display(self):
print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
def get_age(self):
return self.age
def get_names(self):
return self.names
def setup():
a= [student('James',58001,13,177,90),
student('Jane',58002,35,140,60),
student('John',58003,17,156,54),
student('Jonas',58004,40,188,70)]
i=0
while(i<len(a)):
a[i].display()
print()
i=i+1
print('the avg of age is',cal_avgAge(a))
findLess30(a)
def cal_avgAge(a):
sums=0
i=0
while(i<len(a)):
ages=a[i].get_age()
sums=sums+ages
avg=sums/len(a)
i=i+1
return avg
def findLess30(a):
i=0
n=0
while(i<len(a)):
ages=a[i].get_age()
names=a[i].get_names()
if(ages<30):
n=n+1
print(names,'is younger than 30')
i=i+1
print('there are ',n,'students < 30')
setup()
Lab7_Data_BMI
class student:
def __init__(self,names,idno,ages,he ,we ):
self.names = names
self.idNo = idno
self.age = ages
self.weight = we
self.height = he
def display(self):
print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
def get_height(self):
return self.height
def get_weight(self):
return self.weight
def setup():
a= [student('James',58001,13,177,90),
student('Jane',58002,15,140,60),
student('John',58003,17,156,54),
student('Jonas',58004,20,188,70)]
i=0
while(i<len(a)):
a[i].display()
print('BMI = %.2f'%cal_bmi(a,i))
print('this ',find_more_BMI(a,i),'has BMI >25')
print()
i=i+1
def cal_bmi(a,i):
while(i<len(a)):
n=0
w = a[i].get_weight()
h = a[i].get_height()
bmi=w/(h/100)**2
return bmi
def find_more_BMI(a,i):
n=0
if(cal_bmi(a,i)>25):
n='one'
else:
n='one not'
return n
setup()
def __init__(self,names,idno,ages,he ,we ):
self.names = names
self.idNo = idno
self.age = ages
self.weight = we
self.height = he
def display(self):
print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
def get_height(self):
return self.height
def get_weight(self):
return self.weight
def setup():
a= [student('James',58001,13,177,90),
student('Jane',58002,15,140,60),
student('John',58003,17,156,54),
student('Jonas',58004,20,188,70)]
i=0
while(i<len(a)):
a[i].display()
print('BMI = %.2f'%cal_bmi(a,i))
print('this ',find_more_BMI(a,i),'has BMI >25')
print()
i=i+1
def cal_bmi(a,i):
while(i<len(a)):
n=0
w = a[i].get_weight()
h = a[i].get_height()
bmi=w/(h/100)**2
return bmi
def find_more_BMI(a,i):
n=0
if(cal_bmi(a,i)>25):
n='one'
else:
n='one not'
return n
setup()
Lab7_Display_Student_Data
class student:
def __init__(self,names,idno,ages,we ,he ):
self.names = names
self.idNo = idno
self.age = ages
self.weight = we
self.height = he
def display(self):
print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
def setup():
j1=student('James',58001,13,177,50)
j2=student('Jane',58002,15,140,60)
j3=student('John',58003,17,156,54)
j4=student('Jonas',58004,20,188,70)
a=[j1,j2,j3,j4]
i=0
while(i<len(a)):
a[i].display()
i=i+1
setup()
def __init__(self,names,idno,ages,we ,he ):
self.names = names
self.idNo = idno
self.age = ages
self.weight = we
self.height = he
def display(self):
print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
def setup():
j1=student('James',58001,13,177,50)
j2=student('Jane',58002,15,140,60)
j3=student('John',58003,17,156,54)
j4=student('Jonas',58004,20,188,70)
a=[j1,j2,j3,j4]
i=0
while(i<len(a)):
a[i].display()
i=i+1
setup()
Lab6_Matrix_%and*
def setup():
m1=[[1,2,3],[4,5,6]]
m2=[[4,2,6],[14,19,15]]
SubtractMatrix(m1,m2)
MultipleMatrix(m1,m2)
def SubtractMatrix(a,b):
print('SubtractMatrix')
i=0
while(i<len(a)):
j=0
while(j<len(a[i])):
print(a[i][j]-b[i][j]," ",end = "")
j=j+1
i=i+1
print("")
def MultipleMatrix(a,b):
print('MultipleMatrix')
i=0
while(i<len(a)):
j=0
while(j<len(a[i])):
print(a[i][j]*b[i][j]," ",end = "")
j=j+1
i=i+1
print("")
setup()
m1=[[1,2,3],[4,5,6]]
m2=[[4,2,6],[14,19,15]]
SubtractMatrix(m1,m2)
MultipleMatrix(m1,m2)
def SubtractMatrix(a,b):
print('SubtractMatrix')
i=0
while(i<len(a)):
j=0
while(j<len(a[i])):
print(a[i][j]-b[i][j]," ",end = "")
j=j+1
i=i+1
print("")
def MultipleMatrix(a,b):
print('MultipleMatrix')
i=0
while(i<len(a)):
j=0
while(j<len(a[i])):
print(a[i][j]*b[i][j]," ",end = "")
j=j+1
i=i+1
print("")
setup()
Lab6_Matrix_showAndAdd
def setup():
m1=[[1,2,3],[4,5,6]]
m2=[[7,8,9],[10,11,12]]
addMatrix(m1,m2)
def showMatrix(a):
i=0
while(i<len(a)):
print(a[i])
i=i+1
def addMatrix(a,b):
i=0
while(i<len(a)):
j=0
while(j<len(a[i])):
print(a[i][j]+b[i][j]," ",end = "")
j=j+1
i=i+1
print("")
setup()
m1=[[1,2,3],[4,5,6]]
m2=[[7,8,9],[10,11,12]]
addMatrix(m1,m2)
def showMatrix(a):
i=0
while(i<len(a)):
print(a[i])
i=i+1
def addMatrix(a,b):
i=0
while(i<len(a)):
j=0
while(j<len(a[i])):
print(a[i][j]+b[i][j]," ",end = "")
j=j+1
i=i+1
print("")
setup()
Lab6_Find_maximum_chair_index
def setup():
floor1=[14,25,18,38]#building[0][0-3]
floor2=[34,21,48,24]#building[1][0-3]
floor3=[48,29,12,48]#building[2][0-3]
building = [floor1,floor2,floor3]
findRoomWithMaxChair(building)
def findRoomWithMaxChair(a):
i=0
j=0
maximum=0
while(j<len(a)):
while(i<len(a[j])):
if(maximum<a[j][i]):
maximum=a[j][i]
i=i+1
i=0
j=j+1
i=0
j=0
while(j<len(a)):
while(i<len(a[j])):
if(maximum == a[j][i]):
print('floor index:',j,',room index:',i)
i=i+1
i=0
j=j+1
setup()
floor1=[14,25,18,38]#building[0][0-3]
floor2=[34,21,48,24]#building[1][0-3]
floor3=[48,29,12,48]#building[2][0-3]
building = [floor1,floor2,floor3]
findRoomWithMaxChair(building)
def findRoomWithMaxChair(a):
i=0
j=0
maximum=0
while(j<len(a)):
while(i<len(a[j])):
if(maximum<a[j][i]):
maximum=a[j][i]
i=i+1
i=0
j=j+1
i=0
j=0
while(j<len(a)):
while(i<len(a[j])):
if(maximum == a[j][i]):
print('floor index:',j,',room index:',i)
i=i+1
i=0
j=j+1
setup()
Lab6_findIndexofMaximumChair
def setup():
floor1=[14,25,18,38]#building[0][0-3]
floor2=[34,21,28,24]#building[1][0-3]
floor3=[48,29,12,48]#building[2][0-3]
building = [floor1,floor2,floor3]
print('maximum chairs index is ',maxFloor(building))
def maxFloor(a):
i=0#chair
j=0#floor
j2=0
maximum=0
while(j<len(a)):
while(i<len(a[j])):
if(maximum<a[j][i]):
maximum=a[j][i]
j2=j
i=i+1
i=0
j=j+1
return j2
setup()
floor1=[14,25,18,38]#building[0][0-3]
floor2=[34,21,28,24]#building[1][0-3]
floor3=[48,29,12,48]#building[2][0-3]
building = [floor1,floor2,floor3]
print('maximum chairs index is ',maxFloor(building))
def maxFloor(a):
i=0#chair
j=0#floor
j2=0
maximum=0
while(j<len(a)):
while(i<len(a[j])):
if(maximum<a[j][i]):
maximum=a[j][i]
j2=j
i=i+1
i=0
j=j+1
return j2
setup()
Lab6_FindChairsInBuilding
def setup():
floor1=[14,25,18,38]#building[0][0-3]
floor2=[34,21,28,24]#building[1][0-3]
floor3=[24,29,12,48]#building[2][0-3]
building = [floor1,floor2,floor3]
print('there are ',sumChair(building),' chairs in the building')
def sumChair(a):
i=0#chair
j=0#floor
sums=0
while(j<len(a)):
while(i<len(a[j])):
sums=sums+a[j][i]
i=i+1
i=0
j=j+1
return sums
setup()
floor1=[14,25,18,38]#building[0][0-3]
floor2=[34,21,28,24]#building[1][0-3]
floor3=[24,29,12,48]#building[2][0-3]
building = [floor1,floor2,floor3]
print('there are ',sumChair(building),' chairs in the building')
def sumChair(a):
i=0#chair
j=0#floor
sums=0
while(j<len(a)):
while(i<len(a[j])):
sums=sums+a[j][i]
i=i+1
i=0
j=j+1
return sums
setup()
Lab6_DataAndWeight
def setup():
names=["Jack",'John','James','Jane']
idNo=['5801','5802','5803','5804']
age=[18,32,15,41]
weight=[40,69,72,49]
height=[150,162,170,159]
listthedata(names,idNo,age,weight,height)
print('the minimum weight is ',findminW(names,weight))
print('there are ',findMinWeiNumber(names,weight),'students < 50')
def listthedata(names,idNo,age,weight,height):
i=0
while(i<len(names)):
if(weight[i]<50):
print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
print()
i=i+1
def cal_bmi(i,weight,height):
bmi=(weight[i])/((height[i]/100)**2)
return bmi
def findminW(names,weight):
i=0
minimum=weight[0]
while(i<len(weight)):
if(minimum>weight[i]):
minimum=weight[i]
i=i+1
return minimum
def findMinWeiNumber(names,weight):
i=0
sums=0
while(i<len(names)):
if(weight[i]<50):
sums=sums+1
i=i+1
return sums
setup()
names=["Jack",'John','James','Jane']
idNo=['5801','5802','5803','5804']
age=[18,32,15,41]
weight=[40,69,72,49]
height=[150,162,170,159]
listthedata(names,idNo,age,weight,height)
print('the minimum weight is ',findminW(names,weight))
print('there are ',findMinWeiNumber(names,weight),'students < 50')
def listthedata(names,idNo,age,weight,height):
i=0
while(i<len(names)):
if(weight[i]<50):
print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
print()
i=i+1
def cal_bmi(i,weight,height):
bmi=(weight[i])/((height[i]/100)**2)
return bmi
def findminW(names,weight):
i=0
minimum=weight[0]
while(i<len(weight)):
if(minimum>weight[i]):
minimum=weight[i]
i=i+1
return minimum
def findMinWeiNumber(names,weight):
i=0
sums=0
while(i<len(names)):
if(weight[i]<50):
sums=sums+1
i=i+1
return sums
setup()
Lab6_DataAndAge
def setup():
names=["Jack",'John','James','Jane']
idNo=['5801','5802','5803','5804']
age=[18,32,15,41]
weight=[60,99,72,50]
height=[150,162,170,159]
listthedata(names,idNo,age,weight,height)
print(lessage30(names,age),'student < 30')
print('the avg age is',find_avgAge(names,age))
sortByAge(names,age)
def listthedata(names,idNo,age,weight,height):
i=0
while(i<len(names)):
print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
print()
i=i+1
def sortByAge(names,age):
j=1
while(j<len(age)):
n=age[j]
i=j-1
while(i >= 0) and (age[i] > n):
age[i+1]=age[i]
i=i-1
age[i+1] = n
j=j+1
print(age)
def cal_bmi(i,weight,height):
bmi=(weight[i])/((height[i]/100)**2)
return bmi
def lessage30(names,age):
i=0
sums=0
while(i<len(names)):
if(age[i]<30):
sums=sums+1
i=i+1
return sums
def find_avgAge(names,age):
i=0
sums=0
while(i<len(names)):
sums=sums+age[i]
i=i+1
avg=sums/len(names)
return avg
setup()
names=["Jack",'John','James','Jane']
idNo=['5801','5802','5803','5804']
age=[18,32,15,41]
weight=[60,99,72,50]
height=[150,162,170,159]
listthedata(names,idNo,age,weight,height)
print(lessage30(names,age),'student < 30')
print('the avg age is',find_avgAge(names,age))
sortByAge(names,age)
def listthedata(names,idNo,age,weight,height):
i=0
while(i<len(names)):
print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
print()
i=i+1
def sortByAge(names,age):
j=1
while(j<len(age)):
n=age[j]
i=j-1
while(i >= 0) and (age[i] > n):
age[i+1]=age[i]
i=i-1
age[i+1] = n
j=j+1
print(age)
def cal_bmi(i,weight,height):
bmi=(weight[i])/((height[i]/100)**2)
return bmi
def lessage30(names,age):
i=0
sums=0
while(i<len(names)):
if(age[i]<30):
sums=sums+1
i=i+1
return sums
def find_avgAge(names,age):
i=0
sums=0
while(i<len(names)):
sums=sums+age[i]
i=i+1
avg=sums/len(names)
return avg
setup()
วันเสาร์ที่ 31 ตุลาคม พ.ศ. 2558
Lab6_Data&BMI
def setup():
names=["Jack",'John','James','Jane']
idNo=['5801','5802','5803','5804']
age=[18,32,15,41]
weight=[60,99,72,50]
height=[150,162,170,159]
listthedata(names,idNo,age,weight,height)
find_moreBmi25(names,weight,height)
def listthedata(names,idNo,age,weight,height):
i=0
while(i<len(names)):
print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
print()
i=i+1
def cal_bmi(i,weight,height):
bmi=(weight[i])/((height[i]/100)**2)
return bmi
def find_moreBmi25(names,weight,height):
i=0
n=0
while(i<len(names)):
if(cal_bmi(i,weight,height)>25):
print(names[i],'has BMI > 25.')
n=n+1
i=i+1
print(n,' students that have BMI > 25.')
setup()
names=["Jack",'John','James','Jane']
idNo=['5801','5802','5803','5804']
age=[18,32,15,41]
weight=[60,99,72,50]
height=[150,162,170,159]
listthedata(names,idNo,age,weight,height)
find_moreBmi25(names,weight,height)
def listthedata(names,idNo,age,weight,height):
i=0
while(i<len(names)):
print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
print()
i=i+1
def cal_bmi(i,weight,height):
bmi=(weight[i])/((height[i]/100)**2)
return bmi
def find_moreBmi25(names,weight,height):
i=0
n=0
while(i<len(names)):
if(cal_bmi(i,weight,height)>25):
print(names[i],'has BMI > 25.')
n=n+1
i=i+1
print(n,' students that have BMI > 25.')
setup()
วันอาทิตย์ที่ 4 ตุลาคม พ.ศ. 2558
Lab5_Find/CountPositiveNo,_and_SumOfPositiveNo,
def setup():
n=[40,-70,-50,20,-73,79,-61,-77]
print('sum of positive values in array is ',calpositiveSum(n))
find_positive(n)
def calpositiveSum(n):
i=0
sums=0
while(i<len(n)):
if(n[i]>0):
sums=sums+n[i]
i=i+1
return sums
def find_positive(n):
i=0
count=0
while(i<len(n)):
if(n[i]>0):
count=count+1
print('the positive number is in index : ',i)
i=i+1
print('the number of positive number is',count)
setup()
n=[40,-70,-50,20,-73,79,-61,-77]
print('sum of positive values in array is ',calpositiveSum(n))
find_positive(n)
def calpositiveSum(n):
i=0
sums=0
while(i<len(n)):
if(n[i]>0):
sums=sums+n[i]
i=i+1
return sums
def find_positive(n):
i=0
count=0
while(i<len(n)):
if(n[i]>0):
count=count+1
print('the positive number is in index : ',i)
i=i+1
print('the number of positive number is',count)
setup()
Lab5_Find_Maximum_and_its_index
def setup():
n=[9,79,50,20,34,79,61,77]
find_max(n)
def find_max(n):
i=0
maximum=n[0]
while(i<len(n)):
if(maximum<n[i]):
maximum=n[i]
i=i+1
print('max no, is',maximum)
i=0
while(i<len(n)):
if(maximum==n[i]):
print('the index is',i)
i=i+1
setup()
n=[9,79,50,20,34,79,61,77]
find_max(n)
def find_max(n):
i=0
maximum=n[0]
while(i<len(n)):
if(maximum<n[i]):
maximum=n[i]
i=i+1
print('max no, is',maximum)
i=0
while(i<len(n)):
if(maximum==n[i]):
print('the index is',i)
i=i+1
setup()
Lab5_findMinimum
def setup():
n=[40,70,50,20,73,79,61,77]
print("min no. is",find_minimum(n),".")
def find_minimum(n):
i=0
minimum=n[0]
while(i<len(n)):
if(minimum>n[i]):
minimum=n[i]
i=i+1
return minimum
setup()
n=[40,70,50,20,73,79,61,77]
print("min no. is",find_minimum(n),".")
def find_minimum(n):
i=0
minimum=n[0]
while(i<len(n)):
if(minimum>n[i]):
minimum=n[i]
i=i+1
return minimum
setup()
Lab5_SumOfArray_and_AVG
def setup():
n=[40,70,50,20,73,79,61,77]
print('sum of values in array is ',find_sum(n))
print('the avg. of array is',find_avg(n))
def find_avg(n):
avg=(find_sum(n))/len(n)
return avg
def find_sum(n):
i=0
sums=0
while(i<len(n)):
sums=sums+n[i]
i=i+1
return sums
setup()
n=[40,70,50,20,73,79,61,77]
print('sum of values in array is ',find_sum(n))
print('the avg. of array is',find_avg(n))
def find_avg(n):
avg=(find_sum(n))/len(n)
return avg
def find_sum(n):
i=0
sums=0
while(i<len(n)):
sums=sums+n[i]
i=i+1
return sums
setup()
Lab5_ShowElement_and_ChangeValues
def setup():
n=[12,10,50,20,34,79,61,77]
show_number(n)
def show_number(n):
i=0
z=0
x=int(input())
while(z<len(n)):
n[z]=n[z]+x
z=z+1
while(i<len(n)):
print("No. is ",n[i]," and the index is",i)
i=i+1
setup()
n=[12,10,50,20,34,79,61,77]
show_number(n)
def show_number(n):
i=0
z=0
x=int(input())
while(z<len(n)):
n[z]=n[z]+x
z=z+1
while(i<len(n)):
print("No. is ",n[i]," and the index is",i)
i=i+1
setup()
วันอาทิตย์ที่ 20 กันยายน พ.ศ. 2558
Lab4x_Multiple_table
def setup():
n=int(input())
cal_result(n)
def cal_result(n):
count=12
mN=1
print("Multiple Table")
while (mN<=count):
ans=n*mN
print(n," x ",mN," = ",ans)
mN=mN+1
setup()
Lab4x_Plus_Number
def setup():
n = int(input())
calculate(n)
def calculate(n):
i=1
sums=0
while(i<=n):
print("i = ",i)
sums=sums+i
i=i+1
print("1+2+...+N,N = ",n)
print("The result is = ",sums)
setup()
Lab4x_Power_of_ten
def setup() :
power_number=int(input())
calculate(power_number)
def calculate(power_number) :
print("Value : 10 ^",power_number )
if (power_number==6) :
print("Million")
elif (power_number==9) :
print("Billion")
elif (power_number==12) :
print("Trillion")
elif (power_number==15) :
print("Quadrillion")
elif (power_number==18) :
print("Quintillion")
elif (power_number==21) :
print("Sextillion")
elif (power_number==30) :
print("Nonillion")
elif (power_number==100):
print("Googol")
else:
print("The value input doesn't have the word")
setup()
power_number=int(input())
calculate(power_number)
def calculate(power_number) :
print("Value : 10 ^",power_number )
if (power_number==6) :
print("Million")
elif (power_number==9) :
print("Billion")
elif (power_number==12) :
print("Trillion")
elif (power_number==15) :
print("Quadrillion")
elif (power_number==18) :
print("Quintillion")
elif (power_number==21) :
print("Sextillion")
elif (power_number==30) :
print("Nonillion")
elif (power_number==100):
print("Googol")
else:
print("The value input doesn't have the word")
setup()
Lab4x_Grade
def setup() :
score=int(input())
calculating(score)
showscore(score)
def calculating(score) :
if (score>=80) :
print("Your grade is A ." )
elif (score>=75) :
print("Your grade is B+ ." )
elif (score>=70) :
print("Your grade is B ." )
elif (score>=65) :
print("Your grade is C+ ." )
elif (score>=60) :
print("Your grade is C ." )
elif (score>=55) :
print("Your grade is D+ ." )
elif (score>=50) :
print("Your grade is D ." )
else :
print("Your grade is F ." )
def showscore(score):
print("Your score is ",score,".")
setup()
Lab4x_Leap_Year
def setup():
year_input=int(input())
calculate(year_input) #calculate the date
def calculate(year_input) :
if (year_input%4!=0):
print(year_input," isn't the Leap Year")
elif (year_input%100!=0):
print(year_input," is the Leap Year")
elif (year_input%400==0):
print(year_input," is the Leap Year")
else:
print(year_input," isn't the Leap Year")
setup()
year_input=int(input())
calculate(year_input) #calculate the date
def calculate(year_input) :
if (year_input%4!=0):
print(year_input," isn't the Leap Year")
elif (year_input%100!=0):
print(year_input," is the Leap Year")
elif (year_input%400==0):
print(year_input," is the Leap Year")
else:
print(year_input," isn't the Leap Year")
setup()
Lab4x_BMI
def setup():
w = int(input ())
h = int(input ())
calcu_bmi(w,h)
def calcu_bmi(w,h):
h2 = (h/100)**2
BMI = w/h2
print("Weight = ",w," Kg.")
print("Height = ",h," cm.")
print("Value Of BMI =%.2f"%BMI)
setup()
w = int(input ())
h = int(input ())
calcu_bmi(w,h)
def calcu_bmi(w,h):
h2 = (h/100)**2
BMI = w/h2
print("Weight = ",w," Kg.")
print("Height = ",h," cm.")
print("Value Of BMI =%.2f"%BMI)
setup()
Lab4x_Circle_Calculation
def setup() :
dm = int(input())
cal_circle(dm)
def cal_circle(dm):
r=dm/2
r_2=r*r
A=3.14*r_2
Cf=2*(3.14)*r
print("Value of circle's area = %.2f"%A,"m^2.")
print("Value of circumference's circle = %.2f"%Cf)
print("Diameter's circle = ",dm," m.")
print("Radius's circle = ",r," m.")
setup()
วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558
Lab4_Prime_Number
/////PRIME NUMBER////
void setup() {
size(500, 200);
background(0);
int n=15;//number
int count=2;
int sum=0;
int divNo=2;
int posx=0;
while (count<=n) {
if (PrNum_result(count)) {
sum=sum+count;
textSize(20);
text(count, 30+posx, 100);
posx=posx+30;
}
count+=1;
}
text("Sum is = "+sum, 30, 150);
}
boolean PrNum_result(int count) {
int divNo=2;
boolean pr=true; //first one =2
while (divNo<count) {
if (count%divNo==0) {
pr=false;
break;
}
pr=true;
divNo+=1;
}
return pr;
}
void setup() {
size(500, 200);
background(0);
int n=15;//number
int count=2;
int sum=0;
int divNo=2;
int posx=0;
while (count<=n) {
if (PrNum_result(count)) {
sum=sum+count;
textSize(20);
text(count, 30+posx, 100);
posx=posx+30;
}
count+=1;
}
text("Sum is = "+sum, 30, 150);
}
boolean PrNum_result(int count) {
int divNo=2;
boolean pr=true; //first one =2
while (divNo<count) {
if (count%divNo==0) {
pr=false;
break;
}
pr=true;
divNo+=1;
}
return pr;
}
Lab4_Loan_Payment
//LOAN PAYMENT//
void setup() {
size(550, 525);
background(0);
textSize(20);
fill(255);
/////////////TITLE//////////////
text("Monthly Loan Payment", 140, 30);
textSize(13);
fill(255);
////////////FLOAT&FUNTION(LOANPAYMENT)//////////
float loan_Amount = 5000; // loan amount
float loan_Term = 1; // loan term
float interest_Rate = 12; // interest rate
loanPymt(loan_Amount, loan_Term, interest_Rate);
}
////////// Function:Loanpayment/////////////////////////
void loanPymt(float loanAnt, float loanTm, float rate) {
loanTm = loanTm*12;//year
///Calculation///
float j = ((rate/100)/loanTm);
float paymentAnt = loanAnt*(j/(1-(pow(1+j, -loanTm))));
float payment12mths = paymentAnt*loanTm;
textSize(10);
text("Loan Amount : "+loanAnt, 60, 65);
text("Loan Term : "+(int)(loanTm)+" months", 60, 90);
text("Interest Rate : "+nf(rate, 0, 2)+" %", 60, 115);
text("Payment Every Month : "+nf(paymentAnt, 0, 2), 240, 65);
text("Total of 12 Payments : "+nf(payment12mths, 0, 2), 240, 90);
text("Total Interest : "+nf((payment12mths-loanAnt), 0, 2), 240, 115);
/////////////////////// LOOP (WHILE)////////////////
int count = 1;
float unpaid = loanAnt;
float totalInterest = 0;
int posy = 25;
////////Title////////////////
textSize(15);
text("Payment No.", 10, 155);
text("Interest", 110, 155);
text("Principal", 190, 155);
text("Unpaid Balance", 270, 155);
text("Total interest to Date", 390, 155);
while (count <= loanTm) {
float interest = unpaid*j;
totalInterest = totalInterest+interest;
float principal = paymentAnt - interest;
unpaid = abs(unpaid - principal);
/////////////result////////////
//nf(value, "dot total")
text(count, 40, 155+posy);
text(nf(interest, 0, 2), 110, 155+posy);
text(nf(principal, 0, 2), 190, 155+posy);
text(nf(unpaid, 0, 2), 290, 155+posy);
text(nf(totalInterest, 0, 2), 430, 155+posy);
count++;///////UPDATE//////////
posy=posy+30;////////POSITION Y//////////
}
}
size(550, 525);
background(0);
textSize(20);
fill(255);
/////////////TITLE//////////////
text("Monthly Loan Payment", 140, 30);
textSize(13);
fill(255);
////////////FLOAT&FUNTION(LOANPAYMENT)//////////
float loan_Amount = 5000; // loan amount
float loan_Term = 1; // loan term
float interest_Rate = 12; // interest rate
loanPymt(loan_Amount, loan_Term, interest_Rate);
}
////////// Function:Loanpayment/////////////////////////
void loanPymt(float loanAnt, float loanTm, float rate) {
loanTm = loanTm*12;//year
///Calculation///
float j = ((rate/100)/loanTm);
float paymentAnt = loanAnt*(j/(1-(pow(1+j, -loanTm))));
float payment12mths = paymentAnt*loanTm;
textSize(10);
text("Loan Amount : "+loanAnt, 60, 65);
text("Loan Term : "+(int)(loanTm)+" months", 60, 90);
text("Interest Rate : "+nf(rate, 0, 2)+" %", 60, 115);
text("Payment Every Month : "+nf(paymentAnt, 0, 2), 240, 65);
text("Total of 12 Payments : "+nf(payment12mths, 0, 2), 240, 90);
text("Total Interest : "+nf((payment12mths-loanAnt), 0, 2), 240, 115);
/////////////////////// LOOP (WHILE)////////////////
int count = 1;
float unpaid = loanAnt;
float totalInterest = 0;
int posy = 25;
////////Title////////////////
textSize(15);
text("Payment No.", 10, 155);
text("Interest", 110, 155);
text("Principal", 190, 155);
text("Unpaid Balance", 270, 155);
text("Total interest to Date", 390, 155);
while (count <= loanTm) {
float interest = unpaid*j;
totalInterest = totalInterest+interest;
float principal = paymentAnt - interest;
unpaid = abs(unpaid - principal);
/////////////result////////////
//nf(value, "dot total")
text(count, 40, 155+posy);
text(nf(interest, 0, 2), 110, 155+posy);
text(nf(principal, 0, 2), 190, 155+posy);
text(nf(unpaid, 0, 2), 290, 155+posy);
text(nf(totalInterest, 0, 2), 430, 155+posy);
count++;///////UPDATE//////////
posy=posy+30;////////POSITION Y//////////
}
}
Lab4_book
//FAV Book Function
//int posX=0; //fill value to move(X)
//int posY=0;//fill value to move(Y)
void setup() {
size(500, 500);
background(255);//white
int n=5;
int count=1;
int posy=0;
int posx=0;
while (count<n) {
book(posx, posy);
count=count+1;
posy=posy+15;
}
}
void book(int posX, int posY) {//function
fill(#B3CFF0);//blue
strokeWeight(8);//thick line
rect(80+posX, 130+posY, 340, 220);//body of book
strokeWeight(6);//thin line
fill(#78B2F7);//dark blue
rect(230+posX, 130+posY, 40, 220);//spine
rect(290+posX, 150+posY, 110, 60);//title's frame
fill(0);//black
textSize(30);
text("Conan", 300+posX, 190+posY);//Title
strokeWeight(3);//Thinest Line
line(250+posX, 130+posY, 120+posX, 100+posY);//pages1 r
line(250+posX, 130+posY, 110+posX, 108+posY);//pages2 r
line(250+posX, 130+posY, 100+posX, 115+posY);//pages3 r
line(120+posX, 100+posY, 80+posX, 130+posY);//pages border r
line(250+posX, 130+posY, 380+posX, 100+posY);//pages1 l
line(250+posX, 130+posY, 390+posX, 108+posY);//pages2 l
line(250+posX, 130+posY, 400+posX, 115+posY);//pages3 l
line(380+posX, 100+posY, 420+posX, 130+posY);//pages border l
}
//int posX=0; //fill value to move(X)
//int posY=0;//fill value to move(Y)
void setup() {
size(500, 500);
background(255);//white
int n=5;
int count=1;
int posy=0;
int posx=0;
while (count<n) {
book(posx, posy);
count=count+1;
posy=posy+15;
}
}
void book(int posX, int posY) {//function
fill(#B3CFF0);//blue
strokeWeight(8);//thick line
rect(80+posX, 130+posY, 340, 220);//body of book
strokeWeight(6);//thin line
fill(#78B2F7);//dark blue
rect(230+posX, 130+posY, 40, 220);//spine
rect(290+posX, 150+posY, 110, 60);//title's frame
fill(0);//black
textSize(30);
text("Conan", 300+posX, 190+posY);//Title
strokeWeight(3);//Thinest Line
line(250+posX, 130+posY, 120+posX, 100+posY);//pages1 r
line(250+posX, 130+posY, 110+posX, 108+posY);//pages2 r
line(250+posX, 130+posY, 100+posX, 115+posY);//pages3 r
line(120+posX, 100+posY, 80+posX, 130+posY);//pages border r
line(250+posX, 130+posY, 380+posX, 100+posY);//pages1 l
line(250+posX, 130+posY, 390+posX, 108+posY);//pages2 l
line(250+posX, 130+posY, 400+posX, 115+posY);//pages3 l
line(380+posX, 100+posY, 420+posX, 130+posY);//pages border l
}
Lab4_balloon
void draw() {
size(700, 700);
int x=mouseX;
int y=100;
int posY=-20;
int posX=0;
int count=1;
int n=5;
frameRate(20);
background(random(200), random(200), random(200));
if (x<100) {
x=100;
fill(#DD0000);
} else {
if (x>600) {
x=600;
}
if (x>100) {
fill(#0000DD);
}
if (x<600) {
fill(#00DD00);
}
}
while (count<n) {
draw_balloon(x, y, posY,posX);
count=count+1;
posY=posY+100;
posX=posX+100;
}
}
void draw_balloon(int x, int y, int posY,int posX) {
int radius = 100;
int string_length = 150;
strokeWeight(5);
line(x+posX, y+posY, x+posX, y + string_length+posY);
ellipse(x+posX, y+posY, radius, radius);
}
size(700, 700);
int x=mouseX;
int y=100;
int posY=-20;
int posX=0;
int count=1;
int n=5;
frameRate(20);
background(random(200), random(200), random(200));
if (x<100) {
x=100;
fill(#DD0000);
} else {
if (x>600) {
x=600;
}
if (x>100) {
fill(#0000DD);
}
if (x<600) {
fill(#00DD00);
}
}
while (count<n) {
draw_balloon(x, y, posY,posX);
count=count+1;
posY=posY+100;
posX=posX+100;
}
}
void draw_balloon(int x, int y, int posY,int posX) {
int radius = 100;
int string_length = 150;
strokeWeight(5);
line(x+posX, y+posY, x+posX, y + string_length+posY);
ellipse(x+posX, y+posY, radius, radius);
}
Lab4_Plus_Number
int value=0;
int n=1;
void setup() {
size(300, 300);
}
void draw() {
background(0);
frameRate(10);
int i=1;
int sum=0;
while (i<=n) {
println("i = "+i);
sum=sum+i;
i=i+1;
}
textSize(20);
text("1+2+...+N,N = "+n, 70, 130);
text("The result is = "+sum, 70, 190);
if (keyPressed) {
if (key=='w') {
n++;
} else if (key=='s') {
n--;
}
}
if (n<0) {
n=0;
}
}
int n=1;
void setup() {
size(300, 300);
}
void draw() {
background(0);
frameRate(10);
int i=1;
int sum=0;
while (i<=n) {
println("i = "+i);
sum=sum+i;
i=i+1;
}
textSize(20);
text("1+2+...+N,N = "+n, 70, 130);
text("The result is = "+sum, 70, 190);
if (keyPressed) {
if (key=='w') {
n++;
} else if (key=='s') {
n--;
}
}
if (n<0) {
n=0;
}
}
Lab4_Multiple_table
int n=1;
void setup() {
size(150, 350);
}
void draw() {
frameRate(10);//make it slow
background(0);
cal_result();
if (keyPressed) {/// can change the number///
if (key=='w') {
n=n+1;
} else if (key=='s')
n=n-1;
}
}
void cal_result() {//////// calculation function///////
int count=12;
int mN=1;
int posY=70;
fill(255);
textSize(15);
text("Multiple Table", 20, 40);
while (mN<=count) {
int ans=n*mN;
textSize(12);
text(n+" x "+mN+" = "+ans, 20, posY);
posY=posY+20;
mN=mN+1;
}
}
void setup() {
size(150, 350);
}
void draw() {
frameRate(10);//make it slow
background(0);
cal_result();
if (keyPressed) {/// can change the number///
if (key=='w') {
n=n+1;
} else if (key=='s')
n=n-1;
}
}
void cal_result() {//////// calculation function///////
int count=12;
int mN=1;
int posY=70;
fill(255);
textSize(15);
text("Multiple Table", 20, 40);
while (mN<=count) {
int ans=n*mN;
textSize(12);
text(n+" x "+mN+" = "+ans, 20, posY);
posY=posY+20;
mN=mN+1;
}
}
Lab4_Linkinpark
//FAV Song function
//int posX=random(0);//fill value to move(X)
//int posY=random(0);//fill value to move(Y)
int value=2;
int movex=0;
void setup() {
size(500, 500);
}
void draw() {
background(#0000DD);
int n=3;
int count=1;
int movey=-20;
while (count<n) {
movex++;
symbol(movex, movey);
count=count+1;
movey=movey+280;
}
movex=movex+value;
if (movex>400||value<0) {
value=-6;
}
if (movex<-200||value>0) {
value=2;
}
}
////////////// SYMBOL FUCNTION//////////////////
void symbol(int posX, int posY) {
//background's circle
stroke(255);//black line
strokeWeight(14);//thick line
fill(0);//line's color
ellipse(150+posX, 150+posY, 250, 250);//big circle with nothing inside of it
//Linkin Park symbol
line(160+posX, 25+posY, 85+posX, 190+posY);
line(85+posX, 190+posY, 225+posX, 190+posY);
line(225+posX, 190+posY, 175+posX, 80+posY);
line(175+posX, 80+posY, 95+posX, 260+posY);
//open the circle
stroke(0);
line(147+posX, 23+posY, 138+posX, 40+posY);
line(115+posX, 250+posY, 105+posX, 270+posY);
}
//int posX=random(0);//fill value to move(X)
//int posY=random(0);//fill value to move(Y)
int value=2;
int movex=0;
void setup() {
size(500, 500);
}
void draw() {
background(#0000DD);
int n=3;
int count=1;
int movey=-20;
while (count<n) {
movex++;
symbol(movex, movey);
count=count+1;
movey=movey+280;
}
movex=movex+value;
if (movex>400||value<0) {
value=-6;
}
if (movex<-200||value>0) {
value=2;
}
}
////////////// SYMBOL FUCNTION//////////////////
void symbol(int posX, int posY) {
//background's circle
stroke(255);//black line
strokeWeight(14);//thick line
fill(0);//line's color
ellipse(150+posX, 150+posY, 250, 250);//big circle with nothing inside of it
//Linkin Park symbol
line(160+posX, 25+posY, 85+posX, 190+posY);
line(85+posX, 190+posY, 225+posX, 190+posY);
line(225+posX, 190+posY, 175+posX, 80+posY);
line(175+posX, 80+posY, 95+posX, 260+posY);
//open the circle
stroke(0);
line(147+posX, 23+posY, 138+posX, 40+posY);
line(115+posX, 250+posY, 105+posX, 270+posY);
}
Lab4_Bird
int value =1;
int cenywing=250;
int ceny=250;
int cenx=250;
void setup() {
size(500, 500);
}
void draw() {
int n=5;
int count=1;
int posX=50;
int posY=-100;
background(255);
frameRate(40);
background(255);
if (value==1) {
background(#DD0000);
} else {
background(#00DD00);
}
while (count<n) {
draw_bird(posX, posY);
count=count+1;
posX=posX+50;
posY=posY+100;
}
ceny=ceny+value;
cenywing=cenywing+(value*2);
if (ceny>280&&cenywing>290) {
value--;
} else if (ceny<200&&cenywing<220) {
value++;
}
if (cenx>500) {
cenx=cenx%500;
}
if (keyPressed) {
if (key=='d'||key=='D') {
cenx+=3;
}
}
}
void draw_bird(int posX, int posY) {
int wing_L=100;
int radius_head=50;
strokeWeight(10);
//right wing
line(cenx+posX, ceny+posY, cenx+wing_L+posX, cenywing+posY);
//left wing
line(cenx+posX, ceny+posY, cenx-wing_L+posX, cenywing+posY);
ellipse(cenx+posX, ceny+posY, radius_head, radius_head);
}
int cenywing=250;
int ceny=250;
int cenx=250;
void setup() {
size(500, 500);
}
void draw() {
int n=5;
int count=1;
int posX=50;
int posY=-100;
background(255);
frameRate(40);
background(255);
if (value==1) {
background(#DD0000);
} else {
background(#00DD00);
}
while (count<n) {
draw_bird(posX, posY);
count=count+1;
posX=posX+50;
posY=posY+100;
}
ceny=ceny+value;
cenywing=cenywing+(value*2);
if (ceny>280&&cenywing>290) {
value--;
} else if (ceny<200&&cenywing<220) {
value++;
}
if (cenx>500) {
cenx=cenx%500;
}
if (keyPressed) {
if (key=='d'||key=='D') {
cenx+=3;
}
}
}
void draw_bird(int posX, int posY) {
int wing_L=100;
int radius_head=50;
strokeWeight(10);
//right wing
line(cenx+posX, ceny+posY, cenx+wing_L+posX, cenywing+posY);
//left wing
line(cenx+posX, ceny+posY, cenx-wing_L+posX, cenywing+posY);
ellipse(cenx+posX, ceny+posY, radius_head, radius_head);
}
วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558
Lab3_Leap_Year
LEAP YEAR
void setup() {
size(500, 500);
background(255);//white
calculate(2016);//calculate the date
}
void calculate(int year_input) {
int posx=80;
int posy=250;
textSize(30);
fill(0);//black
////fucntion calculation////
if (year_input%4!=0) {
text(year_input+" isn't the Leap Year", posx, posy);
} else if (year_input%100!=0) {
text(year_input+" is the Leap Year", posx, posy);
} else if (year_input%400==0) {
text(year_input+" is the Leap Year", posx, posy);
} else{
text(year_input+" isn't the Leap Year", posx, posy);
}
}
Lab3_Exercise
Exercise
setup มีการเรียกใช้อัตโนมัติเพียงครั้งเดียวdraw มีการเรียกใช้อัตโนมัติซ้ำ
พิสูจน์ได้อย่างไร
ตอบ พิสูจน์ได้ด้วยการจะเห็นว่าเมื่อมีการทำ Animation นั้นจะใช้ void draw() ในการใส่คำสั่งให้รัน เพราะว่า draw จะทำการรันซ้ำๆทำให้เกิดการเคลื่อนไหว ดัง Code ตัวอย่างนี้
Ex.
int posX=50;
void setup() {
size(300, 300);
}
void draw() {
background(0);
ellipse(posX, 150, 50, 50);
posX++;
posX=posX%300;
}
Lab3_Song
LINKINPARK
//FAV Song function
//int posX=random(0);//fill value to move(X)
//int posY=random(0);//fill value to move(Y)
int movex;
int movey;
int value=2;
void setup() {
int movex;
int movey;
int value=2;
void setup() {
size(500, 500);
}
void draw() {
movex=value+movex;
if (movex>200||value<0) {
value=-4;
background(#0000DD);
symbol(movex, movey);
}
if (movex<-200||value>0) {
value=4;
background(#DD0000);
symbol(movex, movey);
}
}
}
void draw() {
movex=value+movex;
if (movex>200||value<0) {
value=-4;
background(#0000DD);
symbol(movex, movey);
}
if (movex<-200||value>0) {
value=4;
background(#DD0000);
symbol(movex, movey);
}
}
void symbol(int posX, int posY) {//function
//background's circle
stroke(255);//black line
strokeWeight(14);//thick line
fill(0);//line's color
ellipse(250+posX, 250+posY, 250, 250);//big circle with nothing inside of it
//Linkin Park symbol
line(260+posX, 125+posY, 185+posX, 290+posY);
line(185+posX, 290+posY, 325+posX, 290+posY);
line(325+posX, 290+posY, 275+posX, 180+posY);
line(275+posX, 180+posY, 195+posX, 360+posY);
//open the circle
stroke(0);
line(247+posX, 123+posY, 238+posX, 140+posY);
line(215+posX, 350+posY, 205+posX, 370+posY);
}
}
Lab3_Bird
BIRD
int value =1;
int cenywing=250;
int ceny=250;
int cenx=250;
void setup() {
size(500, 500);
}
void draw() {
frameRate(40);
background(255);
if (value==1) {
background(#DD0000);
}else {
background(#00DD00);
}
draw_bird();
//make the bird fly
ceny=ceny+value;
cenywing=cenywing+(value*2);
if (ceny>280&&cenywing>290) {
value--;
} else if (ceny<200&&cenywing<220) {
value++;
}
if(cenx>500){
cenx=cenx%500;
}
if (keyPressed) {
if (key=='d'||key=='D') {
cenx+=3;
}
}
}
void draw_bird() {
int wing_L=100;
int radius_head=50;
strokeWeight(10);
//right wing
line(cenx, ceny, cenx+wing_L, cenywing);
//left wing
line(cenx, ceny, cenx-wing_L, cenywing);
ellipse(cenx, ceny, radius_head, radius_head);
}
int cenywing=250;
int ceny=250;
int cenx=250;
void setup() {
size(500, 500);
}
void draw() {
frameRate(40);
background(255);
if (value==1) {
background(#DD0000);
}else {
background(#00DD00);
}
draw_bird();
//make the bird fly
ceny=ceny+value;
cenywing=cenywing+(value*2);
if (ceny>280&&cenywing>290) {
value--;
} else if (ceny<200&&cenywing<220) {
value++;
}
if(cenx>500){
cenx=cenx%500;
}
if (keyPressed) {
if (key=='d'||key=='D') {
cenx+=3;
}
}
}
void draw_bird() {
int wing_L=100;
int radius_head=50;
strokeWeight(10);
//right wing
line(cenx, ceny, cenx+wing_L, cenywing);
//left wing
line(cenx, ceny, cenx-wing_L, cenywing);
ellipse(cenx, ceny, radius_head, radius_head);
}
Lab3_Doraemon
Doraemon
//MY FAV MOVIE//int posX=0;//fill value to move(Horizontal)
//int posY=0;//fill value to move(Vertical)
int posX;
int posY;
void setup() {
size(500, 500);
}
void draw() {
background(#FACFF4);
doraemon();
if (keyPressed) {
if (key =='a' || key =='A') {
posX--;
}if (key =='d' || key =='D') {
posX++;
} if (key =='w' || key =='W') {
posY--;
} if (key =='s' || key =='S') {
posY++;
}
}
}
void doraemon() {
stroke(#0054A5);
strokeWeight(3);
fill(#236ED6);//blue
ellipse(250+posX, 180+posY, 350, 295);//head
fill(255);//white
ellipse(250+posX, 210+posY, 250, 205);//face
ellipse(210+posX, 120+posY, 80, 100);//right hand
ellipse(290+posX, 120+posY, 80, 100);//left hand
fill(#F21D1D);//red
rect(110+posX, 300+posY, 280, 30);//cat collar
fill(255);//white
ellipse(120+posX, 300+posY, 60, 60);//right eye
ellipse(380+posX, 300+posY, 60, 60);//left eye
fill(#FF292D);//red
ellipse(250+posX, 175+posY, 45, 40);//nose
fill(255);//white
arc(250+posX, 235+posY, 180, 50, 0, PI);//cute smile <3
fill(#FAD449);//gold or yellow
ellipse(250+posX, 300+posY, 40, 40);//bell
fill(#3C60B9);//blue
ellipse(225+posX, 135+posY, 20, 20);//inner eye(right)
ellipse(275+posX, 135+posY, 20, 20);//inner eye(left)
line(250+posX, 194+posY, 250+posX, 260+posY);//mouth (line)
line(210+posX, 210+posY, 140+posX, 210+posY);// cat's whiskers mid right
line(290+posX, 210+posY, 360+posX, 210+posY);// cat's whiskers mid left
line(210+posX, 220+posY, 140+posX, 230+posY);// cat's whiskers below right
line(290+posX, 220+posY, 360+posX, 230+posY);// cat's whiskers below left
line(210+posX, 200+posY, 140+posX, 190+posY);// cat's whiskers above right
line(290+posX, 200+posY, 360+posX, 190+posY);// cat's whiskers mid left
line(232+posX, 290+posY, 267+posX, 290+posY);//bell line1
line(210+posX, 300+posY, 290+posX, 300+posY);//bell line2
strokeWeight(7);
line(250+posX, 302+posY, 250+posX, 320+posY);//bell line3
stroke(255);//white line
fill(255);//white
ellipse(258+posX, 170+posY, 12, 12);//reflect nose
}
Lab3_Delivery_Service
Delivery Services
void setup() {
size(500, 300);
background(#D16565);
textSize(30);
text("Expressimo Delivery Service", 50, 100);
/////1=Next Day Priority 2=Next Day Standard 3=2-Day/////
/////fill the detail//////
calculate_letter(0,0);
calculate_box(1,8);
}
void calculate_letter(int weight, int type_service) {
textSize(20);
///////////// SERVICE OF LETTER////////////
if (weight<=8&&type_service==1) {
text("Letter "+weight+" Oz", 100, 200);
text("Charges = $12.00", 100, 250);
text(": Next Day Priority", 220, 200);
} else if (weight<=8&&type_service==2) {
text("Letter "+weight+" Oz", 100, 200);
text("Charges = $10.50", 100, 250);
text(": Next Day Standrard", 220, 200);
} else if (weight>8||type_service>2) {
textSize(25);
text("Not available", 170, 250);
}
}
void calculate_box(int weight, int type_service) {
float value1=(weight-1)*1.25;
float charge1=15.75;
float value2=(weight-1)*1.00;
float charge2=13.75;
float value3=(weight-1)*0.50;
float charge3=7.00;
textSize(20);
///////////// SERVICE OF BOX////////////
if (weight==1&&type_service==1) {
text("Box "+weight+" pound", 100, 200);
text("Charge = $15.75", 100, 250);
text(": Next Day Priority", 270, 200);
}
if (weight>1&&type_service==1) {
text("Box "+weight+" pounds", 100, 200);
text("Charges = $"+(charge1+value1), 100, 250);
text(": Next Day Priority", 270, 200);
}
if (weight==1&&type_service==2) {
text("Box "+weight+" pound", 100, 200);
text("Charge = $13.75", 100, 250);
text(": Next Day Standrad", 270, 200);
}
if (weight>1&&type_service==2) {
text("Box "+weight+" pounds", 100, 200);
text("Charges = $"+(charge2+value2), 100, 250);
text(": Next Day Standrad", 270, 200);
}
if (weight==1&&type_service==3) {
text("Box "+weight+" pound", 100, 200);
text("Charge = $7.00", 100, 250);
text(": 2-Day", 270, 200);
}
if (weight>1&&type_service==3) {
text("Box "+weight+" pounds", 100, 200);
text("Charges = $"+(charge3+value3), 100, 250);
text(": 2-Day", 270, 200);
}else if (type_service>3) {
textSize(25);
text("Not available", 170, 250);
}
}
size(500, 300);
background(#D16565);
textSize(30);
text("Expressimo Delivery Service", 50, 100);
/////1=Next Day Priority 2=Next Day Standard 3=2-Day/////
/////fill the detail//////
calculate_letter(0,0);
calculate_box(1,8);
}
void calculate_letter(int weight, int type_service) {
textSize(20);
///////////// SERVICE OF LETTER////////////
if (weight<=8&&type_service==1) {
text("Letter "+weight+" Oz", 100, 200);
text("Charges = $12.00", 100, 250);
text(": Next Day Priority", 220, 200);
} else if (weight<=8&&type_service==2) {
text("Letter "+weight+" Oz", 100, 200);
text("Charges = $10.50", 100, 250);
text(": Next Day Standrard", 220, 200);
} else if (weight>8||type_service>2) {
textSize(25);
text("Not available", 170, 250);
}
}
void calculate_box(int weight, int type_service) {
float value1=(weight-1)*1.25;
float charge1=15.75;
float value2=(weight-1)*1.00;
float charge2=13.75;
float value3=(weight-1)*0.50;
float charge3=7.00;
textSize(20);
///////////// SERVICE OF BOX////////////
if (weight==1&&type_service==1) {
text("Box "+weight+" pound", 100, 200);
text("Charge = $15.75", 100, 250);
text(": Next Day Priority", 270, 200);
}
if (weight>1&&type_service==1) {
text("Box "+weight+" pounds", 100, 200);
text("Charges = $"+(charge1+value1), 100, 250);
text(": Next Day Priority", 270, 200);
}
if (weight==1&&type_service==2) {
text("Box "+weight+" pound", 100, 200);
text("Charge = $13.75", 100, 250);
text(": Next Day Standrad", 270, 200);
}
if (weight>1&&type_service==2) {
text("Box "+weight+" pounds", 100, 200);
text("Charges = $"+(charge2+value2), 100, 250);
text(": Next Day Standrad", 270, 200);
}
if (weight==1&&type_service==3) {
text("Box "+weight+" pound", 100, 200);
text("Charge = $7.00", 100, 250);
text(": 2-Day", 270, 200);
}
if (weight>1&&type_service==3) {
text("Box "+weight+" pounds", 100, 200);
text("Charges = $"+(charge3+value3), 100, 250);
text(": 2-Day", 270, 200);
}else if (type_service>3) {
textSize(25);
text("Not available", 170, 250);
}
}
วันเสาร์ที่ 5 กันยายน พ.ศ. 2558
Lab3_Battery
Battery Charging
int space;
int value=1;
void setup() {
size(500, 500);
}
void draw() {
frameRate(30);
background(255);//white
battery(80, 140);
space=space+value;
if (space==300) {
value=0;
value=value-1;
} else if (space==0&&value<0) {
value=0;
value=value+1;
}
int percent=(space*100)/300;
textSize(50);
fill(random(255), random(255), random(255));//rainbow color
text((int)percent+"%", 210, 400);
if (percent<10&&value==1) {
text("Charging", 130, 100);
}
if (percent>95) {
text("Full", 200, 100);
}
}
void battery(int countX, int countY) {
int w=300;//width
int h=120;//height
stroke(0);//dark blue
strokeWeight(4);
fill(255);//white
//big square
rect(countX, countY, w, h);
fill(255);//white
//batt head
rect(countX+300, countY+35, w/9, h-70);
//batt symbol
strokeWeight(10);
// + symbol
line(countX+350, countY-50, countX+350, countY+10);
line(countX+320, countY-20, countX+380, countY-20);
/// - Symbol
line(countX-60, countY-20, countX-10, countY-20);
//battery quntity
strokeWeight(2);
if (space>0) {
fill(#DD0000);
}
if (space>70) {
fill(#F5ED00);
}
if (space>230) {
fill(#69E376);
}
rect(countX, countY, space, h);//#1 batt
}
Lab3_Score
การตัดเกรด
int score=99;// score that you get
void setup() {
size(500, 500);
calculating(100,300);
showscore(100, 200);
}
void calculating(int cX,int cY) {
background(0);
textSize(40);
if (score>=80) {
text("Your grade is A .", cX, cY);
} else if (score>=75) {
text("Your grade is B+ .", cX, cY);
} else if (score>=70) {
text("Your grade is B .", cX, cY);
} else if (score>=65) {
text("Your grade is C+ .", cX, cY);
} else if (score>=60) {
text("Your grade is C .", cX, cY);
} else if (score>=55) {
text("Your grade is D+ .", cX, cY);
} else if (score>=50) {
text("Your grade is D .", cX, cY);
} else {
text("Your grade is F .", cX, cY);
}
}
void showscore(int x, int y) {//showscore
text("Your score is "+score+".", x, y);
}
Lab3_Power_of_ten
Power of ten
void setup() {
size(300, 500);
background(255);
draw_number_form(170, 100);
fill(#0000DD);
textSize(15);
//////////////// INPUT VALUE//////////////
calculate(19);
//////////////////////////////////////////
}
void draw_number_form(int posX, int posY) {
fill(0);
textSize(25);
text("Power of Ten", 20, 50);
//// number's word code
textSize(25);
text("Number", posX, posY);
text("Value", 40, 100);
textSize(20);
text("Million", posX, posY+40);
text("Billion", posX, posY+80);
text("Trillion", posX, posY+120);
text("Quadrillion", posX, posY+160);
text("Quintillion", posX, posY+200);
text("Sextillion", posX, posY+240);
text("Nonillion", posX, posY+280);
text("Googol", posX, posY+320);
}
void calculate(int power_number) {
int posX=40;//position X
int posY=100;// position y
text("Value : 10^"+power_number,190,50);
/////show the input value////
if (power_number==6) {
text("10"+"^"+power_number, posX, posY+40);
} else if (power_number==9) {
text("10"+"^"+power_number, posX, posY+80);
} else if (power_number==12) {
text("10"+"^"+power_number, posX, posY+120);
} else if (power_number==15) {
text("10"+"^"+power_number, posX, posY+160);
} else if (power_number==18) {
text("10"+"^"+power_number, posX, posY+200);
} else if (power_number==21) {
text("10"+"^"+power_number, posX, posY+240);
} else if (power_number==30) {
text("10"+"^"+power_number, posX, posY+280);
} else if (power_number==100) {
text("10"+"^"+power_number, posX, posY+320);
} else {
fill(#DD0000);
text("The value input doesn't have the word", 10, 480);
}
}
size(300, 500);
background(255);
draw_number_form(170, 100);
fill(#0000DD);
textSize(15);
//////////////// INPUT VALUE//////////////
calculate(19);
//////////////////////////////////////////
}
void draw_number_form(int posX, int posY) {
fill(0);
textSize(25);
text("Power of Ten", 20, 50);
//// number's word code
textSize(25);
text("Number", posX, posY);
text("Value", 40, 100);
textSize(20);
text("Million", posX, posY+40);
text("Billion", posX, posY+80);
text("Trillion", posX, posY+120);
text("Quadrillion", posX, posY+160);
text("Quintillion", posX, posY+200);
text("Sextillion", posX, posY+240);
text("Nonillion", posX, posY+280);
text("Googol", posX, posY+320);
}
void calculate(int power_number) {
int posX=40;//position X
int posY=100;// position y
text("Value : 10^"+power_number,190,50);
/////show the input value////
if (power_number==6) {
text("10"+"^"+power_number, posX, posY+40);
} else if (power_number==9) {
text("10"+"^"+power_number, posX, posY+80);
} else if (power_number==12) {
text("10"+"^"+power_number, posX, posY+120);
} else if (power_number==15) {
text("10"+"^"+power_number, posX, posY+160);
} else if (power_number==18) {
text("10"+"^"+power_number, posX, posY+200);
} else if (power_number==21) {
text("10"+"^"+power_number, posX, posY+240);
} else if (power_number==30) {
text("10"+"^"+power_number, posX, posY+280);
} else if (power_number==100) {
text("10"+"^"+power_number, posX, posY+320);
} else {
fill(#DD0000);
text("The value input doesn't have the word", 10, 480);
}
}
วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558
Lab3_Example_Balloon
ตัวอย่าง บอลลูน
void draw() {
size(ุ600, 300);
frameRate(20);
background(random(200), random(200), random(200));//random RGB background
int x=mouseX;
int y=100;
if (x<100) {
x=100;
fill(#DD0000);
} else {
if (x>500) {
x=500;
}
if (x>100) {
fill(#0000DD);
}
if (x<500) {
fill(#00DD00);
}
}
draw_balloon(x, y);
}
//balloon funnction
void draw_balloon(int x, int y) {
int radius = 100;
int string_length = 150;
strokeWeight(13);
line(x, y, x, y + string_length);
ellipse(x, y, radius, radius);
}
size(ุ600, 300);
frameRate(20);
background(random(200), random(200), random(200));//random RGB background
int x=mouseX;
int y=100;
if (x<100) {
x=100;
fill(#DD0000);
} else {
if (x>500) {
x=500;
}
if (x>100) {
fill(#0000DD);
}
if (x<500) {
fill(#00DD00);
}
}
draw_balloon(x, y);
}
//balloon funnction
void draw_balloon(int x, int y) {
int radius = 100;
int string_length = 150;
strokeWeight(13);
line(x, y, x, y + string_length);
ellipse(x, y, radius, radius);
}
Lab2_อาการ Syntax Error ต่างๆ
SYNTAX ERROR
Syntax error เกิดจากการที่เราเขียนโค้ดไม่ตรงตามหลักการเขียนที่โปรแกรมกำหนดเอาไว้ การเกิด syntax error ที่เกิดขึ้นได้บ่อยๆ มีดังนี้1.Expecting EOF,found "}" หรือการใส่ปีกกาเกิน
-เกิดจากที่เราใส่ปีกกาเกินตัวฟังก์ชันของมัน
-แก้ไขโดยการลบปีกกาตัวที่เกินออกไป
2.Missing a semicolon ( ; ) หรือการลืมใส่ semicolon ;
- เกิดจากที่เราลืมใส่ semicolon ต่อท้ายฟังก์ชันบางตัว
-แก้ไขว่าลืมใส่ตรงไหน โดยดูที่แถบด้านขวาที่ขึ้นเป็นขีดๆแดงๆ จากนั้นก็ใส่ให้เรียบร้อย
3.Unexpected token: fffff หรือ การไม่พบสัญลักษณ์ที่เกิดขึ้น
-เกิดจากเราเขียนตัวหนังสือลงไปเลย โดยที่ไม่ใช่การคำนวณ ไม่ใช่ฟังก์ชัน ไม่ใช่สัญลักษณ์ของโปรแกรม
-แก้ไขโดยการลบตัวหนังสือนั้นออก
4.Cannot convert from float to int หรือ การที่ไม่สามารถเปลี่ยนชนิด class ได้
-เกิดจากการใช้ class ผิด Syntax ของมัน เช่น คำสั่ง random นั้น syntax ของมันคือ random(float,float) แต่เราใช้ไปเก็บค่าไว้ในตัวแปร int หรือ เรานำข้อมูล float ไปใส่ใน int มันจึงเก็บค่าไม่ได้
-แก้ไข้โดยการเปลี่ยนชนิดตัวแปรที่ไว้เก็บค่า ให้เป็นชนิด float จึงจะเก็บค่าได้
5. The variable "posX" does not exist หรือ การไม่พบตัวแปร
-เกิดจากเราไม่ได้กำหนดตัวแปรนั้น หรือ เราพิมชื่อตัวแปรนั้นผิด
-แก้ไขโดยเช็คชื่อตัวแปรนั้น หรือกำหนดตัวแปรนั้นขึ้นมา
6.การใส่ค่าไม่ครบใน Parameter
-เกิดจากเราใส่ค่าใน Parameter ไม่ครบจำนวนตามที่เรากำหนดไว้ เช่น void Positive(int posX , int posY); เรากำหนดตัว Argument ไว้เป็น posX และ posY เวลาเราเรียกใช้งานฟังก์ชัน เราใส่ Positive(50); แบบนี้จะขึ้น syntax error เพราะว่าเรากำหนดไว้ให้ใส่ไป 2 ค่า แต่เราใส่แค่ค่าเดียว
-แก้ไขโดยการเช็คตัว Argument ว่าเรากำหนดไว้กี่ค่า จากนั้นก็ใส่ค่า Parameter ให้ครบตามที่เรากำหนดไว้
Lab2_Positive_Sign
Positvie Sign by Function
//Positive Sign
int colors=0;
void setup() {
size(500, 500);
}
void draw() {
background(#FF0D0D);//red
positive();
}
void positive() {
int dX=120;//diameterX
int dY=160;//diameterY
int w=100;//weight
int h=100;//height
//rectangular area
stroke(255);
strokeWeight(0);
fill(colors);
rect(dX, dY, w*3, h);//horizontal rect
rect(dX+100, dY-100, w, h*3);//vertical rect
}
void mousePressed() {
if (colors == 0) {
colors = 255;
} else {
colors = 0;
}
}
Lab2_Battery_Function
Battery follow the Cursor!!
void setup() {
size(500, 500);
}
void draw() {
background(255);//white
battery(mouseX, mouseY);
}
void battery(int countX, int countY) {
int space=40;
int w=180;//width
int h=90;//height
stroke(#0041E0);//dark blue
strokeWeight(8);
fill(#0393FF);//blue
//big square
rect(countX, countY, w, h);
fill(255);//white
//batt head
rect(countX+180, countY+35, w/9, h-70);
//battery quntity
fill(#FF0011);//red
rect(countX, countY, space, h);//#1 batt
rect(countX+space, countY, space, h);//#2 batt
rect(countX+space*2, countY, space, h);//#3 batt
rect(countX+space*3, countY, space, h);//#4 batt
}
Lab2_BMI_Function
BMI's Calculation by Function
//BMI Function
void setup() {
size(300,300);
background(#FF8B8B);//pink
calculation(80,175);
}
void calculation(int w,int h){
float h_2=(h/100.0)*(h/100.0);//Height^2
float BMI=w/h_2;//value of BMI
//terminal output
print("Value Of BMI="+BMI);
//explaining text
textSize(24);//size of text
text("Weight = "+w+" Kg.",30,100);
text("Height = "+h+" cm.",30,140);
text("BMI="+BMI+"",30,180);
}
Lab2_Circle'sCalculation_Function
Circle's Calculation by Function
//Circle's Calculationint posx=100;
int posy=100;
int dm=160 ;//diameter
void setup() {
size(500, 500);
circle(100, 100);
calculation();
}
void circle(int posx, int posy) {
background(#FC66C1);//pink <3
ellipse(posx, posy, dm, dm);//example
}
void calculation() {
float r=dm/2;//radius
float r_2=r*r;//radius square
float A=3.14*r_2;//area
float cf=2*(3.14)*r;//circumference
//terminal output
println("Value of circle's area = "+A);
print("Value of circumference's circle = "+cf);
textSize(24);//text size
text("Circumference's circle = "+cf+" m.", 30, 400);
text("Area's circle = "+A+" m^2.", 30, 350);
text("Diameter's circle = "+dm+" m.", 30, 250);
text("Radius's circle = "+r+" m.", 30, 300);
}
Lab2_Book_Function
Book use Function
//FAV Book Function
//int posX=0; //fill value to move(X)
//int posY=0;//fill value to move(Y)
void setup() {
size(500, 500);
background(255);//white
book(0, 0);
}
void book(int posX, int posY) {//function
fill(#B3CFF0);//blue
strokeWeight(8);//thick line
rect(80+posX, 130+posY, 340, 220);//body of book
strokeWeight(6);//thin line
fill(#78B2F7);//dark blue
rect(230+posX, 130+posY, 40, 220);//spine
rect(290+posX, 150+posY, 110, 60);//title's frame
fill(0);//black
textSize(30);
text("Conan", 300+posX, 190+posY);//Title
strokeWeight(3);//Thinest Line
line(250+posX, 130+posY, 120+posX, 100+posY);//pages1 r
line(250+posX, 130+posY, 110+posX, 108+posY);//pages2 r
line(250+posX, 130+posY, 100+posX, 115+posY);//pages3 r
line(120+posX, 100+posY, 80+posX, 130+posY);//pages border r
line(250+posX, 130+posY, 380+posX, 100+posY);//pages1 l
line(250+posX, 130+posY, 390+posX, 108+posY);//pages2 l
line(250+posX, 130+posY, 400+posX, 115+posY);//pages3 l
line(380+posX, 100+posY, 420+posX, 130+posY);//pages border l
}
Lab2_Song_Function
Song use Function
//FAV Song function
//int posX=0;//fill value to move(X)
//int posY=0;//fill value to move(Y)
void setup() {
size(500, 500);
background(0);//black
symbol(0,0);
}
void symbol(int posX,int posY){//function
//background's circle
stroke(255);//black line
strokeWeight(14);//thick line
fill(0);//line's color
ellipse(250+posX, 250+posY, 250, 250);//big circle with nothing inside of it
//Linkin Park symbol
line(260+posX, 125+posY, 185+posX, 290+posY);
line(185+posX, 290+posY, 325+posX, 290+posY);
line(325+posX, 290+posY, 275+posX, 180+posY);
line(275+posX, 180+posY, 195+posX, 360+posY);
//open the circle
stroke(0);
line(258+posX, 100+posY, 238+posX, 140+posY);
line(215+posX, 350+posY, 200+posX, 380+posY);
//title
fill(255);
textSize(40);
textAlign(LEFT);
text("LINKIN PARK", 135+posX, 450+posY);
}
สมัครสมาชิก:
บทความ (Atom)