def setup():
first = [15,13,7,11,9]
second = [19,12,22,29,25]
third = [23,20,34,33,35]
fourth = [49,38,33,45,41]
floor = [first,second,third,fourth]
ifloor = 0
total = 0
while(ifloor<len(floor)):
iroom = 0
while(iroom<len(floor[ifloor])):
total = total+floor[ifloor][iroom]
iroom = iroom+1
ifloor = ifloor+1
print("Total number of chairs =",total)
setup()
วันอังคารที่ 24 พฤศจิกายน พ.ศ. 2558
Lab 6 : Display student records with weight < 50
def setup():
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,49,86,71]
age = [25,18,52,43]
i = 0
while(i<len(weight)):
if(weight[i]<50):
print(name[i],age[i],"years old",height[i],"cm.",weight[i],"kg.")
i = i+1
setup()
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,49,86,71]
age = [25,18,52,43]
i = 0
while(i<len(weight)):
if(weight[i]<50):
print(name[i],age[i],"years old",height[i],"cm.",weight[i],"kg.")
i = i+1
setup()
Lab 6 : Find/count number of students with weight < 50
def setup():
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,49,86,71]
age = [25,18,52,43]
i = 0
count = 0
while(i<len(weight)):
if(weight[i]<50):
count = count+1
print(name[i]," = ",weight[i],"kg.")
i = i+1
print("Total student weight<50 =",count)
setup()
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,49,86,71]
age = [25,18,52,43]
i = 0
count = 0
while(i<len(weight)):
if(weight[i]<50):
count = count+1
print(name[i]," = ",weight[i],"kg.")
i = i+1
print("Total student weight<50 =",count)
setup()
Lab 6 : Find/count number of students with age < 30
def setup():
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
age = [25,18,52,43]
i = 0
count = 0
while(i<len(age)):
if(age[i]<30):
count = count+1
print(name[i]," = ",age[i]," years old")
i = i+1
print("Total student age<30 = ",count)
setup()
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
age = [25,18,52,43]
i = 0
count = 0
while(i<len(age)):
if(age[i]<30):
count = count+1
print(name[i]," = ",age[i]," years old")
i = i+1
print("Total student age<30 = ",count)
setup()
Lab 6 : Find/count number of students with BMI > 25
def setup():
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
age = [25,18,52,43]
i = 0
count = 0
while(i<len(name)):
if(bmi(weight,height,i)>25):
count = count+1
print("BMI = ","%.2f"%bmi(weight,height,i))
i = i+1
print("Total student BMI>25 = ",count)
def bmi(weight,height,i):
h = height[i]/100
bmi = weight[i]/(h*h)
return bmi
setup()
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
age = [25,18,52,43]
i = 0
count = 0
while(i<len(name)):
if(bmi(weight,height,i)>25):
count = count+1
print("BMI = ","%.2f"%bmi(weight,height,i))
i = i+1
print("Total student BMI>25 = ",count)
def bmi(weight,height,i):
h = height[i]/100
bmi = weight[i]/(h*h)
return bmi
setup()
Lab 6 : Find minimum weight of students
def setup():
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
age = [25,18,52,43]
i = 0
min = weight[i]
while(i<len(weight)):
if(min>weight[i]):
min = weight[i]
print(name[i],"is minimum weight of student =",min,"kg.")
i = i+1
setup()
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
age = [25,18,52,43]
i = 0
min = weight[i]
while(i<len(weight)):
if(min>weight[i]):
min = weight[i]
print(name[i],"is minimum weight of student =",min,"kg.")
i = i+1
setup()
Lab 6 : Display student records with BMI > 25
def setup():
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
i = 0
while(i<len(name)):
if(bmi(weight,height,i)>25):
print(name[i],height[i],"cm. ",weight[i],"kg. ","BMI = ","%.2f"%bmi(weight,height,i))
i = i+1
def bmi(weight,height,i):
h = height[i]/100
bmi = weight[i]/(h*h)
return bmi
setup()
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
i = 0
while(i<len(name)):
if(bmi(weight,height,i)>25):
print(name[i],height[i],"cm. ",weight[i],"kg. ","BMI = ","%.2f"%bmi(weight,height,i))
i = i+1
def bmi(weight,height,i):
h = height[i]/100
bmi = weight[i]/(h*h)
return bmi
setup()
Lab 6 : Display student records (data)
def setup():
i = 0
id = 1
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
age = [25,18,52,43]
height = [161,175,177,155]
weight = [62,54,86,71]
while(i<len(name)):
print("ID ",id,name[i],age[i],height[i],weight[i])
i = i+1
id = id+1
setup()
i = 0
id = 1
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
age = [25,18,52,43]
height = [161,175,177,155]
weight = [62,54,86,71]
while(i<len(name)):
print("ID ",id,name[i],age[i],height[i],weight[i])
i = i+1
id = id+1
setup()
Lab 6 : Find average age of students
def setup():
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
age = [25,18,52,43]
print(" Average age of student = ","%.2f"%average(age))
def average(age):
i = 0
sum = 0
while(i<len(age)):
sum = sum+age[i]
i = i+1
average = sum/len(age)
return average
setup()
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
age = [25,18,52,43]
print(" Average age of student = ","%.2f"%average(age))
def average(age):
i = 0
sum = 0
while(i<len(age)):
sum = sum+age[i]
i = i+1
average = sum/len(age)
return average
setup()
Lab 6 : Find student BMI
def setup():
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
i = 0
while(i<len(name)):
print(name[i]," BMI = ","%.2f"%bmi(weight,height,i))
i = i+1
def bmi(weight,height,i):
h = height[i]/100
bmi = weight[i]/(h*h)
return bmi
setup()
name = ["Mum" , "Teng" , "Nong" , "Tukky"]
height = [161,175,177,155]
weight = [62,54,86,71]
i = 0
while(i<len(name)):
print(name[i]," BMI = ","%.2f"%bmi(weight,height,i))
i = i+1
def bmi(weight,height,i):
h = height[i]/100
bmi = weight[i]/(h*h)
return bmi
setup()
วันอาทิตย์ที่ 4 ตุลาคม พ.ศ. 2558
Lab 5 : Find index of (the first) maximum value in array
def setup():
i = 0
index = 0
n = [5,6,23,9,20,10,23,9]
maxi = n[0]
while(i<len(n)):
if(maxi<n[i]):
maxi = n[i]
index = i
i = i+1
print("Index of maximum = ",index)
setup()
i = 0
index = 0
n = [5,6,23,9,20,10,23,9]
maxi = n[0]
while(i<len(n)):
if(maxi<n[i]):
maxi = n[i]
index = i
i = i+1
print("Index of maximum = ",index)
setup()
Lab 5 : Display elements (value) of array and its index
def setup():
i = 0
n = [5,6,7,9,5,18,4]
while(i<len(n)):
print("Index ",i," = ",n[i])
i = i+1
setup()
i = 0
n = [5,6,7,9,5,18,4]
while(i<len(n)):
print("Index ",i," = ",n[i])
i = i+1
setup()
Lab 5 : Find the maximum value in array
def setup():
i = 0
n = [5,6,7,9,5,18,4]
maxi = n[0]
while(i<len(n)):
if(maxi<n[i]):
maxi = n[i]
i = i+1
print("Maximum = ",maxi)
setup()
i = 0
n = [5,6,7,9,5,18,4]
maxi = n[0]
while(i<len(n)):
if(maxi<n[i]):
maxi = n[i]
i = i+1
print("Maximum = ",maxi)
setup()
Lab 5 : Find sum of values in array
def setup():
n = [1,2,3,4,5,6,7,8,9]
print("Sum = ",sum(n))
def sum(a):
i = 0
sum = 0
while(i<len(a)):
sum = sum+a[i]
i = i+1
return sum
setup()
n = [1,2,3,4,5,6,7,8,9]
print("Sum = ",sum(n))
def sum(a):
i = 0
sum = 0
while(i<len(a)):
sum = sum+a[i]
i = i+1
return sum
setup()
วันจันทร์ที่ 14 กันยายน พ.ศ. 2558
Lab 4x : Leap Year
def setup():
year = 2012
if(year%4==0 or year%4==0 and year%100!=0 or year%4==0 and year%100==0 and year%400==0):
print("Year's Leap Year")
if(year%4!=0 or year%4==0 and year%100==0 or year%4==0 and year%100==0 and year%400!=0):
print("Year isn't Leap Year")
setup()
year = 2012
if(year%4==0 or year%4==0 and year%100!=0 or year%4==0 and year%100==0 and year%400==0):
print("Year's Leap Year")
if(year%4!=0 or year%4==0 and year%100==0 or year%4==0 and year%100==0 and year%400!=0):
print("Year isn't Leap Year")
setup()
Lab 4x : Calculate sum of integers from 1 to N
def setup():
print("Sum = ",number(50))
def number(n):
x = 1
sum = 0
while(x <= n):
sum = sum+x
x +=1
return sum
setup()
print("Sum = ",number(50))
def number(n):
x = 1
sum = 0
while(x <= n):
sum = sum+x
x +=1
return sum
setup()
Lab 4x : Calculate sum of Prime number
def setup():
print("Sum = ",prime(10))
def prime(num):
x = 2
sum = 0
while(x<=num):
if(prime_number(x)):
sum +=x
x+=1
return sum
def prime_number(n):
x = 2
if(n==1):
return False
while(x<n):
if(n%x==0):
return False
x+=1
return True
setup()
print("Sum = ",prime(10))
def prime(num):
x = 2
sum = 0
while(x<=num):
if(prime_number(x)):
sum +=x
x+=1
return sum
def prime_number(n):
x = 2
if(n==1):
return False
while(x<n):
if(n%x==0):
return False
x+=1
return True
setup()
Lab 4x : Calculate Multiplication
def setup():
num = 2
x = 1
loop = 13
while(x<loop):
sum = num*x
print(num," * ",x," = ",sum)
x = x+1
setup()
num = 2
x = 1
loop = 13
while(x<loop):
sum = num*x
print(num," * ",x," = ",sum)
x = x+1
setup()
Lab 4x : Calculate grade from score
def setup():
score = 70
if(score>=80 and score<=100):
print("Grade A")
elif(score>=70 and score<=79):
print("Grade B")
elif(score>=60 and score<=69):
print("Grade C")
elif(score>=50 and score<=59):
print("Grade D")
elif(score>=0 and score<=49):
print("Grade F")
else:
print("Error")
setup()
score = 70
if(score>=80 and score<=100):
print("Grade A")
elif(score>=70 and score<=79):
print("Grade B")
elif(score>=60 and score<=69):
print("Grade C")
elif(score>=50 and score<=59):
print("Grade D")
elif(score>=0 and score<=49):
print("Grade F")
else:
print("Error")
setup()
Lab 4x : Calculate of BMI
def setup():
w = 40
h = 160
print("Weight = ",w)
print("Hight = ",h)
print("Value of a BMI = ",bmi(w,h),"kg/cm*cm")
def bmi(w,h):
divisor = h/100
bmi = w/(divisor*divisor)
return bmi
setup()
w = 40
h = 160
print("Weight = ",w)
print("Hight = ",h)
print("Value of a BMI = ",bmi(w,h),"kg/cm*cm")
def bmi(w,h):
divisor = h/100
bmi = w/(divisor*divisor)
return bmi
setup()
Lab 4x : Calculate circum and area of circle
def setup():
r = 10
print("Radian = ",r)
print("Value of Area = ",area(r))
print("Value of Circumference = ",circum(r))
def area(r):
area = (22/7)*r*r
return area
def circum(r):
circum = 2*(22/7)*r
return circum
setup()
r = 10
print("Radian = ",r)
print("Value of Area = ",area(r))
print("Value of Circumference = ",circum(r))
def area(r):
area = (22/7)*r*r
return area
def circum(r):
circum = 2*(22/7)*r
return circum
setup()
Lab 4x : Calculate circum and area of rectangle
def setup():
w = 3
h = 7
print("Height = ",h)
print("Weight = ",w)
print("Value of Area = ",area(w,h))
print("Value of Circumference = ",circum(w,h))
def area(w, h):
area = w*h
return area
def circum(w,h):
circum = (2*w)+(2*h)
return circum
setup()
w = 3
h = 7
print("Height = ",h)
print("Weight = ",w)
print("Value of Area = ",area(w,h))
print("Value of Circumference = ",circum(w,h))
def area(w, h):
area = w*h
return area
def circum(w,h):
circum = (2*w)+(2*h)
return circum
setup()
วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558
Lab 4 : Balloons (while loop)
void setup(){
size(500,500);
}
void draw(){
background(255);
if(mouseY<150){
fill(#9B00FC);
}else if(mouseY>300){
fill(#00FCB3);
}else{
fill(#FC004C);
}
draw_balloon(mouseX,mouseY,100,100,1);
}
void draw_balloon(int x,int y,int w,int h,int n){
int space=0;
while(n<=4){
///////////////////draw balloon////////////////////
strokeWeight(5);
ellipse(x+space,y+space,w,h);
line(x+space,(y+space)+(h/2),x+space,(y+space)+(h+50));
n++;
space = space+w;
}
}
size(500,500);
}
void draw(){
background(255);
if(mouseY<150){
fill(#9B00FC);
}else if(mouseY>300){
fill(#00FCB3);
}else{
fill(#FC004C);
}
draw_balloon(mouseX,mouseY,100,100,1);
}
void draw_balloon(int x,int y,int w,int h,int n){
int space=0;
while(n<=4){
///////////////////draw balloon////////////////////
strokeWeight(5);
ellipse(x+space,y+space,w,h);
line(x+space,(y+space)+(h/2),x+space,(y+space)+(h+50));
n++;
space = space+w;
}
}
Lab 4 : Flock birds
int w=150;
int c;
void setup(){
size(700,700);
}
void draw(){
background(#69C2F7);
w=mouseY;
if(frameCount%40>20){
w+=40;
}else{
w-=50;
}
if(mouseY<200){
c=#FF0000;
}else if(mouseY<350){
c=255;
}else{
c=#10BF08;
}
draw_bird(mouseX,mouseY);
}
void draw_bird(int x,int y){
int n=0;
int sx=0; //space
int sy=0;
while(n<5){
//////////////draw bird//////////////
strokeWeight(5);
fill(c);
ellipse(x+sx,y+sy,150,150); //head
fill(255);
ellipse((x-25)+sx,(y-10)+sy,30,30); //eye l
ellipse((x+25)+sx,(y-10)+sy,30,30); //eye r
fill(#FAC208);
triangle((x-20)+sx,(y+30)+sy,x+sx,(y+15)+sy,(x+20)+sx,(y+30)+sy); //mouse on
triangle((x-15)+sx,(y+30)+sy,x+sx,(y+40)+sy,(x+15)+sx,(y+30)+sy); //mouse under
fill(0);
ellipse((x-25)+sx,(y-10)+sy,10,10); //in eye l
ellipse((x+25)+sx,(y-10)+sy,10,10); //in eye r
rect((x-45)+sx,(y-30)+sy,40,10); //eyebrow l
rect((x+5)+sx,(y-30)+sy,40,10); //eyebrow r
line((x-75)+sx,y+sy,(x-150)+sx,w+sy); //wing l
line((x+75)+sx,y+sy,(x+150)+sx,w+sy); //wing r
n++;
sx = sx-50;
sy = sy+170;
}
}
int c;
void setup(){
size(700,700);
}
void draw(){
background(#69C2F7);
w=mouseY;
if(frameCount%40>20){
w+=40;
}else{
w-=50;
}
if(mouseY<200){
c=#FF0000;
}else if(mouseY<350){
c=255;
}else{
c=#10BF08;
}
draw_bird(mouseX,mouseY);
}
void draw_bird(int x,int y){
int n=0;
int sx=0; //space
int sy=0;
while(n<5){
//////////////draw bird//////////////
strokeWeight(5);
fill(c);
ellipse(x+sx,y+sy,150,150); //head
fill(255);
ellipse((x-25)+sx,(y-10)+sy,30,30); //eye l
ellipse((x+25)+sx,(y-10)+sy,30,30); //eye r
fill(#FAC208);
triangle((x-20)+sx,(y+30)+sy,x+sx,(y+15)+sy,(x+20)+sx,(y+30)+sy); //mouse on
triangle((x-15)+sx,(y+30)+sy,x+sx,(y+40)+sy,(x+15)+sx,(y+30)+sy); //mouse under
fill(0);
ellipse((x-25)+sx,(y-10)+sy,10,10); //in eye l
ellipse((x+25)+sx,(y-10)+sy,10,10); //in eye r
rect((x-45)+sx,(y-30)+sy,40,10); //eyebrow l
rect((x+5)+sx,(y-30)+sy,40,10); //eyebrow r
line((x-75)+sx,y+sy,(x-150)+sx,w+sy); //wing l
line((x+75)+sx,y+sy,(x+150)+sx,w+sy); //wing r
n++;
sx = sx-50;
sy = sy+170;
}
}
Lab 4 : Calculate Multiplication
void setup(){
int num=2; //multiplicad
int x=1; //multiplier
int loop=13;
int sum;
while(x<loop){
sum = num*x;
println(num+" * "+x+" = "+sum);
x++;
}
}
int num=2; //multiplicad
int x=1; //multiplier
int loop=13;
int sum;
while(x<loop){
sum = num*x;
println(num+" * "+x+" = "+sum);
x++;
}
}
Lab 4 : Calculate sum of integers from 1 to N
void setup() {
int n=50;
println("Sum = "+number(n));
}
int number(int n) {
int x = 1;
int sum = 0;
while (x <= n) {
sum = sum+x;
x++;
}
return sum;
}
int n=50;
println("Sum = "+number(n));
}
int number(int n) {
int x = 1;
int sum = 0;
while (x <= n) {
sum = sum+x;
x++;
}
return sum;
}
Lab 4 : Calculate sum of Prime number
void setup(){
int n=10;
println("Sum = "+prime(n));
}
int prime(int n){
int x=1;
int sum=0;
while(x<=n){
if(prime_number(x)){
sum = sum+x;
}
x++;
}
return sum;
}
boolean prime_number(int n){
boolean prime=true;
int x=2;
while(x<n){
if(n%x==0){
prime=false;
}
x++;
}
if(n==1){
prime=false;
}
return prime;
}
int n=10;
println("Sum = "+prime(n));
}
int prime(int n){
int x=1;
int sum=0;
while(x<=n){
if(prime_number(x)){
sum = sum+x;
}
x++;
}
return sum;
}
boolean prime_number(int n){
boolean prime=true;
int x=2;
while(x<n){
if(n%x==0){
prime=false;
}
x++;
}
if(n==1){
prime=false;
}
return prime;
}
Lab 4 : Loan payment
void setup(){
loan_payment(5000,1,12);
}
void loan_payment(float amount,float year,float rate){
int no = 1;
float ratee = rate/100;
float month = year*12;
float ratepermonth = ratee/month;
float prinper = amount*(ratepermonth/(1-pow(1+ratepermonth,-month)));
float principal = prinper;
float total = 0;
println("NO. Beginning balance Interest Total interest to date Principal Unpaid balance");
while(no<=month){
print(nf(no,2)); //NO.
print(" "+nf(amount,4,2)); //Beginning balance
print(" "+nf(ratepermonth*amount,2,2)); //Ineterest
total = total+(ratepermonth*amount);
principal = prinper-(ratepermonth*amount);
amount = amount-principal;
if(amount<0){
amount = 0;
}
print(" "+nf(total,3,2)); //Total interest
print(" "+nf(principal,3,2)); //Principal
print(" "+nf(amount,4,2));
println();
no++;
}
}
loan_payment(5000,1,12);
}
void loan_payment(float amount,float year,float rate){
int no = 1;
float ratee = rate/100;
float month = year*12;
float ratepermonth = ratee/month;
float prinper = amount*(ratepermonth/(1-pow(1+ratepermonth,-month)));
float principal = prinper;
float total = 0;
println("NO. Beginning balance Interest Total interest to date Principal Unpaid balance");
while(no<=month){
print(nf(no,2)); //NO.
print(" "+nf(amount,4,2)); //Beginning balance
print(" "+nf(ratepermonth*amount,2,2)); //Ineterest
total = total+(ratepermonth*amount);
principal = prinper-(ratepermonth*amount);
amount = amount-principal;
if(amount<0){
amount = 0;
}
print(" "+nf(total,3,2)); //Total interest
print(" "+nf(principal,3,2)); //Principal
print(" "+nf(amount,4,2));
println();
no++;
}
}
Lab 4 : Game
int c=#6A3205;
void setup(){
size(500,500);
}
void draw(){
draw_brown(mouseX,mouseY);
}
void draw_brown(int x,int y){
int n=1;
int sx=0; //space
int sy=0;
background(#58D1F4);
while(n<5){
fill(c); //ear l
stroke(#4C2404);
ellipse((x-50)+sx,(y+30)+sy,120,120);
fill(c); //ear r
stroke(#4C2404);
ellipse((x+150)+sx,(y+30)+sy,120,120);
fill(#4C2404); //in ear l
stroke(#4C2404);
ellipse((x-50)+sx,(y+30)+sy,75,75);
fill(#4C2404); //in ear r
stroke(#4C2404);
ellipse((x+150)+sx,(y+30)+sy,75,75);
fill(c); //head
stroke(#4C2404);
ellipse((x+50)+sx,(y+170)+sy,340,320);
fill(#EFF804); //petal1
stroke(#EFF804);
ellipse((x-25)+sx,(y+35)+sy,50,50);
fill(#EFF804); //petal2
stroke(#EFF804);
ellipse((x-55)+sx,(y+60)+sy,50,50);
fill(#EFF804); //petal3
stroke(#EFF804);
ellipse((x+5)+sx,(y+60)+sy,50,50);
fill(#EFF804); //petal4
stroke(#EFF804);
ellipse((x-5)+sx,(y+95)+sy,50,50);
fill(#EFF804); //petal5
stroke(#EFF804);
ellipse((x-45)+sx,(y+95)+sy,50,50);
fill(#522F03); //pollen
stroke(#522F03);
ellipse((x-25)+sx,(y+70)+sy,30,30);
fill(0); //eye l
stroke(0);
ellipse((x+30)+sx,(y+140)+sy,25,25);
fill(0); //eye r
stroke(0);
ellipse((x+80)+sx,(y+140)+sy,25,25);
fill(#FDCF86); //mouth
stroke(#FDCF86);
ellipse((x+55)+sx,(y+200)+sy,80,95);
fill(0); //nose
stroke(0);
ellipse((x+55)+sx,(y+185)+sy,15,15);
noFill(); //continue nose
stroke(0);
strokeWeight(2);
line((x+55)+sx,(y+185)+sy,(x+55)+sx,(y+220)+sy);
curve((x+130)+sx,(y+110)+sy,(x+30)+sx,(y+210)+sy,(x+80)+sx,(y+210)+sy,(x-20)+sx,(y+110)+sy);
fill(#FEAF04); //sun
stroke(#FEAF04);
ellipse((x+260)+sx,(y-270)+sy,250,250);
n++;
sx = sx+200;
sy = sy+100;
}
}
void keyPressed(){
c=#7808BF;
}
Lab 4 : Book
int c;
void setup() {
size(500, 500);
}
void draw(){
background(255);
draw_book(mouseX,mouseY);
}
void draw_book(int posX,int posY){
int n=1;
int sx=0;
int sy=0;
while(n<4){
fill(0); //hair
quad((posX+30)+sx,(posY-180)+sy,(posX+50)+sx,(posY-170)+sy,(posX+30)+sx,(posY-150)+sy,(posX+30)+sx,(posY-160)+sy);
fill(0);
ellipse((posX+30)+sx,(posY-150)+sy,25,25);
fill(0);
ellipse((posX+20)+sx,(posY-125)+sy,35,35);
fill(0);
ellipse((posX+10)+sx,(posY-100)+sy,40,40);
fill(0);
ellipse(posX+sx,(posY-70)+sy,50,50);
stroke(0); //face
fill(#FFEDB9);
ellipse(posX+sx,(posY+50)+sy,200,250);
noFill(); //mouth
stroke(0);
curve((posX+70)+sx,posY+sy,(posX-30)+sx,(posY+100)+sy,(posX+30)+sx,(posY+100)+sy,(posX-70)+sx,posY+sy);
noFill(); //eye l
stroke(0);
curve((posX-150)+sx,(posY+20)+sy,(posX-60)+sx,(posY+25)+sy,(posX-20)+sx,(posY+40)+sy,(posX-50)+sx,(posY+70)+sy);
noFill(); //eye r
stroke(0);
curve((posX+50)+sx,(posY+70)+sy,(posX+20)+sx,(posY+40)+sy,(posX+60)+sx,(posY+25)+sy,(posX+150)+sx,(posY+20)+sy);
stroke(0); //nose
fill(0);
ellipse(posX+sx,(posY+70)+sy,3,3);
stroke(#FCA88A); //cheek l
fill(#FCA88A);
ellipse((posX-65)+sx,(posY+85)+sy,30,30);
stroke(#FCA88A); //cheek r
fill(#FCA88A);
ellipse((posX+65)+sx,(posY+85)+sy,30,30);
stroke(0); //hand l
fill(#FFEDB9);
ellipse((posX-70)+sx,(posY+160)+sy,60,60);
stroke(0); //hand r
fill(#FFEDB9);
ellipse((posX+70)+sx,(posY+160)+sy,60,60);
textSize(60); //name book
fill(c);
text("REBORN!",(posX-120)+sx,(posY-190)+sy);
n++;
sx = sx+250;
sy = sy+20;
}
}
void mousePressed(){
c=#FF0004;
}
void setup() {
size(500, 500);
}
void draw(){
background(255);
draw_book(mouseX,mouseY);
}
void draw_book(int posX,int posY){
int n=1;
int sx=0;
int sy=0;
while(n<4){
fill(0); //hair
quad((posX+30)+sx,(posY-180)+sy,(posX+50)+sx,(posY-170)+sy,(posX+30)+sx,(posY-150)+sy,(posX+30)+sx,(posY-160)+sy);
fill(0);
ellipse((posX+30)+sx,(posY-150)+sy,25,25);
fill(0);
ellipse((posX+20)+sx,(posY-125)+sy,35,35);
fill(0);
ellipse((posX+10)+sx,(posY-100)+sy,40,40);
fill(0);
ellipse(posX+sx,(posY-70)+sy,50,50);
stroke(0); //face
fill(#FFEDB9);
ellipse(posX+sx,(posY+50)+sy,200,250);
noFill(); //mouth
stroke(0);
curve((posX+70)+sx,posY+sy,(posX-30)+sx,(posY+100)+sy,(posX+30)+sx,(posY+100)+sy,(posX-70)+sx,posY+sy);
noFill(); //eye l
stroke(0);
curve((posX-150)+sx,(posY+20)+sy,(posX-60)+sx,(posY+25)+sy,(posX-20)+sx,(posY+40)+sy,(posX-50)+sx,(posY+70)+sy);
noFill(); //eye r
stroke(0);
curve((posX+50)+sx,(posY+70)+sy,(posX+20)+sx,(posY+40)+sy,(posX+60)+sx,(posY+25)+sy,(posX+150)+sx,(posY+20)+sy);
stroke(0); //nose
fill(0);
ellipse(posX+sx,(posY+70)+sy,3,3);
stroke(#FCA88A); //cheek l
fill(#FCA88A);
ellipse((posX-65)+sx,(posY+85)+sy,30,30);
stroke(#FCA88A); //cheek r
fill(#FCA88A);
ellipse((posX+65)+sx,(posY+85)+sy,30,30);
stroke(0); //hand l
fill(#FFEDB9);
ellipse((posX-70)+sx,(posY+160)+sy,60,60);
stroke(0); //hand r
fill(#FFEDB9);
ellipse((posX+70)+sx,(posY+160)+sy,60,60);
textSize(60); //name book
fill(c);
text("REBORN!",(posX-120)+sx,(posY-190)+sy);
n++;
sx = sx+250;
sy = sy+20;
}
}
void mousePressed(){
c=#FF0004;
}
Lab 4 : Song
int x=50;
void setup(){
size(500,500);
}
void draw(){
background(#FCECB5);
draw_song(x,10);
}
void draw_song(int x,int y){
int n=1;
int sx=0;
while(n<=3){
fill(0); //in door
stroke(0);
rect((150+x)+sx,300+y,200,250);
fill(#D36A06); //l door
stroke(#D36A06);
rect((135+x)+sx,300+y,15,250);
fill(#D36A06); //r door
stroke(#D36A06);
rect((350+x)+sx,300+y,15,250);
fill(#D36A06); //on door
stroke(#D36A06);
rect((135+x)+sx,285+y,230,15);
fill(#FF0B03); //open
stroke(#FF0B03);
ellipse((180+x)+sx,450+y,20,20);
/////word on door WELCOME////
fill(#E9FF03);
textSize(20);
text("W",(180+x)+sx,360+y);
fill(#03F9FF);
textSize(20);
text("E",(200+x)+sx,360+y);
fill(#05FF03);
textSize(20);
text("L",(220+x)+sx,360+y);
fill(#FF9F03);
textSize(20);
text("C",(240+x)+sx,360+y);
fill(#AC6BF7);
textSize(20);
text("O",(260+x)+sx,360+y);
fill(#6BF7CA);
textSize(20);
text("M",(280+x)+sx,360+y);
fill(#FF0000);
textSize(20);
text("E",(300+x)+sx,360+y);
/////name of song/////
fill(#0D08A5);
textSize(80);
text("Pra",x+sx,140+y);
fill(#08A50E);
textSize(80);
text("Tu",(150+x)+sx,140+y);
fill(#BC0606);
textSize(80);
text("Jai",(300+x)+sx,140+y);
/////name of singer/////
fill(#AC39F5);
textSize(40);
text("Sao Sao Sao",(x+100)+sx,210+y);
n++;
sx = sx+400;
}
}
void keyPressed(){
x=x+100;
}
void mousePressed(){
x=x-100;
}
void setup(){
size(500,500);
}
void draw(){
background(#FCECB5);
draw_song(x,10);
}
void draw_song(int x,int y){
int n=1;
int sx=0;
while(n<=3){
fill(0); //in door
stroke(0);
rect((150+x)+sx,300+y,200,250);
fill(#D36A06); //l door
stroke(#D36A06);
rect((135+x)+sx,300+y,15,250);
fill(#D36A06); //r door
stroke(#D36A06);
rect((350+x)+sx,300+y,15,250);
fill(#D36A06); //on door
stroke(#D36A06);
rect((135+x)+sx,285+y,230,15);
fill(#FF0B03); //open
stroke(#FF0B03);
ellipse((180+x)+sx,450+y,20,20);
/////word on door WELCOME////
fill(#E9FF03);
textSize(20);
text("W",(180+x)+sx,360+y);
fill(#03F9FF);
textSize(20);
text("E",(200+x)+sx,360+y);
fill(#05FF03);
textSize(20);
text("L",(220+x)+sx,360+y);
fill(#FF9F03);
textSize(20);
text("C",(240+x)+sx,360+y);
fill(#AC6BF7);
textSize(20);
text("O",(260+x)+sx,360+y);
fill(#6BF7CA);
textSize(20);
text("M",(280+x)+sx,360+y);
fill(#FF0000);
textSize(20);
text("E",(300+x)+sx,360+y);
/////name of song/////
fill(#0D08A5);
textSize(80);
text("Pra",x+sx,140+y);
fill(#08A50E);
textSize(80);
text("Tu",(150+x)+sx,140+y);
fill(#BC0606);
textSize(80);
text("Jai",(300+x)+sx,140+y);
/////name of singer/////
fill(#AC39F5);
textSize(40);
text("Sao Sao Sao",(x+100)+sx,210+y);
n++;
sx = sx+400;
}
}
void keyPressed(){
x=x+100;
}
void mousePressed(){
x=x-100;
}
วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558
Lab 3 : Delivery Charge
void setup() {
size(700, 700);
background(0);
cal_charge(2,2,4,22);
fill(#DE1FFC);
textSize(80);
text("Delivery Charge", 40, 200);
}
/////pack1=letter , pack2=box , service1=next day priority , service2=next day standard
/////service3=2-day price=num of packservice
void cal_charge(int pack,int service,int weight,int price) {
int x=100;
int y=300;
float boxprio=15.75+((weight-1)*1.25);
float boxstard=13.75+((weight-1)*1.00);
float boxday=7.00+((weight-1)*0.50);
textSize(35);
fill(#5A94F0);
if (pack==1 && service==1 && weight<=8 && price==11){
text("Package Type : Letter", x, y);
text("Service type : Next Day Priority", x, y+80);
text("Weight : "+weight+" oz",x,y+160);
text("Price : $12.00",x,y+240);
}
if (pack==1 && service==2 && weight<=8 && price==12){
text("Package Type : Letter", x, y);
text("Service type : Next Day Standard", x, y+80);
text("Weight : "+weight+" oz",x,y+160);
text("Price : $10.50",x,y+240);
}
if (pack==1 && service==3 && price==13){
text("Package Type : Letter", x, y);
text("Service type : 2-Day", x, y+80);
text("Weight : "+weight+" oz",x,y+160);
text("Price : Not available",x,y+240);
}
if (pack==2 && service==1 && price==21){
text("Package Type : Box", x, y);
text("Service type : Next Day Priority", x, y+80);
text("Weight : "+weight+" pound",x,y+160);
text("Price : $"+boxprio,x,y+240);
}
if (pack==2 && service==2 && price==22){
text("Package Type : Box", x, y);
text("Service type : Next Day Standard", x, y+80);
text("Weight : "+weight+" pound",x,y+160);
text("Price : $"+boxstard,x,y+240);
}
if (pack==2 && service==3 && price==23){
text("Package Type : Box", x, y);
text("Service type : 2-Day", x, y+80);
text("Weight : "+weight+" pound",x,y+160);
text("Price : $"+boxday,x,y+240);
}
if(pack!=1 && pack!=2 || service!=1 && service!=2 && service!=3 || price!=11 && price!=12 && price!=13 && price!=21 && price!=22 && price!=23){
text("Package Type : Not available", x, y);
text("Service type : Not available", x, y+80);
text("Weight : Not available",x,y+160);
text("Price : Not available",x,y+240);
}
}
size(700, 700);
background(0);
cal_charge(2,2,4,22);
fill(#DE1FFC);
textSize(80);
text("Delivery Charge", 40, 200);
}
/////pack1=letter , pack2=box , service1=next day priority , service2=next day standard
/////service3=2-day price=num of packservice
void cal_charge(int pack,int service,int weight,int price) {
int x=100;
int y=300;
float boxprio=15.75+((weight-1)*1.25);
float boxstard=13.75+((weight-1)*1.00);
float boxday=7.00+((weight-1)*0.50);
textSize(35);
fill(#5A94F0);
if (pack==1 && service==1 && weight<=8 && price==11){
text("Package Type : Letter", x, y);
text("Service type : Next Day Priority", x, y+80);
text("Weight : "+weight+" oz",x,y+160);
text("Price : $12.00",x,y+240);
}
if (pack==1 && service==2 && weight<=8 && price==12){
text("Package Type : Letter", x, y);
text("Service type : Next Day Standard", x, y+80);
text("Weight : "+weight+" oz",x,y+160);
text("Price : $10.50",x,y+240);
}
if (pack==1 && service==3 && price==13){
text("Package Type : Letter", x, y);
text("Service type : 2-Day", x, y+80);
text("Weight : "+weight+" oz",x,y+160);
text("Price : Not available",x,y+240);
}
if (pack==2 && service==1 && price==21){
text("Package Type : Box", x, y);
text("Service type : Next Day Priority", x, y+80);
text("Weight : "+weight+" pound",x,y+160);
text("Price : $"+boxprio,x,y+240);
}
if (pack==2 && service==2 && price==22){
text("Package Type : Box", x, y);
text("Service type : Next Day Standard", x, y+80);
text("Weight : "+weight+" pound",x,y+160);
text("Price : $"+boxstard,x,y+240);
}
if (pack==2 && service==3 && price==23){
text("Package Type : Box", x, y);
text("Service type : 2-Day", x, y+80);
text("Weight : "+weight+" pound",x,y+160);
text("Price : $"+boxday,x,y+240);
}
if(pack!=1 && pack!=2 || service!=1 && service!=2 && service!=3 || price!=11 && price!=12 && price!=13 && price!=21 && price!=22 && price!=23){
text("Package Type : Not available", x, y);
text("Service type : Not available", x, y+80);
text("Weight : Not available",x,y+160);
text("Price : Not available",x,y+240);
}
}
Lab 3 : Leap Year
void setup() {
size(500, 500);
background(0);
int year=2013;
cal_year(year);
fill(#1FFC6A);
textSize(80);
text("Leap Year", 60, 150);
textSize(50);
text("Year : "+year, 110, 250);
}
void cal_year(int year) {
int x=100;
int y=350;
textSize(40);
fill(#FF0000);
if (year%4==0 || year%4==0 && year%100!=0 || year%4==0 && year%100==0 && year%400==0){
text("Year's Leap Year", x-10, y);
}
if(year%4!=0 || year%4==0 && year%100==0 || year%4==0 && year%100==0 && year%400!=0){
text("Year isn't Leap Year",x-30,y);
}
}
size(500, 500);
background(0);
int year=2013;
cal_year(year);
fill(#1FFC6A);
textSize(80);
text("Leap Year", 60, 150);
textSize(50);
text("Year : "+year, 110, 250);
}
void cal_year(int year) {
int x=100;
int y=350;
textSize(40);
fill(#FF0000);
if (year%4==0 || year%4==0 && year%100!=0 || year%4==0 && year%100==0 && year%400==0){
text("Year's Leap Year", x-10, y);
}
if(year%4!=0 || year%4==0 && year%100==0 || year%4==0 && year%100==0 && year%400!=0){
text("Year isn't Leap Year",x-30,y);
}
}
Lab 3 : Power of 10
void setup() {
size(500, 500);
background(0);
int power=21;
cal_power(power);
textSize(70);
text("Power Of 10", 50, 150);
textSize(50);
text("Power = "+power, 120, 250);
}
void cal_power(int power) {
int x=180;
int y=350;
textSize(40);
fill(#FF0000);
if (power==6){
text("Million", x, y);
}else if(power==9){
text("Billion", x, y);
}else if(power==12){
text("Trillion", x, y);
}else if(power==15){
text("Quadrillion", x-30, y);
}else if(power==18){
text("Quintillion", x-20, y);
}else if(power==21){
text("Sextillion", x-10, y);
}else if(power==30){
text("Nonillion", x-10, y);
}else if(power==100){
text("Googol", x+20, y);
}else{
text("No number",x-20,y);
}
}
size(500, 500);
background(0);
int power=21;
cal_power(power);
textSize(70);
text("Power Of 10", 50, 150);
textSize(50);
text("Power = "+power, 120, 250);
}
void cal_power(int power) {
int x=180;
int y=350;
textSize(40);
fill(#FF0000);
if (power==6){
text("Million", x, y);
}else if(power==9){
text("Billion", x, y);
}else if(power==12){
text("Trillion", x, y);
}else if(power==15){
text("Quadrillion", x-30, y);
}else if(power==18){
text("Quintillion", x-20, y);
}else if(power==21){
text("Sextillion", x-10, y);
}else if(power==30){
text("Nonillion", x-10, y);
}else if(power==100){
text("Googol", x+20, y);
}else{
text("No number",x-20,y);
}
}
Lab 3 : Battery
int posX=100;
int posY=100;
int y=25;
int h=100;
int paint;
int mouse;
int per=100;
void setup(){
size(300,300);
frameRate(10);
}
void draw(){
background(#9B8B8B);
draw_battery(posX,posY,60,h);
if(h>0){
h=h-1;
paint=#FF0000;
per=per-1;
}
if(h>40){
paint=#FFF812;
}
if(h>80){
paint=#24BF02;
}
if(h<10){
draw_charge(190,150);
}
if(h==0){
h=100;
h=h+1;
per=101;
per=per-1;
}
}
void draw_battery(int posX,int posY,int w,int h){
//strokeWeight();
fill(255);
rect(posX+10,posY+125,40,20); //head battery
rect(posX-5,posY-5,70,130); //battery
rect(posX-20,posY+150,20,5); //positive and negative
rect(posX+60,posY+150,20,5);
rect(posX+68,posY+143,5,20);
textSize(20);
text(per+" %",posX,posY-25);
fill(paint);
rect(posX,posY,60,h);
}
void draw_charge(int x,int y){
textSize(25);
fill(#FF0000);
text("Charge!",x,y);
}
int posY=100;
int y=25;
int h=100;
int paint;
int mouse;
int per=100;
void setup(){
size(300,300);
frameRate(10);
}
void draw(){
background(#9B8B8B);
draw_battery(posX,posY,60,h);
if(h>0){
h=h-1;
paint=#FF0000;
per=per-1;
}
if(h>40){
paint=#FFF812;
}
if(h>80){
paint=#24BF02;
}
if(h<10){
draw_charge(190,150);
}
if(h==0){
h=100;
h=h+1;
per=101;
per=per-1;
}
}
void draw_battery(int posX,int posY,int w,int h){
//strokeWeight();
fill(255);
rect(posX+10,posY+125,40,20); //head battery
rect(posX-5,posY-5,70,130); //battery
rect(posX-20,posY+150,20,5); //positive and negative
rect(posX+60,posY+150,20,5);
rect(posX+68,posY+143,5,20);
textSize(20);
text(per+" %",posX,posY-25);
fill(paint);
rect(posX,posY,60,h);
}
void draw_charge(int x,int y){
textSize(25);
fill(#FF0000);
text("Charge!",x,y);
}
Lab 3 : Game (follow mouse and keyPressed)
int c=#6A3205;
void setup(){
size(500,500);
}
void draw(){
draw_brown(mouseX,mouseY);
}
void draw_brown(int x,int y){
background(#58D1F4);
fill(c); //ear l
stroke(c);
ellipse(x-50,y+30,120,120);
fill(c); //ear r
stroke(c);
ellipse(x+150,y+30,120,120);
fill(#4C2404); //in ear l
stroke(#4C2404);
ellipse(x-50,y+30,75,75);
fill(#4C2404); //in ear r
stroke(#4C2404);
ellipse(x+150,y+30,75,75);
fill(c); //head
stroke(c);
ellipse(x+50,y+170,340,320);
fill(#EFF804); //petal1
stroke(#EFF804);
ellipse(x-25,y+35,50,50);
fill(#EFF804); //petal2
stroke(#EFF804);
ellipse(x-55,y+60,50,50);
fill(#EFF804); //petal3
stroke(#EFF804);
ellipse(x+5,y+60,50,50);
fill(#EFF804); //petal4
stroke(#EFF804);
ellipse(x-5,y+95,50,50);
fill(#EFF804); //petal5
stroke(#EFF804);
ellipse(x-45,y+95,50,50);
fill(#522F03); //pollen
stroke(#522F03);
ellipse(x-25,y+70,30,30);
fill(0); //eye l
stroke(0);
ellipse(x+30,y+140,25,25);
fill(0); //eye r
stroke(0);
ellipse(x+80,y+140,25,25);
fill(#FDCF86); //mouth
stroke(#FDCF86);
ellipse(x+55,y+200,80,95);
fill(0); //nose
stroke(0);
ellipse(x+55,y+185,15,15);
noFill(); //continue nose
stroke(0);
strokeWeight(2);
line(x+55,y+185,x+55,y+220);
curve(x+130,y+110,x+30,y+210,x+80,y+210,x-20,y+110);
fill(#FEAF04); //sun
stroke(#FEAF04);
ellipse(x+260,y-270,250,250);
}
void keyPressed(){
c=#7808BF;
}
Lab 3 : Song (mousePressed and keyPressed)
int x=50;
void setup(){
size(500,500);
}
void draw(){
draw_song(x,10);
}
void draw_song(int x,int y){
background(#FCECB5);
fill(0); //in door
stroke(0);
rect(150+x,300+y,200,250);
fill(#D36A06); //l door
stroke(#D36A06);
rect(135+x,300+y,15,250);
fill(#D36A06); //r door
stroke(#D36A06);
rect(350+x,300+y,15,250);
fill(#D36A06); //on door
stroke(#D36A06);
rect(135+x,285+y,230,15);
fill(#FF0B03); //open
stroke(#FF0B03);
ellipse(180+x,450+y,20,20);
/////word on door WELCOME////
fill(#E9FF03);
textSize(20);
text("W",180+x,360+y);
fill(#03F9FF);
textSize(20);
text("E",200+x,360+y);
fill(#05FF03);
textSize(20);
text("L",220+x,360+y);
fill(#FF9F03);
textSize(20);
text("C",240+x,360+y);
fill(#AC6BF7);
textSize(20);
text("O",260+x,360+y);
fill(#6BF7CA);
textSize(20);
text("M",280+x,360+y);
fill(#FF0000);
textSize(20);
text("E",300+x,360+y);
/////name of song/////
fill(#0D08A5);
textSize(80);
text("Pra",x,140+y);
fill(#08A50E);
textSize(80);
text("Tu",150+x,140+y);
fill(#BC0606);
textSize(80);
text("Jai",300+x,140+y);
/////name of singer/////
fill(#AC39F5);
textSize(40);
text("Sao Sao Sao",x+100,210+y);
}
void keyPressed(){
x=x+100;
}
void mousePressed(){
x=x-100;
}
Lab 3 : Book (follow mouse and mousePressed)
int c;
void setup() {
size(500, 500);
}
void draw(){
background(255);
draw_book(mouseX,mouseY);
}
void draw_book(int posX,int posY){
fill(0); //hair
quad(posX+30, posY-180, posX+50, posY-170,posX+30, posY-150, posX+30, posY-160);
fill(0);
ellipse(posX+30, posY-150, 25, 25);
fill(0);
ellipse(posX+20, posY-125, 35, 35);
fill(0);
ellipse(posX+10, posY-100, 40, 40);
fill(0);
ellipse(posX, posY-70, 50, 50);
stroke(0); //face
fill(#FFEDB9);
ellipse(posX, posY+50, 200, 250);
noFill(); //mouth
stroke(0);
curve(posX+70,posY,posX-30,posY+100,posX+30,posY+100,posX-70,posY);
noFill(); //eye l
stroke(0);
curve(posX-150,posY+20,posX-60,posY+25,posX-20,posY+40,posX-50,posY+70);
noFill(); //eye r
stroke(0);
curve(posX+50,posY+70,posX+20,posY+40,posX+60,posY+25,posX+150,posY+20);
stroke(0); //nose
fill(0);
ellipse(posX,posY+70,3,3);
stroke(#FCA88A); //cheek l
fill(#FCA88A);
ellipse(posX-65, posY+85, 30, 30);
stroke(#FCA88A); //cheek r
fill(#FCA88A);
ellipse(posX+65, posY+85, 30, 30);
stroke(0); //hand l
fill(#FFEDB9);
ellipse(posX-70, posY+160, 60, 60);
stroke(0); //hand r
fill(#FFEDB9);
ellipse(posX+70, posY+160, 60, 60);
textSize(60); //name book
fill(c);
text("REBORN!",posX-120,posY-190);
}
void mousePressed(){
c=#FF0004;
}
void setup() {
size(500, 500);
}
void draw(){
background(255);
draw_book(mouseX,mouseY);
}
void draw_book(int posX,int posY){
fill(0); //hair
quad(posX+30, posY-180, posX+50, posY-170,posX+30, posY-150, posX+30, posY-160);
fill(0);
ellipse(posX+30, posY-150, 25, 25);
fill(0);
ellipse(posX+20, posY-125, 35, 35);
fill(0);
ellipse(posX+10, posY-100, 40, 40);
fill(0);
ellipse(posX, posY-70, 50, 50);
stroke(0); //face
fill(#FFEDB9);
ellipse(posX, posY+50, 200, 250);
noFill(); //mouth
stroke(0);
curve(posX+70,posY,posX-30,posY+100,posX+30,posY+100,posX-70,posY);
noFill(); //eye l
stroke(0);
curve(posX-150,posY+20,posX-60,posY+25,posX-20,posY+40,posX-50,posY+70);
noFill(); //eye r
stroke(0);
curve(posX+50,posY+70,posX+20,posY+40,posX+60,posY+25,posX+150,posY+20);
stroke(0); //nose
fill(0);
ellipse(posX,posY+70,3,3);
stroke(#FCA88A); //cheek l
fill(#FCA88A);
ellipse(posX-65, posY+85, 30, 30);
stroke(#FCA88A); //cheek r
fill(#FCA88A);
ellipse(posX+65, posY+85, 30, 30);
stroke(0); //hand l
fill(#FFEDB9);
ellipse(posX-70, posY+160, 60, 60);
stroke(0); //hand r
fill(#FFEDB9);
ellipse(posX+70, posY+160, 60, 60);
textSize(60); //name book
fill(c);
text("REBORN!",posX-120,posY-190);
}
void mousePressed(){
c=#FF0004;
}
วันเสาร์ที่ 5 กันยายน พ.ศ. 2558
Lab 3 : Flying Bird
int w=150;
int c;
void setup(){
size(500,500);
}
void draw(){
background(#69C2F7);
w=mouseY;
if(frameCount%40>20){
w+=40;
}else{
w-=50;
}
if(mouseY<200){
c=#FF0000;
}else if(mouseY<350){
c=255;
}else{
c=#10BF08;
}
draw_bird(mouseX,mouseY);
}
void draw_bird(int x,int y){
strokeWeight(5);
fill(c);
ellipse(x,y,150,150); //head
fill(255);
ellipse(x-25,y-10,30,30); //eye l
ellipse(x+25,y-10,30,30); //eye r
fill(#FAC208);
triangle(x-20,y+30,x,y+15,x+20,y+30); //mouse on
triangle(x-15,y+30,x,y+40,x+15,y+30); //mouse under
fill(0);
ellipse(x-25,y-10,10,10); //in eye l
ellipse(x+25,y-10,10,10); //in eye r
rect(x-45,y-30,40,10); //eyebrow l
rect(x+5,y-30,40,10); //eyebrow r
line(x-75,y,x-150,w); //wing l
line(x+75,y,x+150,w); //wing r
}
int c;
void setup(){
size(500,500);
}
void draw(){
background(#69C2F7);
w=mouseY;
if(frameCount%40>20){
w+=40;
}else{
w-=50;
}
if(mouseY<200){
c=#FF0000;
}else if(mouseY<350){
c=255;
}else{
c=#10BF08;
}
draw_bird(mouseX,mouseY);
}
void draw_bird(int x,int y){
strokeWeight(5);
fill(c);
ellipse(x,y,150,150); //head
fill(255);
ellipse(x-25,y-10,30,30); //eye l
ellipse(x+25,y-10,30,30); //eye r
fill(#FAC208);
triangle(x-20,y+30,x,y+15,x+20,y+30); //mouse on
triangle(x-15,y+30,x,y+40,x+15,y+30); //mouse under
fill(0);
ellipse(x-25,y-10,10,10); //in eye l
ellipse(x+25,y-10,10,10); //in eye r
rect(x-45,y-30,40,10); //eyebrow l
rect(x+5,y-30,40,10); //eyebrow r
line(x-75,y,x-150,w); //wing l
line(x+75,y,x+150,w); //wing r
}
วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558
Lab 3 : Calculate grade from score
void setup(){
size(300,200);
background(255);
}
void draw(){
draw_score(90,100);
}
void draw_score(int x,int y){
int score=85;
fill(0);
textSize(20);
text("Your score = "+score,50,50);
if(score>=80 && score<=100){
text("Grade A",x,y);
}else if(score>=70 && score<=79){
text("Grade B",x,y);
}else if(score>=60 && score<=69){
text("Grade C",x,y);
}else if(score>=50 && score<=59){
text("Grade D",x,y);
}else if(score<=49 && score>=0){
text("Grade F",x,y);
}else{
text("Error",x,y);
}
}
size(300,200);
background(255);
}
void draw(){
draw_score(90,100);
}
void draw_score(int x,int y){
int score=85;
fill(0);
textSize(20);
text("Your score = "+score,50,50);
if(score>=80 && score<=100){
text("Grade A",x,y);
}else if(score>=70 && score<=79){
text("Grade B",x,y);
}else if(score>=60 && score<=69){
text("Grade C",x,y);
}else if(score>=50 && score<=59){
text("Grade D",x,y);
}else if(score<=49 && score>=0){
text("Grade F",x,y);
}else{
text("Error",x,y);
}
}
Before Lab 3 : Balloon (follow mouse)
void setup(){
size(300,300);
}
void draw(){
background(255);
int x=mouseX;
int y=mouseY;
if(y<50){
y=50;
fill(#9B00FC);
}else if(y>200){
fill(#00FCB3);
}else{
fill(#FC004C);
}
draw_balloon(x,y);
draw_balloon(x-100,y-100);
}
void draw_balloon(int x,int y){
strokeWeight(5);
ellipse(x,y,100,100);
line(x,y+50,x,y+150);
}
size(300,300);
}
void draw(){
background(255);
int x=mouseX;
int y=mouseY;
if(y<50){
y=50;
fill(#9B00FC);
}else if(y>200){
fill(#00FCB3);
}else{
fill(#FC004C);
}
draw_balloon(x,y);
draw_balloon(x-100,y-100);
}
void draw_balloon(int x,int y){
strokeWeight(5);
ellipse(x,y,100,100);
line(x,y+50,x,y+150);
}
Lab 2 : Syntax Error
1. Missing a semicolon เป็นการลืมใส่สัญลักษณ์ semicolon (;) หลังประโยคคำสั่ง
วิธีแก้ : ใส่ semicolon (;) ในบรรทัดที่ไม่มี
2. The variable "..." does not exist เป็นการที่เราใส่ชื่อตัวแปรไม่ตรงตามที่เราได้กำหนดไว้
วิธีแก้ : แก้ชื่อตัวแปรให้ตรงตามที่เรากำหนดไว้
3. String literal is not properly closed by a double-quote เป็นการที่เวลาพิมพ์ text แล้วใส่เครื่องหมายคำพูด ("...") ไม่ครบ
วิธีแก้ : ใส่เครื่องหมายคำพูด ("...") ให้ครบ
4. The function "..." does not exist เป็นการที่เราใส่ชื่อฟังก์ชันไม่ตรงตามชื่อฟังก์ชันของ Processing
วิธีแก้ : แก้ชื่อฟังก์ชันให้ตรงตามโปรแกรม Processing
วิธีแก้ : ใส่ semicolon (;) ในบรรทัดที่ไม่มี
2. The variable "..." does not exist เป็นการที่เราใส่ชื่อตัวแปรไม่ตรงตามที่เราได้กำหนดไว้
วิธีแก้ : แก้ชื่อตัวแปรให้ตรงตามที่เรากำหนดไว้
3. String literal is not properly closed by a double-quote เป็นการที่เวลาพิมพ์ text แล้วใส่เครื่องหมายคำพูด ("...") ไม่ครบ
วิธีแก้ : ใส่เครื่องหมายคำพูด ("...") ให้ครบ
4. The function "..." does not exist เป็นการที่เราใส่ชื่อฟังก์ชันไม่ตรงตามชื่อฟังก์ชันของ Processing
วิธีแก้ : แก้ชื่อฟังก์ชันให้ตรงตามโปรแกรม Processing
Lab 2 : Book (use function + move)
float posX=10;
float posY=20;
void setup() {
size(500, 500);
frameRate(25);
}
void draw(){
background(255);
fill(0); //hair
quad(280+posX, 70+posY, 300+posX, 80+posY,280+posX, 100+posY, 280+posX, 90+posY);
fill(0);
ellipse(280+posX, 100+posY, 25, 25);
fill(0);
ellipse(270+posX, 125+posY, 35, 35);
fill(0);
ellipse(260+posX, 150+posY, 40, 40);
fill(0);
ellipse(250+posX, 180+posY, 50, 50);
stroke(0); //face
fill(#FFEDB9);
ellipse(250+posX, 300+posY, 200, 250);
noFill(); //mouth
stroke(0);
curve(320+posX,250+posY,220+posX,350+posY,280+posX,350+posY,180+posX,250+posY);
noFill(); //eye l
stroke(0);
curve(100+posX,270+posY,190+posX,275+posY,230+posX,290+posY,200+posX,320+posY);
noFill(); //eye r
stroke(0);
curve(300+posX,320+posY,270+posX,290+posY,310+posX,275+posY,400+posX,270+posY);
stroke(0); //nose
fill(0);
ellipse(250+posX,320+posY,3,3);
stroke(#FCA88A); //cheek l
fill(#FCA88A);
ellipse(185+posX, 335+posY, 30, 30);
stroke(#FCA88A); //cheek r
fill(#FCA88A);
ellipse(315+posX, 335+posY, 30, 30);
stroke(0); //hand l
fill(#FFEDB9);
ellipse(180+posX, 410+posY, 60, 60);
stroke(0); //hand r
fill(#FFEDB9);
ellipse(320+posX, 410+posY, 60, 60);
textSize(60); //name book
fill(#1104B4);
text("REBORN!",130+posX,60+posY);
posX = (posX+5)%width;
posY = (posY+5)%width;
}
float posY=20;
void setup() {
size(500, 500);
frameRate(25);
}
void draw(){
background(255);
fill(0); //hair
quad(280+posX, 70+posY, 300+posX, 80+posY,280+posX, 100+posY, 280+posX, 90+posY);
fill(0);
ellipse(280+posX, 100+posY, 25, 25);
fill(0);
ellipse(270+posX, 125+posY, 35, 35);
fill(0);
ellipse(260+posX, 150+posY, 40, 40);
fill(0);
ellipse(250+posX, 180+posY, 50, 50);
stroke(0); //face
fill(#FFEDB9);
ellipse(250+posX, 300+posY, 200, 250);
noFill(); //mouth
stroke(0);
curve(320+posX,250+posY,220+posX,350+posY,280+posX,350+posY,180+posX,250+posY);
noFill(); //eye l
stroke(0);
curve(100+posX,270+posY,190+posX,275+posY,230+posX,290+posY,200+posX,320+posY);
noFill(); //eye r
stroke(0);
curve(300+posX,320+posY,270+posX,290+posY,310+posX,275+posY,400+posX,270+posY);
stroke(0); //nose
fill(0);
ellipse(250+posX,320+posY,3,3);
stroke(#FCA88A); //cheek l
fill(#FCA88A);
ellipse(185+posX, 335+posY, 30, 30);
stroke(#FCA88A); //cheek r
fill(#FCA88A);
ellipse(315+posX, 335+posY, 30, 30);
stroke(0); //hand l
fill(#FFEDB9);
ellipse(180+posX, 410+posY, 60, 60);
stroke(0); //hand r
fill(#FFEDB9);
ellipse(320+posX, 410+posY, 60, 60);
textSize(60); //name book
fill(#1104B4);
text("REBORN!",130+posX,60+posY);
posX = (posX+5)%width;
posY = (posY+5)%width;
}
Lab 2 : Song (use function + move)
int posX=50;
int posW=500;
int posY=0;
void setup(){
size(500,500);
frameRate(2);
}
void draw(){
draw_song(50,10);
posX = (posX+20)%width;
posW = (-posW+250)%width;
posY = (posY+50)%height;
}
void draw_song(int x,int y){
background(#FCECB5);
fill(0); //in door
stroke(0);
rect(150+x,300+posY+y,200,250);
fill(#D36A06); //l door
stroke(#D36A06);
rect(135+x,300+posY+y,15,250);
fill(#D36A06); //r door
stroke(#D36A06);
rect(350+x,300+posY+y,15,250);
fill(#D36A06); //on door
stroke(#D36A06);
rect(135+x,285+posY+y,230,15);
fill(#FF0B03); //open
stroke(#FF0B03);
ellipse(180+x,450+posY+y,20,20);
/////word on door WELCOME////
fill(#E9FF03);
textSize(20);
text("W",180+x,360+posY+y);
fill(#03F9FF);
textSize(20);
text("E",200+x,360+posY+y);
fill(#05FF03);
textSize(20);
text("L",220+x,360+posY+y);
fill(#FF9F03);
textSize(20);
text("C",240+x,360+posY+y);
fill(#AC6BF7);
textSize(20);
text("O",260+x,360+posY+y);
fill(#6BF7CA);
textSize(20);
text("M",280+x,360+posY+y);
fill(#FF0000);
textSize(20);
text("E",300+x,360+posY+y);
/////name of song/////
fill(#0D08A5);
textSize(80);
text("Pra",posX+x,140+y);
fill(#08A50E);
textSize(80);
text("Tu",150+posX+x,140+y);
fill(#BC0606);
textSize(80);
text("Jai",300+posX+x,140+y);
/////name of singer/////
fill(#AC39F5);
textSize(40);
text("Sao Sao Sao",posW+x,210+y);
}
int posW=500;
int posY=0;
void setup(){
size(500,500);
frameRate(2);
}
void draw(){
draw_song(50,10);
posX = (posX+20)%width;
posW = (-posW+250)%width;
posY = (posY+50)%height;
}
void draw_song(int x,int y){
background(#FCECB5);
fill(0); //in door
stroke(0);
rect(150+x,300+posY+y,200,250);
fill(#D36A06); //l door
stroke(#D36A06);
rect(135+x,300+posY+y,15,250);
fill(#D36A06); //r door
stroke(#D36A06);
rect(350+x,300+posY+y,15,250);
fill(#D36A06); //on door
stroke(#D36A06);
rect(135+x,285+posY+y,230,15);
fill(#FF0B03); //open
stroke(#FF0B03);
ellipse(180+x,450+posY+y,20,20);
/////word on door WELCOME////
fill(#E9FF03);
textSize(20);
text("W",180+x,360+posY+y);
fill(#03F9FF);
textSize(20);
text("E",200+x,360+posY+y);
fill(#05FF03);
textSize(20);
text("L",220+x,360+posY+y);
fill(#FF9F03);
textSize(20);
text("C",240+x,360+posY+y);
fill(#AC6BF7);
textSize(20);
text("O",260+x,360+posY+y);
fill(#6BF7CA);
textSize(20);
text("M",280+x,360+posY+y);
fill(#FF0000);
textSize(20);
text("E",300+x,360+posY+y);
/////name of song/////
fill(#0D08A5);
textSize(80);
text("Pra",posX+x,140+y);
fill(#08A50E);
textSize(80);
text("Tu",150+posX+x,140+y);
fill(#BC0606);
textSize(80);
text("Jai",300+posX+x,140+y);
/////name of singer/////
fill(#AC39F5);
textSize(40);
text("Sao Sao Sao",posW+x,210+y);
}
Lab 2 : Game (use function + move)
int posX=10;
int xx=-40;
int yy=170;
void setup(){
size(500,500);
frameRate(50);
}
void draw(){
draw_brown(150,150);
posX = (posX+5)%width;
}
void draw_brown(int x,int y){
background(#58D1F4);
fill(#6A3205); //ear l
stroke(#6A3205);
ellipse(posX-150,330,120,120);
fill(#6A3205); //ear r
stroke(#6A3205);
ellipse(posX+50,330,120,120);
fill(#4C2404); //in ear l
stroke(#4C2404);
ellipse(posX-150,330,75,75);
fill(#4C2404); //in ear r
stroke(#4C2404);
ellipse(posX+50,330,75,75);
fill(#6A3205); //head
stroke(#6A3205);
ellipse(posX-50,470,340,320);
fill(#EFF804); //petal1
stroke(#EFF804);
ellipse((posX-85)+x,165+y,50,50);
fill(#EFF804); //petal2
stroke(#EFF804);
ellipse((posX-115)+x,190+y,50,50);
fill(#EFF804); //petal3
stroke(#EFF804);
ellipse((posX-55)+x,190+y,50,50);
fill(#EFF804); //petal4
stroke(#EFF804);
ellipse((posX-65)+x,225+y,50,50);
fill(#EFF804); //petal5
stroke(#EFF804);
ellipse((posX-105)+x,225+y,50,50);
fill(#522F03); //pollen
stroke(#522F03);
ellipse((posX-85)+x,200+y,30,30);
fill(0); //eye l
stroke(0);
ellipse((posX-70),440,25,25);
fill(0); //eye r
stroke(0);
ellipse((posX-20),440,25,25);
fill(#FDCF86); //mouth
stroke(#FDCF86);
ellipse((posX-45),500,80,95);
fill(0); //nose
stroke(0);
ellipse((posX-45),485,15,15);
noFill(); //continue nose
stroke(0);
strokeWeight(2);
line((posX-45),485,(posX-45),500);
fill(#FEAF04); //sun
stroke(#FEAF04);
ellipse(posX,30,250,250);
}
int xx=-40;
int yy=170;
void setup(){
size(500,500);
frameRate(50);
}
void draw(){
draw_brown(150,150);
posX = (posX+5)%width;
}
void draw_brown(int x,int y){
background(#58D1F4);
fill(#6A3205); //ear l
stroke(#6A3205);
ellipse(posX-150,330,120,120);
fill(#6A3205); //ear r
stroke(#6A3205);
ellipse(posX+50,330,120,120);
fill(#4C2404); //in ear l
stroke(#4C2404);
ellipse(posX-150,330,75,75);
fill(#4C2404); //in ear r
stroke(#4C2404);
ellipse(posX+50,330,75,75);
fill(#6A3205); //head
stroke(#6A3205);
ellipse(posX-50,470,340,320);
fill(#EFF804); //petal1
stroke(#EFF804);
ellipse((posX-85)+x,165+y,50,50);
fill(#EFF804); //petal2
stroke(#EFF804);
ellipse((posX-115)+x,190+y,50,50);
fill(#EFF804); //petal3
stroke(#EFF804);
ellipse((posX-55)+x,190+y,50,50);
fill(#EFF804); //petal4
stroke(#EFF804);
ellipse((posX-65)+x,225+y,50,50);
fill(#EFF804); //petal5
stroke(#EFF804);
ellipse((posX-105)+x,225+y,50,50);
fill(#522F03); //pollen
stroke(#522F03);
ellipse((posX-85)+x,200+y,30,30);
fill(0); //eye l
stroke(0);
ellipse((posX-70),440,25,25);
fill(0); //eye r
stroke(0);
ellipse((posX-20),440,25,25);
fill(#FDCF86); //mouth
stroke(#FDCF86);
ellipse((posX-45),500,80,95);
fill(0); //nose
stroke(0);
ellipse((posX-45),485,15,15);
noFill(); //continue nose
stroke(0);
strokeWeight(2);
line((posX-45),485,(posX-45),500);
fill(#FEAF04); //sun
stroke(#FEAF04);
ellipse(posX,30,250,250);
}
Lab 2 : My Clock
void setup(){
size(500,300);
}
void draw(){
draw_clock(100,100);
}
void draw_clock(int posX,int posY){
background(0);
int s=second();
int m=minute();
int h=hour();
int d=day();
int mo=month();
int y=year();
fill(255);
textSize(50);
text(nf(h,2)+" : "+nf(m,2)+" : "+nf(s,2),posX,posY+80);
fill(#FF0000);
textSize(30);
text(nf(d,2)+" / "+nf(mo,2)+" / "+y,posX+30,posY);
}
size(500,300);
}
void draw(){
draw_clock(100,100);
}
void draw_clock(int posX,int posY){
background(0);
int s=second();
int m=minute();
int h=hour();
int d=day();
int mo=month();
int y=year();
fill(255);
textSize(50);
text(nf(h,2)+" : "+nf(m,2)+" : "+nf(s,2),posX,posY+80);
fill(#FF0000);
textSize(30);
text(nf(d,2)+" / "+nf(mo,2)+" / "+y,posX+30,posY);
}
Lab 2 : Battery (use function + move)
int posX=100;
int posY=100;
int y=25;
void setup(){
size(300,300);
frameRate(50);
}
void draw(){
background(#FF0000);
draw_battery(posX,posY);
posX = (posX+1)%width;
}
void draw_battery(int posX,int posY){
rect(posX+10,posY-25,40,15);
noStroke();
rect(posX-10,posY-10,80,140);
fill(0);
rect(posX-5,posY-5,70,130);
rect(posX-20,posY-30,20,5);
rect(posX+60,posY-30,20,5);
rect(posX+68,posY-37,5,20);
fill(255);
rect(posX,posY,60,20);
rect(posX,posY+y,60,20);
rect(posX,posY+2*y,60,20);
rect(posX,posY+3*y,60,20);
rect(posX,posY+4*y,60,20);
textSize(20);
text("100%",posX,posY+160);
}
int posY=100;
int y=25;
void setup(){
size(300,300);
frameRate(50);
}
void draw(){
background(#FF0000);
draw_battery(posX,posY);
posX = (posX+1)%width;
}
void draw_battery(int posX,int posY){
rect(posX+10,posY-25,40,15);
noStroke();
rect(posX-10,posY-10,80,140);
fill(0);
rect(posX-5,posY-5,70,130);
rect(posX-20,posY-30,20,5);
rect(posX+60,posY-30,20,5);
rect(posX+68,posY-37,5,20);
fill(255);
rect(posX,posY,60,20);
rect(posX,posY+y,60,20);
rect(posX,posY+2*y,60,20);
rect(posX,posY+3*y,60,20);
rect(posX,posY+4*y,60,20);
textSize(20);
text("100%",posX,posY+160);
}
Lab 2 : Positive (use function + move)
int posY=50;
void setup(){
size(500,500);
frameRate(10);
}
void draw(){
draw_positive(posX,posY);
posY = (posY+5)%height;
}
void draw_positive(int posX,int posY){
background(255);
noStroke();
fill(#FF0000);
rect(posX,posY,100,100);
rect(posX-100,posY+100,300,100);
rect(posX,posY+200,100,100);
}
วันอาทิตย์ที่ 23 สิงหาคม พ.ศ. 2558
Lab 2 : Calculate body mass index (BMI) (use function)
void setup() {
size(400,100);
background(255);
float w=40;
float h=160;
textSize(15);
fill(0);
text("Value of a BMI = "+BMI(w,h)+" kg/cm*cm",40,40);
}
///// calculate BMI/////
float BMI(float w,float h){
float BMI;
float Divisor;
Divisor = h/100;
BMI = w/(Divisor*Divisor);
return BMI;
}
Lab 2 : Calculate circumference and area of a circle (use function)
void setup() {
size(400,200);
background(255);
float r=10;
textSize(15);
fill(0);
text("Value of a Area = "+area(r)+" cm*cm",40,40);
text("Value of a Circumference = "+circum(r)+" cm.",40,80);
}
///// calculate area of circle/////
float area(float r){
float area;
area = PI*r*r;
return area;
}
/////calculate circum of circle/////
float circum(float r){
float circum;
circum = TWO_PI*r;
return circum;
}
size(400,200);
background(255);
float r=10;
textSize(15);
fill(0);
text("Value of a Area = "+area(r)+" cm*cm",40,40);
text("Value of a Circumference = "+circum(r)+" cm.",40,80);
}
///// calculate area of circle/////
float area(float r){
float area;
area = PI*r*r;
return area;
}
/////calculate circum of circle/////
float circum(float r){
float circum;
circum = TWO_PI*r;
return circum;
}
Lab 2 : Calculate circumference and area of a rectangle (use function)
void setup() {
size(400,200);
background(255);
int w=70;
int h=150;
textSize(15);
fill(0);
text("Value of a Area = "+area(w,h)+" cm*cm",40,40);
text("Value of a Circumference = "+circum(w,h)+" cm.",40,80);
}
///// calculate area of rectangle /////
int area(int w,int h){
int area;
area = w*h;
return area;
}
///// calculate circum of rectangle /////
int circum(int w,int h){
int circum;
circum = (2*w)+(2*h);
return circum;
}
Lab 1 : Calculate circumference and area of a rectangle
void setup(){
size(400,200);
float w;
float h;
float Area;
float Circumference;
//////////calculate area of a rect//////////
w=100;
h=150;
Area=w*h;
//////////calculate circumference of a rect/////////
Circumference=(2*w)+(2*h);
textSize(20);
fill(0);
text("Value of Area = "+Area+" cm*cm",20,120);
text("Value of Circumference = "+Circumference+" cm.",20,160);
text("Height = "+h+" cm.",20,40);
text("Wide = "+w+" cm.",20,80);
}
สมัครสมาชิก:
บทความ (Atom)



