วันเสาร์ที่ 28 พฤศจิกายน พ.ศ. 2558
วันอาทิตย์ที่ 15 พฤศจิกายน พ.ศ. 2558
fraction
class fraction:
def __init__(self, a, b=1):
self.a=a
self.b=b
def __add__ (self,other):
a=self.b #1
b=other.b #5
x=0
if a>b:
x=a
else:
x=b
while (not(x%a==0 and x%b==0)):
x+=1
c=x/a
d=x/b
return fraction(int(self.a*c+other.a*d),x)
def print_value (self):
print( self.a,'/',self.b)
def setup():
a=fraction(5,10)
b=fraction(2,5)
c=a+b
c.print_value()
assert c.a==9 and c.b==10
setup()
============================================================
class fraction:
def __init__(self, a, b=1):
self.a=a
self.b=b
def __add__ (self,other):
a=self.b
b=other.b
if a==b:
return fraction(self.a+other.a,self.b)
else:
return fraction(self.a*b+other.a*a,a*b)
def print_value (self):
print( self.a,'/',self.b)
def setup():
a=fraction(5,10)
b=fraction(2,5)
c=a+b
c.print_value()
assert c.a==45 and c.b==50
setup()
==============================================
def setup():
a=Fraction(3,5)
b=Fraction(4,6)
c=a.add(b)
print (c.top ,"/",c.down)
class Fraction:
def __init__(self,top,down):
self.top=top
self.down=down
def add(self,b):
lcm = (self.down*b.down)/self.gcd(self.down,b.down)
return Fraction((self.top*lcm/self.down)+(b.top*lcm/b.down),lcm)
def gcd(self,a,b):
if (b==0):
return a
else:
return self.gcd(b,a%b)
setup()
def __init__(self, a, b=1):
self.a=a
self.b=b
def __add__ (self,other):
a=self.b #1
b=other.b #5
x=0
if a>b:
x=a
else:
x=b
while (not(x%a==0 and x%b==0)):
x+=1
c=x/a
d=x/b
return fraction(int(self.a*c+other.a*d),x)
def print_value (self):
print( self.a,'/',self.b)
def setup():
a=fraction(5,10)
b=fraction(2,5)
c=a+b
c.print_value()
assert c.a==9 and c.b==10
setup()
============================================================
class fraction:
def __init__(self, a, b=1):
self.a=a
self.b=b
def __add__ (self,other):
a=self.b
b=other.b
if a==b:
return fraction(self.a+other.a,self.b)
else:
return fraction(self.a*b+other.a*a,a*b)
def print_value (self):
print( self.a,'/',self.b)
def setup():
a=fraction(5,10)
b=fraction(2,5)
c=a+b
c.print_value()
assert c.a==45 and c.b==50
setup()
==============================================
def setup():
a=Fraction(3,5)
b=Fraction(4,6)
c=a.add(b)
print (c.top ,"/",c.down)
class Fraction:
def __init__(self,top,down):
self.top=top
self.down=down
def add(self,b):
lcm = (self.down*b.down)/self.gcd(self.down,b.down)
return Fraction((self.top*lcm/self.down)+(b.top*lcm/b.down),lcm)
def gcd(self,a,b):
if (b==0):
return a
else:
return self.gcd(b,a%b)
setup()
วันพุธที่ 4 พฤศจิกายน พ.ศ. 2558
Report Raspberry pi
1.Python : รันได้ตามปกติ แต่จะช้าเล็กน้อย
2.Run A1 on web : กระตุก , ไม่เจอบัคเพราะว่ากระตุกจนเล่นไม่ได้ครับ
3.Raspberry pi : เครื่องเล็ก ใช้งานได้ แต่กระตุกไปหน่อย
2.Run A1 on web : กระตุก , ไม่เจอบัคเพราะว่ากระตุกจนเล่นไม่ได้ครับ
3.Raspberry pi : เครื่องเล็ก ใช้งานได้ แต่กระตุกไปหน่อย
Raspberry pi lab
class Student:
def __init__(self,name,id,score):
self.name=name
self.id=id
self.score=score
def display(self):
print('name :',self.name)
print('id :',self.id)
print('score :',self.score)
def get_score(self):
return self.score
def set_socre(self,score):
self.score=score
def setup():
std = [Student('John',1,81),
Student('Gase',2,80),
Student('Joh',3,75),
Student('Blob',4,65),
Student('Sk',5,85)]
count_grade('A',std)
show_allGrade(std)
def find_grade(a):
if a.get_score()>=80 and a.get_score()<=100:
return 'A'
elif a.get_score()>=70 and a.get_score()<80:
return 'B'
elif a.get_score()>60 and a.get_score()<70:
return 'C'
elif a.get_score()>=50 and a.get_score()<60:
return 'D'
elif a.get_score()<50 and a.get_score()>=0:
return 'F'
def count_grade(a,array):
count=0
i=0
while i<len(array):
if find_grade(array[i])==a:
count+=1
i+=1
print('Grade ',a,'= ',count)
def show_allGrade(a):
i=0
while i<len(a):
a[i].display()
print('Grade :',find_grade(a[i]))
i+=1
setup()
def __init__(self,name,id,score):
self.name=name
self.id=id
self.score=score
def display(self):
print('name :',self.name)
print('id :',self.id)
print('score :',self.score)
def get_score(self):
return self.score
def set_socre(self,score):
self.score=score
def setup():
std = [Student('John',1,81),
Student('Gase',2,80),
Student('Joh',3,75),
Student('Blob',4,65),
Student('Sk',5,85)]
count_grade('A',std)
show_allGrade(std)
def find_grade(a):
if a.get_score()>=80 and a.get_score()<=100:
return 'A'
elif a.get_score()>=70 and a.get_score()<80:
return 'B'
elif a.get_score()>60 and a.get_score()<70:
return 'C'
elif a.get_score()>=50 and a.get_score()<60:
return 'D'
elif a.get_score()<50 and a.get_score()>=0:
return 'F'
def count_grade(a,array):
count=0
i=0
while i<len(array):
if find_grade(array[i])==a:
count+=1
i+=1
print('Grade ',a,'= ',count)
def show_allGrade(a):
i=0
while i<len(a):
a[i].display()
print('Grade :',find_grade(a[i]))
i+=1
setup()
วันจันทร์ที่ 2 พฤศจิกายน พ.ศ. 2558
Lab08 : String to Text [Java]
public class Banner { private String text=""; private char style='#'; public Banner(String text,char style){ this.text=text; this.style=style; } public void setStyle(char style){ this.style=style; } public void display(){ String[] A={" ## ","# # ","#### ","# # ","# # "}; String[] E={ "#### ", "# ", "#### ", "# ", "#### "}; String[] C={ "#### ", "# ", "# ", "# ", "#### "}; String[] S={ "#### ", "# ", "#### ", " # ", "#### "}; int j=0; while (j<5){ int i=0; while (i<this.text.length()){ if (this.text.charAt(i)=='A'){ A[j]=replace_one(A[j],'#',this.style); System.out.print(A[j]); } if (this.text.charAt(i)=='E'){ E[j]=replace_one(E[j],'#',this.style); System.out.print(E[j]); } if (this.text.charAt(i)=='C'){ C[j]=replace_one(C[j],'#',this.style); System.out.print(C[j]); } if (this.text.charAt(i)=='S'){ S[j]=replace_one(S[j],'#',this.style); System.out.print(S[j]); } i+=1; } System.out.println(); j+=1; } } public String replace_one(String t,char s,char r){ StringBuilder temp = new StringBuilder(t); for (int i=0;i<t.length();i++){ if (t.charAt(i)=='#'){ temp.setCharAt(i,r); } } return temp.toString(); } public static void main(String[] args){ Banner B = new Banner("AEC",'x'); B.display(); B.setStyle('o'); B.display(); } }
Lab08 : Insertion sort [Java]
public class Student { private String name; private int id; private int age; private int weight; private int height; public Student(String name,int id,int age, int weight,int height) { this.name = name; this.id = id; this.age = age; this.weight=weight; this.height=height; } public int getWeight(){ return this.weight; } public int getHeight(){ return this.height; } public int getAge(){ return this.age; } public String getName(){ return this.name ; } public int getID(){ return this.id; } public void setWeight(int weight){ this.weight=weight; } public void setHeight(int height){ this.height=height; } public void setAge(int age){ this.age=age; } public void setName(String name){ this.name=name ; } public void setID(int id){ this.id=id; } public void display(){ System.out.println("Name :"+this.name); System.out.println("ID :"+this.id); System.out.println("AGE :"+this.age); System.out.println("WEIGHT :"+this.weight); System.out.println("HEIGHT :"+this.height); } public static void main(String[] args) { Student[] std={new Student("Roger",1,18,55,165), new Student("Gold",2,16,49,173), new Student("D",3,17,80,163)}; insertion_sort(std); display_student(std); } public static void display_student(Student[] std){ int i=0; while (i<std.length){ std[i].display(); i+=1; } } public static void insertion_sort(Student[] std){ int j; for (int i=0;i<std.length;i++){ j=i ; while (j>0 && std[j].getAge()<std[j-1].getAge()){ swap_student(j,j-1,std); j-=1; } } } public static void swap_student(int i,int k,Student[] stdnt){ int temp; temp=stdnt[i].getAge(); //1 stdnt[i].setAge(stdnt[k].getAge()); stdnt[k].setAge(temp) ; temp=stdnt[i].getWeight(); //2 stdnt[i].setWeight(stdnt[k].getWeight()); stdnt[k].setWeight(temp) ; temp=stdnt[i].getHeight() ;//3 stdnt[i].setHeight(stdnt[k].getHeight()); stdnt[k].setHeight(temp) ; temp=stdnt[i].getID() ;//4 stdnt[i].setID(stdnt[k].getID()); stdnt[k].setID(temp) ; String tempo=stdnt[i].getName(); //5 stdnt[i].setName(stdnt[k].getName()); stdnt[k].setName(tempo) ; } }
วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558
Lab08 : Student Class [Java]
public class Student { private String name; private int id; private int age; private int weight; private int height; public Student(String name,int id,int age, int weight,int height) { this.name = name; this.id = id; this.age = age; this.weight=weight; this.height=height; } public int get_w(){ return this.weight; } public int get_h(){ return this.height; } public int get_age(){ return this.age; } public String get_name(){ return this.name ; } public void display(){ System.out.println("Name :"+this.name); System.out.println("ID :"+this.id); System.out.println("AGE :"+this.age); System.out.println("WEIGHT :"+this.weight); System.out.println("HEIGHT :"+this.height); } public static void main(String[] args) { Student[] std={new Student("Roger",1,15,55,165), new Student("Gold",2,18,49,173), new Student("D",3,17,80,163)}; display_student(std); bmi_student(std); age_student(std); weight_student(std); } public static void display_student(Student[] std){ int i=0; while (i<std.length){ std[i].display(); i+=1; } } public static void bmi_student(Student[] std){ int i=0; int count=0; while (i<std.length){ float m=(float)std[i].get_h()/100; System.out.print("BMI [ "+std[i].get_name()+" ] ="+(float)std[i].get_w()/(m*m)); if ((float)std[i].get_w()/(m*m) > 25){ count+=1; System.out.println("<--- (BMI >25)"); } else { System.out.println(); } i+=1; } System.out.println("count BMI > 25 = "+count); } public static void age_student(Student[] std){ float avg=0; int i=0; int count=0; while (i<std.length){ avg+=std[i].get_age(); if (std[i].get_age()<30){ count+=1; } i+=1; } avg/=std.length; System.out.println("average age = "+avg); System.out.println("count age < 30 = "+count); } public static void weight_student(Student[] std){ int min=std[0].get_w(); int i=0; int count=0; while (i < std.length){ if (std[i].get_w() < min){ min=std[i].get_w(); } if (std[i].get_w() < 50){ count+=1; std[i].display(); } i+=1; } System.out.println("count Weight < 50 ="+count); } }
วันจันทร์ที่ 26 ตุลาคม พ.ศ. 2558
Lab07 : String Text
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | class banner: def __init__ (self,text,style): self.text=text self.style=style def display(self): a1=" ## " a2="# # " a3="#### " a4="# # " a5="# # " A=[a1,a2,a3,a4,a5] e1="#### " e2="# " e3="#### " e4="# " e5="#### " E=[ e1, e2, e3, e4, e5] c1="#### " c2="# " c3="# " c4="# " c5="#### " C=[ c1, c2, c3, c4, c5] s1="#### " s2="# " s3="#### " s4=" # " s5="#### " S=[ s1, s2, s3, s4, s5] j=0 while j<5: i=0 while i<len(self.text): if self.text[i]=="A": A[j]=replace_one(A[j],"#",self.style) print(A[j],end='') if self.text[i]=="E": E[j]=replace_one(E[j],"#",self.style) print(E[j],end='') if self.text[i]=="C": C[j]=replace_one(C[j],"#",self.style) print(C[j],end='') if self.text[i]=="S": S[j]=replace_one(S[j],"#",self.style) print(S[j],end='') i+=1 print() j+=1 def setStyle(self,style): self.style=style def setup(): text=input("input text:") B=banner(text,"+") B.display() B.setStyle("*") B.display() B.setStyle("#") B.display() def replace_one(t,s,r): i=0 text="" while i<len(t): if t[i]!=s: text+=t[i] else: text+=r i+=1 return text setup() |
https://repl.it/BUU7
Lab07 : Insertion sort
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | class student: def __init__(self,id_num,name,age,weight,height): self.id_num=id_num self.name=name self.age=age self.weight=weight self.height=height def display(self): print("id:",self.id_num) print("name:",self.name) print("age:",self.age) print("weight:",self.weight) print("height:",self.height) def getWeight(self): return self.weight def getHeight(self): return self.height def getAge(self): return self.age def getID(self): return self.id_num def getName(self): return self.name def setWeight(self,w): self.weight=w def setHeight(self,h): self.height=h def setAge(self,age): self.age=age def setID(self,id): self.id_num=id def setName(self,name): self.name=name def setup(): a=student(1,"John",18,100,160) b=student(2,"Jo",20,50,180) c=student(3,"Jan",17,42,150) d=student(4,"ISH",19,55,170) stdnt=[a,b,c,d] insertion_sort_class(stdnt) #sort by age display_class(stdnt) def display_class(stdnt): i=0 while i<len(stdnt): #display stdnt[i].display() i+=1 def insertion_sort_class(stdnt): i=1 j=0 while i<len(stdnt): j=i while j>0 and stdnt[j].getAge()<stdnt[j-1].getAge():#Age swap(j,j-1,stdnt) j-=1 i+=1 def swap(i,k,stdnt): temp=stdnt[i].getAge() #1 stdnt[i].setAge(stdnt[k].getAge()) stdnt[k].setAge(temp) temp=stdnt[i].getWeight() #2 stdnt[i].setWeight(stdnt[k].getWeight()) stdnt[k].setWeight(temp) temp=stdnt[i].getHeight() #3 stdnt[i].setHeight(stdnt[k].getHeight()) stdnt[k].setHeight(temp) temp=stdnt[i].getID() #4 stdnt[i].setID(stdnt[k].getID()) stdnt[k].setID(temp) temp=stdnt[i].getName() #5 stdnt[i].setName(stdnt[k].getName()) stdnt[k].setName(temp) setup() |
วันอาทิตย์ที่ 25 ตุลาคม พ.ศ. 2558
Lab07 : Student Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | class student: def __init__(self,id_num,name,age,weight,height): self.id_num=id_num self.name=name self.age=age self.weight=weight self.height=height def display(self): print("id:",self.id_num) print("name:",self.name) print("age:",self.age) print("weight:",self.weight) print("height:",self.height) def getWeight(self): return self.weight def getHeight(self): return self.height def getAge(self): return self.age def setup(): stdnt=[student(1,"John",18,100,160), student(2,"Jo",20,50,180), student(3,"Jan",17,42,150), student(4,"ISH",19,55,170)] display_class(stdnt) BMI(stdnt) age_class(stdnt) weight_class(stdnt) def display_class(stdnt): i=0 while i<len(stdnt): #display stdnt[i].display() i+=1 def BMI(student): bmi=[] i=0 while i<len(student): m=student[i].getHeight()/100 bmi.append(student[i].getWeight()/(m*m)) i+=1 print("********* Display BMI>25 *********") i=0 count=0 while i<len(bmi): #bmi>25 if bmi[i]>25: count+=1 student[i].display() i+=1 print("Count BMI>25 :",count) print("************************************") def age_class(stdnt): i=0 sum=0 while i<len(stdnt): sum+=stdnt[i].getAge() i+=1 avg=sum/len(stdnt) print("Average age:",avg) i=0 count_age=0 while i<len(stdnt): if stdnt[i].getAge()<30: count_age+=1 i+=1 print("Age < 30 :",count_age) def weight_class(stdnt): print("Min weight : ",min_class(stdnt)) print("********* Display Weight<50 *********") i=0 count_weight=0 while i<len(stdnt): if stdnt[i].getWeight()<50: count_weight+=1 stdnt[i].display() i+=1 print("Weight < 50 :",count_weight) print("************************************") def min_class(a): min=a[0].getWeight() i=0 while i<len(a): if a[i].getWeight()<min: min=a[i].getWeight() i+=1 return min setup() |
วันอังคารที่ 20 ตุลาคม พ.ศ. 2558
v1.0
/*vending machine value*/
int insert=0; //1->Select Product & Input money | 2->coin[0]>Buy & Can Buy now | 3->Press 'c' to clear
int buy=0; // total buy
int[] coin={0, 100, 100, 100, 0, 0, 0, 0, 0, 0} ;//0 total input value |1-3 remain | 4-6 input | 7-9 change
int[] n= {30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //0-4 remain | 5-9 get | 10-14 sold
int[] price={12, 20, 7, 15, 10}; //pepi orage watr tea mlk
/*animated*/
int posY=90, dy=80, c=0; //control line
int xin=0; //animated skewline
float show=-1, dx=0;//animated coin
int s=0; //coin Y position
float light_opacity=50, plusl=0.25;
/*admin value*/
String trans=""; // HISTORY detail
String timeBF=""; //checking time if same then do not add time
int count=0;
boolean admin=true;
int action=0; //'1' select action '2'insert or remove
String info="Select action by button";
int frameclick, frameZ=0, reset=0; //animated 1 second button & Z
int allzero=0;
void setup() {
size(350, 520);
textSize(15);
}
void draw() {
if (n[0]==0 && n[1]==0 && n[2]==0 && n[3]==0 && n[4]==0 && insert==0)
allzero=1;
else
allzero=0;
if (admin==true) {
background(51);
admin_panel();
} else {
ven_img();
coin[0]=coin[4]+coin[5]*5+coin[6]*10; //calc money u have
if (allzero==0) {
if (insert==1 || insert==2) {
/*TEXT ZONE*/
String textcoin="Coin 1(1):"+coin[4]+" \nCoin 5(2):"+coin[5]+" \nCoin 10(3):"+coin[6]+" \n= "+coin[0]+" Baht";
if (reset==0) {
show-=0.05;
dx+=0.5;
if (show<=-1) {
show=-1;
dx=0;
}
if (show>-1) {
draw_coin(100+dx, 428+s, map(show, 1, -1, 255, 0));
}
fill(255);
text("ENTER COIN", 20, 410);
fill(#78BC80);
text(textcoin, 20, 428);
// show text total buy
if (buy>0) { //buy > 0
fill(#C6D842);
text("Total : "+buy+".-", 130, 410);
fill(#FF5858);
text("Press Z to reset coin and item", 130, 450);
insert=2;
//================show "YOU CAN BUY" ++ ================
if (coin[0]>=buy) {
fill(#F6FF08);
text("You can BUY by press ENTER", 130, 430);
}
}
}
if (reset==1) {
fill(#f02e6e);
text("Your Change : ", 20, 410);
text(textcoin, 20, 428);
if (frameCount-frameZ==60) {
reset_CBGET();
reset=0;
insert=1;
}
}
} else if (insert==3) { //calc Change and show what you get
fill(#929292);
text("Total : "+buy+".-", 90, 430);
fill(#7c852b);
text("Your money : "+coin[0]+".-", 40, 410);
fill(#F6FF08);
text("Change : "+(coin[0]-buy)+".- "+calc_coin(coin[0]-buy), 199, 410);
fill(#C6D842);
text("Press 'C' to clear", 119, 512);
}
} else if (allzero==1) {
fill(#FC666B);
text("PLEASE CONTACT OWNER - OUT OF STOCK", 20, 450);
}
}
}
//==================================================INTERACTIVE AND INPUT======================================================================//
void mousePressed() {
if (mouseButton==LEFT) {
if (mouseX>=220 && mouseX<=340 && mouseY>=368 && mouseY<=388 && insert==0) { //can enter admin only insert==0
if (keyPressed && (key=='X' || key=='x')) {
admin=true;
}
}
//admin click quit & action//
if (admin==true) {
if (mouseX>=20 && mouseX<=70 && mouseY>=20 && mouseY<=40 && action==0) {
admin=false;
}
if (mouseX>=280 && mouseX<=340 && mouseY>=20 && mouseY<=40 && action==0) {
action=1;
}
if (mouseX>=20 && mouseX<=70 && mouseY>=20 && mouseY<=40 && action==1) {
action=0;
}
if (mouseX>=50 && mouseX<=300 && mouseY>=170 && mouseY<=250 && action==1) { //RESET MACHINE
info="Reset Machine Completed !";
frameclick=frameCount;
reset();
}
if (mouseX>=50 && mouseX<=300 && mouseY>=270 && mouseY<=350 && action==1) { //RESET SIMULATOR
info="Reset Simulator Completed !";
frameclick=frameCount;
reset();
count=0;
for (int i=10; i<=14; i++) {
n[i]=0;
}
trans="";
}
if (mouseX>=50 && mouseX<=300 && mouseY>=70 && mouseY<=150 && action==1) { //GO TO action2 = INSERT/REMOVE COINS PRODUCTS
action=2;
}
if (action==2) {
if (mouseX>=20 && mouseX<=70 && mouseY>=20 && mouseY<=40) { //back to action1
action=1;
}
for (int i=0; i<5; i++) { //add
if (mouseX>=42+60*i && mouseX<=57+60*i && mouseY>=59 && mouseY<=74) {
if (n[i]<30)
n[i]+=1;
}
}
for (int i=0; i<5; i++) { //minus
if (mouseX>=42+60*i && mouseX<=57+60*i && mouseY>=123 && mouseY<=136) {
if (n[i]>0)
n[i]-=1;
}
}
}
}
//buying zone//
if ((insert==0 || insert==1) && allzero==0) {
if (mouseX>=10 && mouseX<=130 && mouseY>=368 && mouseY<=388) {
if (insert==0) {
insert=1;
} else if (insert==1) {
insert=0;
show=-1; //resetcoin ani
reset_CBGET(); // reset coin
}
}
}
if (insert==1 || insert==2) {
for (int i=0; i<5; i++) {
if (mouseX>=315 && mouseX<=335 && mouseY>=60+60*i && mouseY<=80+60*i && n[i]>0) {
buy+=price[i];
n[i+5]+=1;
n[i]--;
}
}
}
//end buying zone//
}
}
void mouseDragged() {
if (mouseX>=169 && mouseX<=183 && mouseY>=71 && mouseY<=229) {
dy=mouseY;
if (dy>=230)dy=230;
if (dy<=80)dy=80;
posY=int(map(dy, 80, 230, 90, -c));
}
}
void keyPressed() {
if (insert==1 || insert==2 && reset==0) {
if (key=='1') {
coin[4]+=1;
show*=-1;
s=0;
dx=0;
}
if (key=='2') {
coin[5]+=1;
show*=-1;
s=20;
dx=0;
}
if (key=='3') {
coin[6]+=1;
show*=-1;
s=40;
dx=0;
}
}
if (insert==2) {
if (key=='Z' || key=='z') {
for (int i=0; i<=4; i++) { //reset number of pieces [by add nget to nremain]
n[i]+=n[i+5];
}
frameZ=frameCount;
reset=1;
}
if (keyCode==ENTER && coin[0]>=buy) {
for (int i=5; i<=9; i++) { //add sold product
n[i+5]+=n[i];
}
//add coin to remain coin
coin[1]+=coin[4];
coin[2]+=coin[5];
coin[3]+=coin[6];
count++;
String timenow=nf(hour(), 2)+":"+nf(minute(), 2); //check timebefore
if (timenow.equals(timeBF)==false) {
trans+="Time : "+timenow+"\n" ;
timeBF=timenow;
}
c+=25;// scrolling line
println(c);
trans+="+";
//check and add to history
if (n[5]>0)trans+="Px"+n[5]+" ";
if (n[6]>0)trans+="Ox"+n[6]+" ";
if (n[7]>0)trans+="Wx"+n[7]+" ";
if (n[8]>0)trans+="Tx"+n[8]+" ";
if (n[9]>0)trans+="Mx"+n[9]+" ";
trans+="\n";
insert=3;
show=-1;
}
}
if (insert==3) {
if (key=='c' || key=='C') {
//dec coin from changing
for (int i=1; i<=3; i++) {
coin[i]-=coin[i+6];
coin[i+6]=0;
}
reset_CBGET();
insert=0;
}
}
if (action==2 && admin==true) {
if (key=='+') {
if (mouseX>=61 && mouseX<=121 && mouseY>=207 && mouseY<=267) {
if (coin[3]<1000)
coin[3]++;
}
if (mouseX>=146 && mouseX<=197 && mouseY>=212 && mouseY<=263) {
if (coin[2]<1000)
coin[2]++;
}
if (mouseX>=215 && mouseX<=258 && mouseY>=218 && mouseY<=258) {
if (coin[1]<1000)
coin[1]++;
}
} else if (key=='-') {
if (mouseX>=61 && mouseX<=121 && mouseY>=207 && mouseY<=267) {
if (coin[3]>0)
coin[3]--;
}
if (mouseX>=146 && mouseX<=197 && mouseY>=212 && mouseY<=263) {
if (coin[2]>0)
coin[2]--;
}
if (mouseX>=215 && mouseX<=258 && mouseY>=218 && mouseY<=258) {
if (coin[1]>0)
coin[1]--;
}
}
}
}
//==================================================END INTERACTIVE AND INPUT======================================================================//
// draw vending machine and product
void ven_img() {
fill(31);
rect(0, 0, width, height);
fill(51);
rect(0, 0, width-20, height-170);//inner black
/*==== button ====*/
fill(0);
rect(13, 372, 120, 20);
rect(223, 372, 120, 20);
fill(#C18585);
rect(10, 368, 120, 20); //pink rect [end =130]
fill(#FF812C);
rect(220, 368, 120, 20); //yellow rect [end =340]
fill(255);
text("BUY", 20, 385);
text("ADMIN", 230, 385);
/*====draw goods zone====*/
for (int x=0; x<n[0]; x++) {
fill(0);
ellipse(20+x*40, 65, 35, 35);
pepsi(20+x*40, 60, 35, 35); //pepsi
}
for (int x=0; x<n[1]; x++) {
fill(0);
ellipse(20+x*40, 125, 35, 35);
orange(20+x*40, 120, 35, 35); //orange
}
for (int x=0; x<n[2]; x++) {
fill(0);
ellipse(20+x*40, 190, 35, 35);
water(20+x*40, 180, 35, 35); //water
}
for (int x=0; x<n[3]; x++) {
fill(0);
ellipse(20+x*40, 250, 35, 35);
tea(20+x*40, 240, 35, 35); //tea
}
for (int x=0; x<n[4]; x++) {
fill(0);
ellipse(20+x*40, 310, 35, 35);
milk(20+x*40, 300, 35, 35); //milk
}
/*end draw goods*/
if (insert>=1) { //light animated
if (light_opacity==25 || light_opacity==50)plusl*=-1;
light_opacity+=plusl;
for (int i=16; i<46; i++) { //light
stroke(#39A52B, map(i, 16, 45, light_opacity, 0)); //<change_lightcolor>
line(0, i, width, i);
line(0, 364-i, width, 364-i);
}
}
fill(20);
rect(300, 0, 50, height-170);//right tab
/*======== Draw button ==========*/
for (int i=1; i<=5; i++) {
fill(#F2315E);
rect(315, 60*i, 20, 20);
}
/*=========Show prices and show green color============*/
for (int i=0; i<=4; i++) {
if (n[i]>0) {
fill(#81FF97);
rect(315, 60*(i+1), 20, 20);
if (n[i]>0)
text(price[i]+".-", 315, 50+60*i);
}
}
fill(33);
rect(0, 0, width, 33);// Title Vending Machine & Animated
skew_line(xin, 30, 20, 30, 50, 1);
textSize(25);
fill(0);
text("Drinking Water", 93, 25);
fill(#47EAE9);
text("Drinking Water", 90, 22);
textSize(15);
}
// ======================================= Drawing Function =====================================//
void pepsi(int x, int y, int w, int h) {
noStroke();
fill(#F01D44);
ellipse(x, y, w, h);
fill(#1A73FF);
arc(x, y, w, h, radians(-20), radians(160));
stroke(255);
noFill();
strokeWeight(3);
bezier(x-w*0.47, y, x-w*0.4, y+h*0.5, x+w*0.4, y-h*0.5, x+w*0.47, y);
noStroke();
}
void orange(int x, int y, int w, int h) {
fill(#FCC80A);
ellipse(x, y, w, h);
fill(255);
ellipse(x, y, w-5, h-5);
fill(#FCC80A);
ellipse(x, y, w-10, h-10);
}
void water(int x, int y, int w, int h) {
fill(#47EAE9);
noStroke();
ellipse(x, y+h*0.159, w, h);
triangle(x, y-h*0.5, x+w*0.49, y, x-w*0.49, y);
}
void tea(int x, int y, int w, int h) {
String tea="tea";
fill(#2AB434);
noStroke();
ellipse(x, y+h*0.159, w, h);
triangle(x, y-h*0.5, x+w*0.49, y, x-w*0.49, y);
fill(255);
text(tea, x-textWidth(tea)/2, y+h*0.3);
}
void milk(int x, int y, int w, int h) {
String tea="milk";
fill(255);
noStroke();
ellipse(x, y+h*0.159, w, h);
triangle(x, y-h*0.5, x+w*0.49, y, x-w*0.49, y);
fill(#5067D6);
text(tea, x-textWidth(tea)/2, y+h*0.3);
}
void plus(float x, float y, int sizebox) {
noStroke();
fill(#9CFC82);
rect(x, y, sizebox*3, sizebox*0.8); //x
rect(x+sizebox*1.1, y-sizebox*1.1, sizebox*0.8, sizebox*3); //y
}
void minus(float x, float y, int sizebox) {
noStroke();
fill(255, 0, 0);
rect(x, y, sizebox*3, sizebox*0.8);
}
void skew_line(int x, int y, int w, int h, int n, int dx) {
noStroke();
fill(#F52A67, 50);
xin+=dx;
if (xin>=20)xin=-100;
for (int i=0; i<n; i++) {
quad(x+(i*w*2), y, x+w+(i*w*2), y, x+w*2+(i*w*2), y-h, x+w+(i*w*2), y-h);
}
}
// ======================================= END Drawing Function =====================================//
String calc_coin(int n) { //show change in coins and - coins [coin7-9 for change only]
String coins="";
if (coin[3]>0) {
coin[9]=int(n/10);
if ( coin[9]>coin[3]) coin[9]=coin[3];
n=n-( coin[9]*10);
}
if (coin[2]>0) {
coin[8]=int(n/5);
if (coin[8]>coin[2])coin[8]=coin[2];
n=n-(coin[8]*5);
}
if (coin[1]>0) {
coin[7]=n;
if (coin[7]>coin[1])coin[7]=coin[1];
}
if (coin[9]>0) coins+="\nCoin10="+coin[9]+" ";
if (coin[8]>0) coins+="\nCoin5="+coin[8]+" ";
if (coin[7]>0) coins+="\nCoin1="+coin[7]+" " ;
if (coin[7]==0 && coin[8]==0 && coin[9]==0) { // no coin and no change //coin1 5 10 for change
if (coin[0]!=buy)
coins="\nSorry no coin left.";
else
coins="\nNo Change";
}
return coins;
}
// ============================================================= ADMIN ======================================================//
void admin_panel() {
if (action!=0) {
fill(33);
rect(0, 15, width, 33);// Animated skew line
skew_line(xin, 45, 20, 30, 50, 1);
}
if (action==0) {
fill(30);
rect(185, 55, 155, 450); //box right
rect(0,73,182,444); // box left
/* =================== remaining ============== */
fill(#FA0A42);
text("Remaining Product", 190, 360);
String remain="Pepsi(P) : "+n[0]+"\nOrange Juice(O) : "+n[1]+"\nWater(W) : "+n[2]+"\nTea(T) : "+n[3]+"\nMilk(M) : "+n[4];
fill(#94FCB4);
text(remain, 190, 380);
/* ===================== sold ================= */
fill(#FF9100);
text("Sold Product", 190, 190);
String sold="Pepsi : "+n[10]+"["+(n[10]*12)+"]"+
"\nOrange Juice : "+n[11]+"["+(n[11]*20)+"]"+
"\nWater : "+n[12]+"["+(n[12]*7)+"]"+
"\nTea : "+n[13]+"["+(n[13]*15)+"]"+
"\nMilk : "+n[14]+"["+(n[14]*10)+"]";
fill(#94FCB4);
text(sold, 190, 210);
/* ===================== coin ================= */
fill(#35B45C);
text("Remaining Coins", 190, 70);
String coins="One : "+coin[1]+"\nFive : "+coin[2]+"\nTen : "+coin[3];
fill(#94FCB4);
text(coins, 190, 90);
fill(#FFC16F);
text("Value : "+(coin[1]+coin[2]*5+coin[3]*10)+" Baht", 190, 155);
text("Sold : "+(n[10]*12+n[11]*20+n[12]*7+n[13]*15+n[14]*10)+" Baht", 190, 325); //sold value
/* ===================== history ================= */
fill(120);
text(trans, 5, posY);
fill(51);
rect(0, 0, 183, 70);
fill(#FCAB40);
text("History "+day()+"/"+month()+"/"+year()+"["+count+"]", 5, 70);
ctrl_line(175, 80, 0, 255);
/*==============header====================*/
fill(33);
rect(0, 15, width, 33);// Animated skew line
skew_line(xin, 45, 20, 30, 50, 1);
fill(#6EF798);
text("ADMIN", 150, 35);
fill(30);
rect(20, 20, 50, 20, 8); //button
rect(280, 20, 60, 20, 8);
fill(#FFF708);
text("Quit", 30, 35);
text("Action", 287, 35);
} else if (action==1) {
fill(#ACA8EA);
text("ADMIN ACTION", 120, 35);
for (int i=0; i<3; i++) {
fill(35);
rect(50, 70+100*i, 250, 80, 8);
}
fill(30);
rect(20, 20, 50, 20, 8);
fill(#FFF708);
text("Back", 30, 35);
fill(#64F77D);
text("Insert/Remove Product & Coins", 60, 110);
fill(#FFDA03);
text("RESET MACHINES", 110, 210);
text("RESET SIMULATOR", 110, 310);
fill(#00B9FF);
if (frameCount-frameclick==30)info="Select action by button";
text("INFO : "+info, 71, 400);
} else if (action==2) { // INSERT OR REMOVE PRODUCT & INSERT OR REMOVE COIN
fill(#ACA8EA);
text("ADMIN ACTION", 120, 35);
fill(30);
rect(20, 20, 50, 20, 8);//back button
fill(#FFF708);
text("Back", 30, 35);//back
fill(100);
rect(0, 80, width, 40);
/*====draw goods && +,- buttonin admin zone====*/
pepsi(50, 100, 35, 35); //pepsi
orange(110, 100, 35, 35); //orange
water(170, 95, 35, 35); //water
tea(230, 95, 35, 35); //tea
milk(290, 95, 35, 35); //milk
for (int i=0; i<5; i++) {
plus(42+i*60, 65, 5);
minus(42+i*60, 130, 5);
fill(0);
rect(35+i*60, 140, 30, 20);
}
fill(#F23350);
for (int i=0; i<5; i++) {
text(nf(n[i], 2), 40+60*i, 155);
}
/*end draw goods*/
fill(#795A5F);
ellipse(92, 238, 60, 60);
ellipse(173, 238, 50, 50);
ellipse(237, 238, 40, 40);
fill(255);
text("10", 82, 243);
text("5", 168, 243);
text("1", 232, 243);
text(nf(coin[3], 3), 78, 295);
text(nf(coin[2], 3), 159, 295);
text(nf(coin[1], 3), 222, 295);
text("How to +/- coin", 88, 354);
fill(#E395A1);
text("1.place mouse on coin", 92, 374);
text("2.press + or - ", 92, 394);
}
}
void reset() { //reset machine
allzero=0;
for (int i=0; i<=4; i++) {
n[i]=30;
}
coin[1]=100;
coin[2]=100;
coin[3]=100;
}
void reset_CBGET() { //reset coin & nget & buy 'z'
coin[4]=0; //coin input reset
coin[5]=0;
coin[6]=0;
buy=0;
for (int i=5; i<=9; i++) { //reset number you get
n[i]=0;
}
}
void draw_coin(float x, int y, float z) {
noStroke();
fill(#FC2626, z);
ellipse(x, y, 15, 15);
text("+1", x+10, y);
}
void ctrl_line(int x, int y, int index, int col) {
strokeWeight(3);
stroke(255, 50);
line(x, y+150, x, y);
fill(col);
ellipse(x, dy, 10, 10);
noStroke();
}
int insert=0; //1->Select Product & Input money | 2->coin[0]>Buy & Can Buy now | 3->Press 'c' to clear
int buy=0; // total buy
int[] coin={0, 100, 100, 100, 0, 0, 0, 0, 0, 0} ;//0 total input value |1-3 remain | 4-6 input | 7-9 change
int[] n= {30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //0-4 remain | 5-9 get | 10-14 sold
int[] price={12, 20, 7, 15, 10}; //pepi orage watr tea mlk
/*animated*/
int posY=90, dy=80, c=0; //control line
int xin=0; //animated skewline
float show=-1, dx=0;//animated coin
int s=0; //coin Y position
float light_opacity=50, plusl=0.25;
/*admin value*/
String trans=""; // HISTORY detail
String timeBF=""; //checking time if same then do not add time
int count=0;
boolean admin=true;
int action=0; //'1' select action '2'insert or remove
String info="Select action by button";
int frameclick, frameZ=0, reset=0; //animated 1 second button & Z
int allzero=0;
void setup() {
size(350, 520);
textSize(15);
}
void draw() {
if (n[0]==0 && n[1]==0 && n[2]==0 && n[3]==0 && n[4]==0 && insert==0)
allzero=1;
else
allzero=0;
if (admin==true) {
background(51);
admin_panel();
} else {
ven_img();
coin[0]=coin[4]+coin[5]*5+coin[6]*10; //calc money u have
if (allzero==0) {
if (insert==1 || insert==2) {
/*TEXT ZONE*/
String textcoin="Coin 1(1):"+coin[4]+" \nCoin 5(2):"+coin[5]+" \nCoin 10(3):"+coin[6]+" \n= "+coin[0]+" Baht";
if (reset==0) {
show-=0.05;
dx+=0.5;
if (show<=-1) {
show=-1;
dx=0;
}
if (show>-1) {
draw_coin(100+dx, 428+s, map(show, 1, -1, 255, 0));
}
fill(255);
text("ENTER COIN", 20, 410);
fill(#78BC80);
text(textcoin, 20, 428);
// show text total buy
if (buy>0) { //buy > 0
fill(#C6D842);
text("Total : "+buy+".-", 130, 410);
fill(#FF5858);
text("Press Z to reset coin and item", 130, 450);
insert=2;
//================show "YOU CAN BUY" ++ ================
if (coin[0]>=buy) {
fill(#F6FF08);
text("You can BUY by press ENTER", 130, 430);
}
}
}
if (reset==1) {
fill(#f02e6e);
text("Your Change : ", 20, 410);
text(textcoin, 20, 428);
if (frameCount-frameZ==60) {
reset_CBGET();
reset=0;
insert=1;
}
}
} else if (insert==3) { //calc Change and show what you get
fill(#929292);
text("Total : "+buy+".-", 90, 430);
fill(#7c852b);
text("Your money : "+coin[0]+".-", 40, 410);
fill(#F6FF08);
text("Change : "+(coin[0]-buy)+".- "+calc_coin(coin[0]-buy), 199, 410);
fill(#C6D842);
text("Press 'C' to clear", 119, 512);
}
} else if (allzero==1) {
fill(#FC666B);
text("PLEASE CONTACT OWNER - OUT OF STOCK", 20, 450);
}
}
}
//==================================================INTERACTIVE AND INPUT======================================================================//
void mousePressed() {
if (mouseButton==LEFT) {
if (mouseX>=220 && mouseX<=340 && mouseY>=368 && mouseY<=388 && insert==0) { //can enter admin only insert==0
if (keyPressed && (key=='X' || key=='x')) {
admin=true;
}
}
//admin click quit & action//
if (admin==true) {
if (mouseX>=20 && mouseX<=70 && mouseY>=20 && mouseY<=40 && action==0) {
admin=false;
}
if (mouseX>=280 && mouseX<=340 && mouseY>=20 && mouseY<=40 && action==0) {
action=1;
}
if (mouseX>=20 && mouseX<=70 && mouseY>=20 && mouseY<=40 && action==1) {
action=0;
}
if (mouseX>=50 && mouseX<=300 && mouseY>=170 && mouseY<=250 && action==1) { //RESET MACHINE
info="Reset Machine Completed !";
frameclick=frameCount;
reset();
}
if (mouseX>=50 && mouseX<=300 && mouseY>=270 && mouseY<=350 && action==1) { //RESET SIMULATOR
info="Reset Simulator Completed !";
frameclick=frameCount;
reset();
count=0;
for (int i=10; i<=14; i++) {
n[i]=0;
}
trans="";
}
if (mouseX>=50 && mouseX<=300 && mouseY>=70 && mouseY<=150 && action==1) { //GO TO action2 = INSERT/REMOVE COINS PRODUCTS
action=2;
}
if (action==2) {
if (mouseX>=20 && mouseX<=70 && mouseY>=20 && mouseY<=40) { //back to action1
action=1;
}
for (int i=0; i<5; i++) { //add
if (mouseX>=42+60*i && mouseX<=57+60*i && mouseY>=59 && mouseY<=74) {
if (n[i]<30)
n[i]+=1;
}
}
for (int i=0; i<5; i++) { //minus
if (mouseX>=42+60*i && mouseX<=57+60*i && mouseY>=123 && mouseY<=136) {
if (n[i]>0)
n[i]-=1;
}
}
}
}
//buying zone//
if ((insert==0 || insert==1) && allzero==0) {
if (mouseX>=10 && mouseX<=130 && mouseY>=368 && mouseY<=388) {
if (insert==0) {
insert=1;
} else if (insert==1) {
insert=0;
show=-1; //resetcoin ani
reset_CBGET(); // reset coin
}
}
}
if (insert==1 || insert==2) {
for (int i=0; i<5; i++) {
if (mouseX>=315 && mouseX<=335 && mouseY>=60+60*i && mouseY<=80+60*i && n[i]>0) {
buy+=price[i];
n[i+5]+=1;
n[i]--;
}
}
}
//end buying zone//
}
}
void mouseDragged() {
if (mouseX>=169 && mouseX<=183 && mouseY>=71 && mouseY<=229) {
dy=mouseY;
if (dy>=230)dy=230;
if (dy<=80)dy=80;
posY=int(map(dy, 80, 230, 90, -c));
}
}
void keyPressed() {
if (insert==1 || insert==2 && reset==0) {
if (key=='1') {
coin[4]+=1;
show*=-1;
s=0;
dx=0;
}
if (key=='2') {
coin[5]+=1;
show*=-1;
s=20;
dx=0;
}
if (key=='3') {
coin[6]+=1;
show*=-1;
s=40;
dx=0;
}
}
if (insert==2) {
if (key=='Z' || key=='z') {
for (int i=0; i<=4; i++) { //reset number of pieces [by add nget to nremain]
n[i]+=n[i+5];
}
frameZ=frameCount;
reset=1;
}
if (keyCode==ENTER && coin[0]>=buy) {
for (int i=5; i<=9; i++) { //add sold product
n[i+5]+=n[i];
}
//add coin to remain coin
coin[1]+=coin[4];
coin[2]+=coin[5];
coin[3]+=coin[6];
count++;
String timenow=nf(hour(), 2)+":"+nf(minute(), 2); //check timebefore
if (timenow.equals(timeBF)==false) {
trans+="Time : "+timenow+"\n" ;
timeBF=timenow;
}
c+=25;// scrolling line
println(c);
trans+="+";
//check and add to history
if (n[5]>0)trans+="Px"+n[5]+" ";
if (n[6]>0)trans+="Ox"+n[6]+" ";
if (n[7]>0)trans+="Wx"+n[7]+" ";
if (n[8]>0)trans+="Tx"+n[8]+" ";
if (n[9]>0)trans+="Mx"+n[9]+" ";
trans+="\n";
insert=3;
show=-1;
}
}
if (insert==3) {
if (key=='c' || key=='C') {
//dec coin from changing
for (int i=1; i<=3; i++) {
coin[i]-=coin[i+6];
coin[i+6]=0;
}
reset_CBGET();
insert=0;
}
}
if (action==2 && admin==true) {
if (key=='+') {
if (mouseX>=61 && mouseX<=121 && mouseY>=207 && mouseY<=267) {
if (coin[3]<1000)
coin[3]++;
}
if (mouseX>=146 && mouseX<=197 && mouseY>=212 && mouseY<=263) {
if (coin[2]<1000)
coin[2]++;
}
if (mouseX>=215 && mouseX<=258 && mouseY>=218 && mouseY<=258) {
if (coin[1]<1000)
coin[1]++;
}
} else if (key=='-') {
if (mouseX>=61 && mouseX<=121 && mouseY>=207 && mouseY<=267) {
if (coin[3]>0)
coin[3]--;
}
if (mouseX>=146 && mouseX<=197 && mouseY>=212 && mouseY<=263) {
if (coin[2]>0)
coin[2]--;
}
if (mouseX>=215 && mouseX<=258 && mouseY>=218 && mouseY<=258) {
if (coin[1]>0)
coin[1]--;
}
}
}
}
//==================================================END INTERACTIVE AND INPUT======================================================================//
// draw vending machine and product
void ven_img() {
fill(31);
rect(0, 0, width, height);
fill(51);
rect(0, 0, width-20, height-170);//inner black
/*==== button ====*/
fill(0);
rect(13, 372, 120, 20);
rect(223, 372, 120, 20);
fill(#C18585);
rect(10, 368, 120, 20); //pink rect [end =130]
fill(#FF812C);
rect(220, 368, 120, 20); //yellow rect [end =340]
fill(255);
text("BUY", 20, 385);
text("ADMIN", 230, 385);
/*====draw goods zone====*/
for (int x=0; x<n[0]; x++) {
fill(0);
ellipse(20+x*40, 65, 35, 35);
pepsi(20+x*40, 60, 35, 35); //pepsi
}
for (int x=0; x<n[1]; x++) {
fill(0);
ellipse(20+x*40, 125, 35, 35);
orange(20+x*40, 120, 35, 35); //orange
}
for (int x=0; x<n[2]; x++) {
fill(0);
ellipse(20+x*40, 190, 35, 35);
water(20+x*40, 180, 35, 35); //water
}
for (int x=0; x<n[3]; x++) {
fill(0);
ellipse(20+x*40, 250, 35, 35);
tea(20+x*40, 240, 35, 35); //tea
}
for (int x=0; x<n[4]; x++) {
fill(0);
ellipse(20+x*40, 310, 35, 35);
milk(20+x*40, 300, 35, 35); //milk
}
/*end draw goods*/
if (insert>=1) { //light animated
if (light_opacity==25 || light_opacity==50)plusl*=-1;
light_opacity+=plusl;
for (int i=16; i<46; i++) { //light
stroke(#39A52B, map(i, 16, 45, light_opacity, 0)); //<change_lightcolor>
line(0, i, width, i);
line(0, 364-i, width, 364-i);
}
}
fill(20);
rect(300, 0, 50, height-170);//right tab
/*======== Draw button ==========*/
for (int i=1; i<=5; i++) {
fill(#F2315E);
rect(315, 60*i, 20, 20);
}
/*=========Show prices and show green color============*/
for (int i=0; i<=4; i++) {
if (n[i]>0) {
fill(#81FF97);
rect(315, 60*(i+1), 20, 20);
if (n[i]>0)
text(price[i]+".-", 315, 50+60*i);
}
}
fill(33);
rect(0, 0, width, 33);// Title Vending Machine & Animated
skew_line(xin, 30, 20, 30, 50, 1);
textSize(25);
fill(0);
text("Drinking Water", 93, 25);
fill(#47EAE9);
text("Drinking Water", 90, 22);
textSize(15);
}
// ======================================= Drawing Function =====================================//
void pepsi(int x, int y, int w, int h) {
noStroke();
fill(#F01D44);
ellipse(x, y, w, h);
fill(#1A73FF);
arc(x, y, w, h, radians(-20), radians(160));
stroke(255);
noFill();
strokeWeight(3);
bezier(x-w*0.47, y, x-w*0.4, y+h*0.5, x+w*0.4, y-h*0.5, x+w*0.47, y);
noStroke();
}
void orange(int x, int y, int w, int h) {
fill(#FCC80A);
ellipse(x, y, w, h);
fill(255);
ellipse(x, y, w-5, h-5);
fill(#FCC80A);
ellipse(x, y, w-10, h-10);
}
void water(int x, int y, int w, int h) {
fill(#47EAE9);
noStroke();
ellipse(x, y+h*0.159, w, h);
triangle(x, y-h*0.5, x+w*0.49, y, x-w*0.49, y);
}
void tea(int x, int y, int w, int h) {
String tea="tea";
fill(#2AB434);
noStroke();
ellipse(x, y+h*0.159, w, h);
triangle(x, y-h*0.5, x+w*0.49, y, x-w*0.49, y);
fill(255);
text(tea, x-textWidth(tea)/2, y+h*0.3);
}
void milk(int x, int y, int w, int h) {
String tea="milk";
fill(255);
noStroke();
ellipse(x, y+h*0.159, w, h);
triangle(x, y-h*0.5, x+w*0.49, y, x-w*0.49, y);
fill(#5067D6);
text(tea, x-textWidth(tea)/2, y+h*0.3);
}
void plus(float x, float y, int sizebox) {
noStroke();
fill(#9CFC82);
rect(x, y, sizebox*3, sizebox*0.8); //x
rect(x+sizebox*1.1, y-sizebox*1.1, sizebox*0.8, sizebox*3); //y
}
void minus(float x, float y, int sizebox) {
noStroke();
fill(255, 0, 0);
rect(x, y, sizebox*3, sizebox*0.8);
}
void skew_line(int x, int y, int w, int h, int n, int dx) {
noStroke();
fill(#F52A67, 50);
xin+=dx;
if (xin>=20)xin=-100;
for (int i=0; i<n; i++) {
quad(x+(i*w*2), y, x+w+(i*w*2), y, x+w*2+(i*w*2), y-h, x+w+(i*w*2), y-h);
}
}
// ======================================= END Drawing Function =====================================//
String calc_coin(int n) { //show change in coins and - coins [coin7-9 for change only]
String coins="";
if (coin[3]>0) {
coin[9]=int(n/10);
if ( coin[9]>coin[3]) coin[9]=coin[3];
n=n-( coin[9]*10);
}
if (coin[2]>0) {
coin[8]=int(n/5);
if (coin[8]>coin[2])coin[8]=coin[2];
n=n-(coin[8]*5);
}
if (coin[1]>0) {
coin[7]=n;
if (coin[7]>coin[1])coin[7]=coin[1];
}
if (coin[9]>0) coins+="\nCoin10="+coin[9]+" ";
if (coin[8]>0) coins+="\nCoin5="+coin[8]+" ";
if (coin[7]>0) coins+="\nCoin1="+coin[7]+" " ;
if (coin[7]==0 && coin[8]==0 && coin[9]==0) { // no coin and no change //coin1 5 10 for change
if (coin[0]!=buy)
coins="\nSorry no coin left.";
else
coins="\nNo Change";
}
return coins;
}
// ============================================================= ADMIN ======================================================//
void admin_panel() {
if (action!=0) {
fill(33);
rect(0, 15, width, 33);// Animated skew line
skew_line(xin, 45, 20, 30, 50, 1);
}
if (action==0) {
fill(30);
rect(185, 55, 155, 450); //box right
rect(0,73,182,444); // box left
/* =================== remaining ============== */
fill(#FA0A42);
text("Remaining Product", 190, 360);
String remain="Pepsi(P) : "+n[0]+"\nOrange Juice(O) : "+n[1]+"\nWater(W) : "+n[2]+"\nTea(T) : "+n[3]+"\nMilk(M) : "+n[4];
fill(#94FCB4);
text(remain, 190, 380);
/* ===================== sold ================= */
fill(#FF9100);
text("Sold Product", 190, 190);
String sold="Pepsi : "+n[10]+"["+(n[10]*12)+"]"+
"\nOrange Juice : "+n[11]+"["+(n[11]*20)+"]"+
"\nWater : "+n[12]+"["+(n[12]*7)+"]"+
"\nTea : "+n[13]+"["+(n[13]*15)+"]"+
"\nMilk : "+n[14]+"["+(n[14]*10)+"]";
fill(#94FCB4);
text(sold, 190, 210);
/* ===================== coin ================= */
fill(#35B45C);
text("Remaining Coins", 190, 70);
String coins="One : "+coin[1]+"\nFive : "+coin[2]+"\nTen : "+coin[3];
fill(#94FCB4);
text(coins, 190, 90);
fill(#FFC16F);
text("Value : "+(coin[1]+coin[2]*5+coin[3]*10)+" Baht", 190, 155);
text("Sold : "+(n[10]*12+n[11]*20+n[12]*7+n[13]*15+n[14]*10)+" Baht", 190, 325); //sold value
/* ===================== history ================= */
fill(120);
text(trans, 5, posY);
fill(51);
rect(0, 0, 183, 70);
fill(#FCAB40);
text("History "+day()+"/"+month()+"/"+year()+"["+count+"]", 5, 70);
ctrl_line(175, 80, 0, 255);
/*==============header====================*/
fill(33);
rect(0, 15, width, 33);// Animated skew line
skew_line(xin, 45, 20, 30, 50, 1);
fill(#6EF798);
text("ADMIN", 150, 35);
fill(30);
rect(20, 20, 50, 20, 8); //button
rect(280, 20, 60, 20, 8);
fill(#FFF708);
text("Quit", 30, 35);
text("Action", 287, 35);
} else if (action==1) {
fill(#ACA8EA);
text("ADMIN ACTION", 120, 35);
for (int i=0; i<3; i++) {
fill(35);
rect(50, 70+100*i, 250, 80, 8);
}
fill(30);
rect(20, 20, 50, 20, 8);
fill(#FFF708);
text("Back", 30, 35);
fill(#64F77D);
text("Insert/Remove Product & Coins", 60, 110);
fill(#FFDA03);
text("RESET MACHINES", 110, 210);
text("RESET SIMULATOR", 110, 310);
fill(#00B9FF);
if (frameCount-frameclick==30)info="Select action by button";
text("INFO : "+info, 71, 400);
} else if (action==2) { // INSERT OR REMOVE PRODUCT & INSERT OR REMOVE COIN
fill(#ACA8EA);
text("ADMIN ACTION", 120, 35);
fill(30);
rect(20, 20, 50, 20, 8);//back button
fill(#FFF708);
text("Back", 30, 35);//back
fill(100);
rect(0, 80, width, 40);
/*====draw goods && +,- buttonin admin zone====*/
pepsi(50, 100, 35, 35); //pepsi
orange(110, 100, 35, 35); //orange
water(170, 95, 35, 35); //water
tea(230, 95, 35, 35); //tea
milk(290, 95, 35, 35); //milk
for (int i=0; i<5; i++) {
plus(42+i*60, 65, 5);
minus(42+i*60, 130, 5);
fill(0);
rect(35+i*60, 140, 30, 20);
}
fill(#F23350);
for (int i=0; i<5; i++) {
text(nf(n[i], 2), 40+60*i, 155);
}
/*end draw goods*/
fill(#795A5F);
ellipse(92, 238, 60, 60);
ellipse(173, 238, 50, 50);
ellipse(237, 238, 40, 40);
fill(255);
text("10", 82, 243);
text("5", 168, 243);
text("1", 232, 243);
text(nf(coin[3], 3), 78, 295);
text(nf(coin[2], 3), 159, 295);
text(nf(coin[1], 3), 222, 295);
text("How to +/- coin", 88, 354);
fill(#E395A1);
text("1.place mouse on coin", 92, 374);
text("2.press + or - ", 92, 394);
}
}
void reset() { //reset machine
allzero=0;
for (int i=0; i<=4; i++) {
n[i]=30;
}
coin[1]=100;
coin[2]=100;
coin[3]=100;
}
void reset_CBGET() { //reset coin & nget & buy 'z'
coin[4]=0; //coin input reset
coin[5]=0;
coin[6]=0;
buy=0;
for (int i=5; i<=9; i++) { //reset number you get
n[i]=0;
}
}
void draw_coin(float x, int y, float z) {
noStroke();
fill(#FC2626, z);
ellipse(x, y, 15, 15);
text("+1", x+10, y);
}
void ctrl_line(int x, int y, int index, int col) {
strokeWeight(3);
stroke(255, 50);
line(x, y+150, x, y);
fill(col);
ellipse(x, dy, 10, 10);
noStroke();
}
สมัครสมาชิก:
บทความ (Atom)
commit เพิ่มเติม : เพื่ม userstory, bookmark
>> add userstory ทำการเพิ่ม userstory ใน functional tests >> add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...
-
1 2 3 4 5 6 7 8 9 def setup (): print (d2b( 8 )) def d2b (num): x = "" while num > 0 : x = str ( int (n...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 def test_layout_and_styling ( self ): # Edith goes to the home page self . brow...
-
การใช้ template inheritence คือการสืบทอดเทมเพลต เพื่อให้ไม่ต้องเขียนโค้ดหน้าเว็บๆซ้ำๆ เราจะมีหน้าหลักอันเดียว (base.html or parent) ภายในนั...