วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558
[LAB_INTRO] Raseberry pi
class Student:
def __init__(self,name,ID,score):
self.name = name
self.ID = ID
self.score = score
def display(self):
print(self.name)
print(self.ID)
print(self.score)
def get_name(self):
return self.name
def get_score(self):
return self.score
def setup():
A = Student('Bung',10041,86)
B = Student('Ploy',20119,75)
C = Student('Toffy',20042,71)
D = Student('Game',20145,65)
E = Student('Mew',30078,79)
Total = [A,B,C,D,E]
print(find_grade(C))
print(count_grade('A',Total))
print()
show_allGtade(Total)
def find_grade(i):
char = ''
score = i.get_score()
if(score >= 80):
char = 'A'
elif(score >= 70 and score <= 79):
char = 'B'
elif(score >= 60 and score <= 69):
char = 'C'
elif(score >= 50 and score <= 59):
char = 'D'
else:
char = 'E'
return char
def count_grade(char , Total):
i = 0
number = 0
while(i < len(Total)):
score = Total[i].get_score()
if(char == 'A' and score >= 80):
number = number + 1
elif(char == 'B' and score >= 70 and score <= 79):
number = number + 1
elif(char == 'C' and score >= 60 and score <= 69):
number = number + 1
elif(char == 'D' and score >= 50 and score <= 59):
number = number + 1
elif(char == 'F' and score <= 49):
number = number + 1
i = i+1
return number
def show_allGtade(Total):
for i in Total:
i.display()
print(find_grade(i))
print()
setup()
def __init__(self,name,ID,score):
self.name = name
self.ID = ID
self.score = score
def display(self):
print(self.name)
print(self.ID)
print(self.score)
def get_name(self):
return self.name
def get_score(self):
return self.score
def setup():
A = Student('Bung',10041,86)
B = Student('Ploy',20119,75)
C = Student('Toffy',20042,71)
D = Student('Game',20145,65)
E = Student('Mew',30078,79)
Total = [A,B,C,D,E]
print(find_grade(C))
print(count_grade('A',Total))
print()
show_allGtade(Total)
def find_grade(i):
char = ''
score = i.get_score()
if(score >= 80):
char = 'A'
elif(score >= 70 and score <= 79):
char = 'B'
elif(score >= 60 and score <= 69):
char = 'C'
elif(score >= 50 and score <= 59):
char = 'D'
else:
char = 'E'
return char
def count_grade(char , Total):
i = 0
number = 0
while(i < len(Total)):
score = Total[i].get_score()
if(char == 'A' and score >= 80):
number = number + 1
elif(char == 'B' and score >= 70 and score <= 79):
number = number + 1
elif(char == 'C' and score >= 60 and score <= 69):
number = number + 1
elif(char == 'D' and score >= 50 and score <= 59):
number = number + 1
elif(char == 'F' and score <= 49):
number = number + 1
i = i+1
return number
def show_allGtade(Total):
for i in Total:
i.display()
print(find_grade(i))
print()
setup()
[LAB8] BANNER V#JAVA
public class Banner {
private String word;
private String symbol;
public Banner(String word, String symbol) {
this.word = word;
this.symbol = symbol;
}
public void printWord() {
String[] A = { "A", " # ", " # # ", "# #", "#####", "# #" };
String[] C = { "C", "#####", "# ", "# ", "# ", "#####" };
String[] E = { "E", "#####", "# ", "#### ", "# ", "#####" };
String[] blank = { " ", " ", " ", " ", " ", " " };
String[][] character = { A, C, E, blank };
this.changesymbol(character);
char[] wordArray = this.word.toCharArray();
for (int row = 1; row <= 5; row++) {
for (int i = 0; i < this.word.length(); i++) {
for (int j = 0; j < character.length; j++) {
char checkChar = character[j][0].charAt(0);
if (wordArray[i] == checkChar) {
System.out.print(character[j][row]+" ");
}
}
}
System.out.println();
}
}
public void changesymbol(String[][] character) {
for (int i = 0; i < character.length; i++) {
for (int j = 1; j < character[i].length; j++) {
String newSymbol = "";
char[] wordArray = character[i][j].toCharArray();
char checkSymbol = this.symbol.charAt(0);
for (int k = 0; k < character[i][j].length(); k++) {
if (wordArray[k] != checkSymbol && wordArray[k] != ' ') {
newSymbol += this.symbol;
} else {
newSymbol += wordArray[k];
}
}
character[i][j] = newSymbol;
}
}
}
public void set_symbol(String symbol) {
this.symbol = symbol;
}
public static void main(String[] args) {
Banner word = new Banner("AEC ACE ECE ACA", "#");
word.printWord();
System.out.println();
word.set_symbol("*");
word.printWord();
}
}
private String word;
private String symbol;
public Banner(String word, String symbol) {
this.word = word;
this.symbol = symbol;
}
public void printWord() {
String[] A = { "A", " # ", " # # ", "# #", "#####", "# #" };
String[] C = { "C", "#####", "# ", "# ", "# ", "#####" };
String[] E = { "E", "#####", "# ", "#### ", "# ", "#####" };
String[] blank = { " ", " ", " ", " ", " ", " " };
String[][] character = { A, C, E, blank };
this.changesymbol(character);
char[] wordArray = this.word.toCharArray();
for (int row = 1; row <= 5; row++) {
for (int i = 0; i < this.word.length(); i++) {
for (int j = 0; j < character.length; j++) {
char checkChar = character[j][0].charAt(0);
if (wordArray[i] == checkChar) {
System.out.print(character[j][row]+" ");
}
}
}
System.out.println();
}
}
public void changesymbol(String[][] character) {
for (int i = 0; i < character.length; i++) {
for (int j = 1; j < character[i].length; j++) {
String newSymbol = "";
char[] wordArray = character[i][j].toCharArray();
char checkSymbol = this.symbol.charAt(0);
for (int k = 0; k < character[i][j].length(); k++) {
if (wordArray[k] != checkSymbol && wordArray[k] != ' ') {
newSymbol += this.symbol;
} else {
newSymbol += wordArray[k];
}
}
character[i][j] = newSymbol;
}
}
}
public void set_symbol(String symbol) {
this.symbol = symbol;
}
public static void main(String[] args) {
Banner word = new Banner("AEC ACE ECE ACA", "#");
word.printWord();
System.out.println();
word.set_symbol("*");
word.printWord();
}
}
[LAB8] AGE #JAVA
public class DataStudent
{
private String name;
private int sID;
private int age;
private int height;
private int weight;
public DataStudent(String name, int sID, int age, int height, int weight)
{
this.name = name;
this.sID = sID;
this.age = age;
this.height = height;
this.weight = weight;
}
public String get_name()
{
return this.name;
}
public int get_age()
{
return this.age;
}
public static void main(String[] args)
{
DataStudent[] s =
{
new DataStudent("Nop",20046,28.0,173,52),
new DataStudent("Pee",20054,35.0,176,78),
new DataStudent("Fern",20097,26.0,174,58),
};
//System.out.println(find_average(s));
//System.out.println(find_age_less30(s));
System.out.println(Sort_Age(s))
}
public static float find_average(DataStudent s)
{
float i = 0;
float total = 0;
float a = 0;
while(i < s.length)
{
total = total + s[i].get_age() ;
i = i + 1 ;
}
a = total / s.length ;
return a ;
}
public static int find_age_less30(DataStudent[] s)
{
int c = 0;
while(int i = 0 < student.length)
{
if(s[i].get_age() < 30)
{
c = c + 1;
}
}
return c;
}
public static void Sort_Age(Student[] student)
{
for (int i = 1; i < student.length; i++)
{
Student currentStudent = student[i];
int pos = i;
while(pos > 0 && student[pos - 1].get_age() > currentStudent.get_age())
{
student[pos] = student[pos - 1];
pos = pos - 1;
}
student[pos] = currentStudent;
}
}
}
{
private String name;
private int sID;
private int age;
private int height;
private int weight;
public DataStudent(String name, int sID, int age, int height, int weight)
{
this.name = name;
this.sID = sID;
this.age = age;
this.height = height;
this.weight = weight;
}
public String get_name()
{
return this.name;
}
public int get_age()
{
return this.age;
}
public static void main(String[] args)
{
DataStudent[] s =
{
new DataStudent("Nop",20046,28.0,173,52),
new DataStudent("Pee",20054,35.0,176,78),
new DataStudent("Fern",20097,26.0,174,58),
};
//System.out.println(find_average(s));
//System.out.println(find_age_less30(s));
System.out.println(Sort_Age(s))
}
public static float find_average(DataStudent s)
{
float i = 0;
float total = 0;
float a = 0;
while(i < s.length)
{
total = total + s[i].get_age() ;
i = i + 1 ;
}
a = total / s.length ;
return a ;
}
public static int find_age_less30(DataStudent[] s)
{
int c = 0;
while(int i = 0 < student.length)
{
if(s[i].get_age() < 30)
{
c = c + 1;
}
}
return c;
}
public static void Sort_Age(Student[] student)
{
for (int i = 1; i < student.length; i++)
{
Student currentStudent = student[i];
int pos = i;
while(pos > 0 && student[pos - 1].get_age() > currentStudent.get_age())
{
student[pos] = student[pos - 1];
pos = pos - 1;
}
student[pos] = currentStudent;
}
}
}
[LAB8] BMI #JAVA
public class DataStudent
{
private String name;
private int sID;
private int age;
private int height;
private int weight;
public DataStudent(String name, int sID, int age, int height, int weight)
{
this.name = name;
this.sID = sID;
this.age = age;
this.height = height;
this.weight = weight;
}
public String get_name()
{
return this.name;
}
public float get_weight()
{
return this.weight;
}
public float get_height()
{
return this.height;
}
public static void main(String[] args)
{
DataStudent[] s =
{
new DataStudent("Nop",20046,28,173,52),
new DataStudent("Pee",20054,35,176,78),
new DataStudent("Fern",20097,26,174,58),
};
//display_bmi_more_25
int i = 0;
while(i < s.length)
{
if(find_BMI_more25(s[i]) > 25)
{
System.out.println();
System.out.println(s[i].get_name());
System.out.println(String.format("%.2f",find_BMI_more25(s[i])));
}
i = i + 1;
}
}
public static float find_BMI_more25(DataStudent sign)
{
float bmi = sign.get_weight()/((sign.get_height()/100) * (sign.get_height()/100));
return bmi ;
}
}
{
private String name;
private int sID;
private int age;
private int height;
private int weight;
public DataStudent(String name, int sID, int age, int height, int weight)
{
this.name = name;
this.sID = sID;
this.age = age;
this.height = height;
this.weight = weight;
}
public String get_name()
{
return this.name;
}
public float get_weight()
{
return this.weight;
}
public float get_height()
{
return this.height;
}
public static void main(String[] args)
{
DataStudent[] s =
{
new DataStudent("Nop",20046,28,173,52),
new DataStudent("Pee",20054,35,176,78),
new DataStudent("Fern",20097,26,174,58),
};
//display_bmi_more_25
int i = 0;
while(i < s.length)
{
if(find_BMI_more25(s[i]) > 25)
{
System.out.println();
System.out.println(s[i].get_name());
System.out.println(String.format("%.2f",find_BMI_more25(s[i])));
}
i = i + 1;
}
}
public static float find_BMI_more25(DataStudent sign)
{
float bmi = sign.get_weight()/((sign.get_height()/100) * (sign.get_height()/100));
return bmi ;
}
}
[LAB8] Data Student #JAVA
public class DataStudent
{
private String name;
private int sID;
private int age;
private int height;
private int weight;
public DataStudent(String name, int sID, int age, int height, int weight)
{
this.name = name;
this.sID = sID;
this.age = age;
this.height = height;
this.weight = weight;
}
public void display()
{
System.out.println(this.name);
System.out.println(this.sID);
System.out.println(this.age);
System.out.println(this.height);
System.out.println(this.weight+"\n");
}
public static void main(String[] args)
{
DataStudent[] s =
{
new DataStudent("Nop",20046,28,173,52),
new DataStudent("Pee",20054,35,176,67),
new DataStudent("Fern",20097,26,174,58),
};
//Display_student
int i = 0;
while(i < s.length)
{
s[i].display();
i = i + 1;
}
}
}
{
private String name;
private int sID;
private int age;
private int height;
private int weight;
public DataStudent(String name, int sID, int age, int height, int weight)
{
this.name = name;
this.sID = sID;
this.age = age;
this.height = height;
this.weight = weight;
}
public void display()
{
System.out.println(this.name);
System.out.println(this.sID);
System.out.println(this.age);
System.out.println(this.height);
System.out.println(this.weight+"\n");
}
public static void main(String[] args)
{
DataStudent[] s =
{
new DataStudent("Nop",20046,28,173,52),
new DataStudent("Pee",20054,35,176,67),
new DataStudent("Fern",20097,26,174,58),
};
//Display_student
int i = 0;
while(i < s.length)
{
s[i].display();
i = i + 1;
}
}
}
วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558
[LAB7] BANNER LETTER #INCOMPLETE
class words:
def __init__(self,first,second,third,fourth,fifth):
self.first = first
self.second = second
self.third = third
self.fourth = fourth
self.fifth = fifth
def display_L_first(self):
print(self.first,end = "")
def display_L_second(self):
print(self.second,end = "")
def display_L_third(self):
print(self.third,end = "")
def display_L_fourth(self):
print(self.fourth,end = "")
def display_L_fifth(self):
print(self.fifth,end = "")
def get_word_L_first(self):
return self.first
def get_word_L_second(self):
return self.second
def get_word_L_third(self):
return self.third
def get_word_L_fourth(self):
return self.fourth
def get_word_L_fifth(self):
return self.fifth
def star_first(self):
hashtag_star(self.first)
def star_second(self):
hashtag_star(self.second)
def star_third(self):
hashtag_star(self.third)
def star_fourth(self):
hashtag_star(self.fourth)
def star_fifth(self):
hashtag_star(self.fifth)
def setup():
B = words("#####","# #","#####","# #","#####")
U = words("# #","# #","# #","# #"," ### ")
N = words("# #","## #","# # #","# ##","# #")
G = words(" ####","# ","# ###","# #","#####")
letter = [B,U,N,G]
word = input("")
draw_word(letter,word)
def draw_word(letter,word):
i_print = 0
while(i_print < 5):
i = 0
while(i < len(word)):
if(word[i] == "B"):
fun_print(letter,i_print,0)
elif(word[i] == "L"):
fun_print(letter,i_print,1)
elif(word[i] == "U"):
fun_print(letter,i_print,2)
elif(word[i] == "E"):
fun_print(letter,i_print,3)
i = i + 1
print()
i_print = i_print + 1
def hashtag_star(temp):
i = 0
while(i < len(temp)):
if(temp[i] == "#"):
print("*",end = "")
else:
print(" ",end = "")
i = i + 1
def fun_print(letter,i_print,word_index):
if(i_print == 0):
letter[word_index].star_first()
elif(i_print == 1):
letter[word_index].star_second()
elif(i_print == 2):
letter[word_index].star_third()
elif(i_print == 3):
letter[word_index].star_fourth()
elif(i_print == 4):
letter[word_index].star_fifth()
setup()
def __init__(self,first,second,third,fourth,fifth):
self.first = first
self.second = second
self.third = third
self.fourth = fourth
self.fifth = fifth
def display_L_first(self):
print(self.first,end = "")
def display_L_second(self):
print(self.second,end = "")
def display_L_third(self):
print(self.third,end = "")
def display_L_fourth(self):
print(self.fourth,end = "")
def display_L_fifth(self):
print(self.fifth,end = "")
def get_word_L_first(self):
return self.first
def get_word_L_second(self):
return self.second
def get_word_L_third(self):
return self.third
def get_word_L_fourth(self):
return self.fourth
def get_word_L_fifth(self):
return self.fifth
def star_first(self):
hashtag_star(self.first)
def star_second(self):
hashtag_star(self.second)
def star_third(self):
hashtag_star(self.third)
def star_fourth(self):
hashtag_star(self.fourth)
def star_fifth(self):
hashtag_star(self.fifth)
def setup():
B = words("#####","# #","#####","# #","#####")
U = words("# #","# #","# #","# #"," ### ")
N = words("# #","## #","# # #","# ##","# #")
G = words(" ####","# ","# ###","# #","#####")
letter = [B,U,N,G]
word = input("")
draw_word(letter,word)
def draw_word(letter,word):
i_print = 0
while(i_print < 5):
i = 0
while(i < len(word)):
if(word[i] == "B"):
fun_print(letter,i_print,0)
elif(word[i] == "L"):
fun_print(letter,i_print,1)
elif(word[i] == "U"):
fun_print(letter,i_print,2)
elif(word[i] == "E"):
fun_print(letter,i_print,3)
i = i + 1
print()
i_print = i_print + 1
def hashtag_star(temp):
i = 0
while(i < len(temp)):
if(temp[i] == "#"):
print("*",end = "")
else:
print(" ",end = "")
i = i + 1
def fun_print(letter,i_print,word_index):
if(i_print == 0):
letter[word_index].star_first()
elif(i_print == 1):
letter[word_index].star_second()
elif(i_print == 2):
letter[word_index].star_third()
elif(i_print == 3):
letter[word_index].star_fourth()
elif(i_print == 4):
letter[word_index].star_fifth()
setup()
[LAB7] AGE #INSERT-SORT
class DataStudents:
def __init__(self,name,sID,ages,heights,weights):
self.name = name
self.sID = sID
self.age = ages
self.height = heights
self.weight = weights
def get_age(self):
return self.age
def get_name(self):
return self.name
def setup():
nop = DataStudents("Nop",20046,28,173,52)
pee = DataStudents("Pee",20054,35,176,78)
fern = DataStudents("Fern",20097,26,174,58)
Recond = [nop,pee,fern]
#average_age(Recond)
#less_than_30(Recond)
sort(Recond)
def average_age(Recond):
i = 0
total = 0
a = 0
while(i < len(Recond)):
total = total + Recond[i].get_age()
i = i + 1
a = total / len(Recond)
print("%.2f"%a)
def less_than_30(Recond):
i = 0
while(i < len(Recond)):
if(Recond[i].get_age() < 30):
print(Recond[i].get_name())
print(Recond[i].get_age())
i = i + 1
def sort(Recond):
i = 0
j = 1
charge = 0
min_age = 0
while(i < len(Recond)):
min_age = Recond[i].get_age()
while(j < len(Recond)):
if(min_age > Recond[j].get_age()):
charge = min_age
min_age = Recond[j].get_age()
Recond[j].get_age() = charge
j = j + 1
print(Recond[i].get_name())
print(Recond[i].get_age())
print()
i = i + 1
setup()
def __init__(self,name,sID,ages,heights,weights):
self.name = name
self.sID = sID
self.age = ages
self.height = heights
self.weight = weights
def get_age(self):
return self.age
def get_name(self):
return self.name
def setup():
nop = DataStudents("Nop",20046,28,173,52)
pee = DataStudents("Pee",20054,35,176,78)
fern = DataStudents("Fern",20097,26,174,58)
Recond = [nop,pee,fern]
#average_age(Recond)
#less_than_30(Recond)
sort(Recond)
def average_age(Recond):
i = 0
total = 0
a = 0
while(i < len(Recond)):
total = total + Recond[i].get_age()
i = i + 1
a = total / len(Recond)
print("%.2f"%a)
def less_than_30(Recond):
i = 0
while(i < len(Recond)):
if(Recond[i].get_age() < 30):
print(Recond[i].get_name())
print(Recond[i].get_age())
i = i + 1
def sort(Recond):
i = 0
j = 1
charge = 0
min_age = 0
while(i < len(Recond)):
min_age = Recond[i].get_age()
while(j < len(Recond)):
if(min_age > Recond[j].get_age()):
charge = min_age
min_age = Recond[j].get_age()
Recond[j].get_age() = charge
j = j + 1
print(Recond[i].get_name())
print(Recond[i].get_age())
print()
i = i + 1
setup()
[LAB7] BMI
class DataStudents:
def __init__(self,name,sID,ages,heights,weights):
self.name = name
self.sID = sID
self.age = ages
self.height = heights
self.weight = weights
def get_name(self):
return self.name
def get_height(self):
return self.height
def get_weight(self):
return self.weight
def setup():
nop = DataStudents("Nop",20046,28,173,52)
pee = DataStudents("Pee",20054,35,176,78)
fern = DataStudents("Fern",20097,26,174,58)
Recond = [nop,pee,fern]
find_BMI_more_than_25(Recond)
def find_BMI_more_than_25(Recond):
i = 0
BMI = 0
while(i < len(Recond)):
BMI = Recond[i].get_weight()/((Recond[i].get_height()/100) * (Recond[i].get_height()/100))
if(BMI > 25):
print(Recond[i].get_name())
print("%.2f"%BMI)
i = i + 1
setup()
def __init__(self,name,sID,ages,heights,weights):
self.name = name
self.sID = sID
self.age = ages
self.height = heights
self.weight = weights
def get_name(self):
return self.name
def get_height(self):
return self.height
def get_weight(self):
return self.weight
def setup():
nop = DataStudents("Nop",20046,28,173,52)
pee = DataStudents("Pee",20054,35,176,78)
fern = DataStudents("Fern",20097,26,174,58)
Recond = [nop,pee,fern]
find_BMI_more_than_25(Recond)
def find_BMI_more_than_25(Recond):
i = 0
BMI = 0
while(i < len(Recond)):
BMI = Recond[i].get_weight()/((Recond[i].get_height()/100) * (Recond[i].get_height()/100))
if(BMI > 25):
print(Recond[i].get_name())
print("%.2f"%BMI)
i = i + 1
setup()
[LAB7] Data Student
class DataStudents:
def __init__(self,name,sID,ages,heights,weights):
self.name = name
self.sID = sID
self.age = ages
self.height = heights
self.weight = weights
def display(self):
print(self.name)
print(self.sID)
print(self.age)
print(self.height)
print(self.weight)
def setup():
nop = DataStudents("Nop",20046,28,173,52)
pee = DataStudents("Pee",20054,35,176,67)
fern = DataStudents("Fern",20097,26,174,58)
nop.display()
print()
pee.display()
print()
fern.display()
print()
setup()
def __init__(self,name,sID,ages,heights,weights):
self.name = name
self.sID = sID
self.age = ages
self.height = heights
self.weight = weights
def display(self):
print(self.name)
print(self.sID)
print(self.age)
print(self.height)
print(self.weight)
def setup():
nop = DataStudents("Nop",20046,28,173,52)
pee = DataStudents("Pee",20054,35,176,67)
fern = DataStudents("Fern",20097,26,174,58)
nop.display()
print()
pee.display()
print()
fern.display()
print()
setup()
วันอาทิตย์ที่ 25 ตุลาคม พ.ศ. 2558
[LAB6] Large Letter #2D_Array
def setup():
my_word = input("")
draw_word(my_word)
def draw_word(my_word):
B_line0 = "##### "
B_line1 = "# #"
B_line2 = "##### "
B_line3 = "# #"
B_line4 = "##### "
word_B = [B_line0,B_line1,B_line2,B_line3,B_line4]
U_line0 = "# #"
U_line1 = "# #"
U_line2 = "# #"
U_line3 = "# #"
U_line4 = " #### "
word_U = [U_line0,U_line1,U_line2,U_line3,U_line4]
N_line0 = "# #"
N_line1 = "## #"
N_line2 = "# # #"
N_line3 = "# ##"
N_line4 = "# #"
word_N = [N_line0,B_line1,N_line2,N_line3,N_line4]
G_line0 = " #### "
G_line1 = "# "
G_line2 = "# ### "
G_line3 = "# #"
G_line4 = "##### "
word_G = [G_line0,G_line1,G_line2,G_line3,G_line4]
i_print = 0
while(i_print < len(word_G)):
i = 0
while(i < len(my_word)):
if(my_word[i] == "B"):
print(word_B[i_print],end = " ")
elif(my_word[i] == "U"):
print(word_U[i_print],end = " ")
elif(my_word[i] == "N"):
print(word_N[i_print],end = " ")
elif(my_word[i] == "G"):
print(word_G[i_print],end = " ")
i = i + 1
print("")
i_print = i_print + 1
setup()
my_word = input("")
draw_word(my_word)
def draw_word(my_word):
B_line0 = "##### "
B_line1 = "# #"
B_line2 = "##### "
B_line3 = "# #"
B_line4 = "##### "
word_B = [B_line0,B_line1,B_line2,B_line3,B_line4]
U_line0 = "# #"
U_line1 = "# #"
U_line2 = "# #"
U_line3 = "# #"
U_line4 = " #### "
word_U = [U_line0,U_line1,U_line2,U_line3,U_line4]
N_line0 = "# #"
N_line1 = "## #"
N_line2 = "# # #"
N_line3 = "# ##"
N_line4 = "# #"
word_N = [N_line0,B_line1,N_line2,N_line3,N_line4]
G_line0 = " #### "
G_line1 = "# "
G_line2 = "# ### "
G_line3 = "# #"
G_line4 = "##### "
word_G = [G_line0,G_line1,G_line2,G_line3,G_line4]
i_print = 0
while(i_print < len(word_G)):
i = 0
while(i < len(my_word)):
if(my_word[i] == "B"):
print(word_B[i_print],end = " ")
elif(my_word[i] == "U"):
print(word_U[i_print],end = " ")
elif(my_word[i] == "N"):
print(word_N[i_print],end = " ")
elif(my_word[i] == "G"):
print(word_G[i_print],end = " ")
i = i + 1
print("")
i_print = i_print + 1
setup()
[LAB6] Matrix(+Transpose) #2D_Array
def setup():
first1 = [1, 2, 3]
second1 = [2, 4, 6]
third1 = [3, 5, 7]
maxtrix1 = [first1,second1,third1]
third2 = [1, 2, 3]
first2 = [2, 3, 6]
second2 = [3, 5, 7]
maxtrix2 = [first2,second2,third2]
display(maxtrix1)
display(maxtrix2)
#add(maxtrix1,maxtrix2)
#sub(maxtrix1,maxtrix2)
#multi(maxtrix1,maxtrix2)
print("///// Transpose /////")
tran(maxtrix1)
#display(maxtrix1)
def display(maxtrix1):
h = 0
while(h < len(maxtrix1)):
v = 0
print(end = "")
while(v < len(maxtrix1[h])):
print("",maxtrix1[h][v],"", end = "")
v = v + 1
print("")
h = h + 1
print("")
def add(maxtrix1,maxtrix2):
h = 0
while(h < len(maxtrix1)):
v = 0
print(end = "")
while(v < len(maxtrix1[h])):
print("",maxtrix1[h][v]+maxtrix2[h][v],"",end = "")
v = v + 1
print("")
h = h + 1
def sub(maxtrix1,maxtrix2):
h = 0
while(h < len(maxtrix1)):
v = 0
print(end = "")
while(v < len(maxtrix1[h])):
print("",maxtrix1[h][v]-maxtrix2[h][v],"",end = "")
v = v + 1
print("")
h = h + 1
def multi(maxtrix1,maxtrix2):
h = 0
while(h < len(maxtrix1)):
v = 0
print(end = "")
while(v < len(maxtrix1[h])):
print("",maxtrix1[h][v]*maxtrix2[h][v],"",end = "")
v = v + 1
print("")
h = h + 1
def tran(maxtrix1):
h = 0
while(h < len(maxtrix1)):
v = h
while(v < len(maxtrix1[h])):
charge = maxtrix1[h][v]
maxtrix1[h][v] = maxtrix1[v][h]
maxtrix1[v][h] = charge
v = v + 1
h = h + 1
setup()
first1 = [1, 2, 3]
second1 = [2, 4, 6]
third1 = [3, 5, 7]
maxtrix1 = [first1,second1,third1]
third2 = [1, 2, 3]
first2 = [2, 3, 6]
second2 = [3, 5, 7]
maxtrix2 = [first2,second2,third2]
display(maxtrix1)
display(maxtrix2)
#add(maxtrix1,maxtrix2)
#sub(maxtrix1,maxtrix2)
#multi(maxtrix1,maxtrix2)
print("///// Transpose /////")
tran(maxtrix1)
#display(maxtrix1)
def display(maxtrix1):
h = 0
while(h < len(maxtrix1)):
v = 0
print(end = "")
while(v < len(maxtrix1[h])):
print("",maxtrix1[h][v],"", end = "")
v = v + 1
print("")
h = h + 1
print("")
def add(maxtrix1,maxtrix2):
h = 0
while(h < len(maxtrix1)):
v = 0
print(end = "")
while(v < len(maxtrix1[h])):
print("",maxtrix1[h][v]+maxtrix2[h][v],"",end = "")
v = v + 1
print("")
h = h + 1
def sub(maxtrix1,maxtrix2):
h = 0
while(h < len(maxtrix1)):
v = 0
print(end = "")
while(v < len(maxtrix1[h])):
print("",maxtrix1[h][v]-maxtrix2[h][v],"",end = "")
v = v + 1
print("")
h = h + 1
def multi(maxtrix1,maxtrix2):
h = 0
while(h < len(maxtrix1)):
v = 0
print(end = "")
while(v < len(maxtrix1[h])):
print("",maxtrix1[h][v]*maxtrix2[h][v],"",end = "")
v = v + 1
print("")
h = h + 1
def tran(maxtrix1):
h = 0
while(h < len(maxtrix1)):
v = h
while(v < len(maxtrix1[h])):
charge = maxtrix1[h][v]
maxtrix1[h][v] = maxtrix1[v][h]
maxtrix1[v][h] = charge
v = v + 1
h = h + 1
setup()
[LAB6] Classroom #2D_Array
def setup():
first_floors = [26, 32, 18, 17]
second_floors = [16, 15, 24, 31]
third_floors = [19, 26, 21, 30]
buildings = [first_floors,second_floors,third_floors]
#total_chairs(buildings)
#find_max_floor(buildings)
find_max_room(buildings)
def total_chairs(buildings):
i = 0
total = 0
while(i < len(buildings)):
choose = 0
while(choose < len(buildings[i])):
total = total + buildings[i][choose]
choose = choose + 1
i = i + 1
print(total)
def find_max_floor(buildings):
i = 0
max_floor = 0
total = 0
ref = 0
while(i < len(buildings)):
choose = 0
while(choose < len(buildings[i])):
total = total + buildings[i][choose]
choose = choose + 1
if(total > ref):
ref = total
max_floor = i
i = i + 1
print(max_floor)
def find_max_room(buildings):
i = 0
ref = buildings[0][0]
while(i < len(buildings)):
choose = 0
while(choose < len(buildings[i])):
if(buildings[i][choose] > ref):
ref = buildings[i][choose]
choose = choose + 1
i = i + 1
i = 0
while(i < len(buildings)):
choose = 0
while(choose < len(buildings[i])):
if(ref == buildings[i][choose]):
print("[",i,"][",choose,"]")
choose = choose + 1
i = i + 1
setup()
first_floors = [26, 32, 18, 17]
second_floors = [16, 15, 24, 31]
third_floors = [19, 26, 21, 30]
buildings = [first_floors,second_floors,third_floors]
#total_chairs(buildings)
#find_max_floor(buildings)
find_max_room(buildings)
def total_chairs(buildings):
i = 0
total = 0
while(i < len(buildings)):
choose = 0
while(choose < len(buildings[i])):
total = total + buildings[i][choose]
choose = choose + 1
i = i + 1
print(total)
def find_max_floor(buildings):
i = 0
max_floor = 0
total = 0
ref = 0
while(i < len(buildings)):
choose = 0
while(choose < len(buildings[i])):
total = total + buildings[i][choose]
choose = choose + 1
if(total > ref):
ref = total
max_floor = i
i = i + 1
print(max_floor)
def find_max_room(buildings):
i = 0
ref = buildings[0][0]
while(i < len(buildings)):
choose = 0
while(choose < len(buildings[i])):
if(buildings[i][choose] > ref):
ref = buildings[i][choose]
choose = choose + 1
i = i + 1
i = 0
while(i < len(buildings)):
choose = 0
while(choose < len(buildings[i])):
if(ref == buildings[i][choose]):
print("[",i,"][",choose,"]")
choose = choose + 1
i = i + 1
setup()
[LAB6] WEIGHT data
def setup():
names = [ "art", "bird", "cat"]
student_id = [ 22, 24,17]
ages = [ 30, 21, 17]
weights = [ 72, 53, 49]
heights = [ 168, 169, 181]
#min_weight(names,weights)
count_weight50down(names,weights)
def min_weight(names,weights):
i = 0
min_w = weights[i]
min_n = 0
while(i < len(weights)):
if(min_w > weights[i]):
min_w = weights[i]
min_n = names[i]
i = i + 1
print(min_n)
print(min_w)
def count_weight50down(names,weights):
i = 0
count = 0
while(i < len(weights)):
if(weights[i] < 50):
count = count + 1
print(names[i])
print("Weights =",weights[i])
i = i + 1
#print("count_weight50down ="count)
setup()
names = [ "art", "bird", "cat"]
student_id = [ 22, 24,17]
ages = [ 30, 21, 17]
weights = [ 72, 53, 49]
heights = [ 168, 169, 181]
#min_weight(names,weights)
count_weight50down(names,weights)
def min_weight(names,weights):
i = 0
min_w = weights[i]
min_n = 0
while(i < len(weights)):
if(min_w > weights[i]):
min_w = weights[i]
min_n = names[i]
i = i + 1
print(min_n)
print(min_w)
def count_weight50down(names,weights):
i = 0
count = 0
while(i < len(weights)):
if(weights[i] < 50):
count = count + 1
print(names[i])
print("Weights =",weights[i])
i = i + 1
#print("count_weight50down ="count)
setup()
[LAB6] AGE (+insertion sort)
def setup():
names = [ "art", "bird", "cat"]
student_id = [ 22, 24,17]
ages = [ 30, 21, 17]
weights = [ 72, 53, 51]
heights = [ 168, 169, 181]
#average_age(ages)
#age30down(names,ages)
sort(names,ages)
def average_age(ages):
i = 0
total = 0
a = 0
while(i < len(ages)):
total = total + ages[i]
i = i + 1
a = total / len(ages)
print("average =","%.2f"%a)
def age30down(names,ages):
i = 0
while(i < len(names)):
if(ages[i] < 30):
print(names[i])
print("age =",ages[i])
i = i + 1
def sort(names,ages):
i = 0
j = 1
charge = 0
min_age = 0
while(i < len(ages)):
min_age = ages[i]
while(j < len(ages)):
if(min_age > ages[j]):
charge = min_age
min_age = ages[j]
ages[j] = charge
j = j + 1
print(names[i])
print(ages[i])
print("")
i = i + 1
setup()
names = [ "art", "bird", "cat"]
student_id = [ 22, 24,17]
ages = [ 30, 21, 17]
weights = [ 72, 53, 51]
heights = [ 168, 169, 181]
#average_age(ages)
#age30down(names,ages)
sort(names,ages)
def average_age(ages):
i = 0
total = 0
a = 0
while(i < len(ages)):
total = total + ages[i]
i = i + 1
a = total / len(ages)
print("average =","%.2f"%a)
def age30down(names,ages):
i = 0
while(i < len(names)):
if(ages[i] < 30):
print(names[i])
print("age =",ages[i])
i = i + 1
def sort(names,ages):
i = 0
j = 1
charge = 0
min_age = 0
while(i < len(ages)):
min_age = ages[i]
while(j < len(ages)):
if(min_age > ages[j]):
charge = min_age
min_age = ages[j]
ages[j] = charge
j = j + 1
print(names[i])
print(ages[i])
print("")
i = i + 1
setup()
[LAB6] BMI data
def setup():
names = [ "art", "bird", "cat"]
student_id = [ 22, 24,17]
ages = [ 17, 18, 19]
weights = [ 72, 53, 51]
heights = [ 168, 169, 181]
BMI(names, weights, heights)
def BMI(names, weights, heights):
i = 0
count = 0
while(i < len(names)):
BMI = weights[i]/((heights[i]/100) * (heights[i]/100))
#print(names[i],"BMI =","%.2f"%BMI)
if(BMI > 25):
count = count + 1
print("count_bmi25up =",count)
print(names[i])
print("weight", weights[i])
print("height", heights[i])
print("BMI =", "%.2f"%BMI)
i = i + 1
setup()
names = [ "art", "bird", "cat"]
student_id = [ 22, 24,17]
ages = [ 17, 18, 19]
weights = [ 72, 53, 51]
heights = [ 168, 169, 181]
BMI(names, weights, heights)
def BMI(names, weights, heights):
i = 0
count = 0
while(i < len(names)):
BMI = weights[i]/((heights[i]/100) * (heights[i]/100))
#print(names[i],"BMI =","%.2f"%BMI)
if(BMI > 25):
count = count + 1
print("count_bmi25up =",count)
print(names[i])
print("weight", weights[i])
print("height", heights[i])
print("BMI =", "%.2f"%BMI)
i = i + 1
setup()
[LAB6] Display student records (data)
def setup():
names = [ "art", "bird", "cat"]
student_id = [ 22, 24,17]
ages = [ 17, 18, 19]
weights = [ 48, 53, 51]
heights = [ 174, 168, 181]
show_student(names,student_id,ages,weights,heights)
def show_student(names,student_id,ages,weights,heights):
i = 0
while(i < len(names)):
print("Name :",names[i])
print("Id :",student_id[i])
print("Age :",ages[i])
print("Weight :",weights[i])
print("Height :",heights[i])
print()
i = i + 1
setup()
names = [ "art", "bird", "cat"]
student_id = [ 22, 24,17]
ages = [ 17, 18, 19]
weights = [ 48, 53, 51]
heights = [ 174, 168, 181]
show_student(names,student_id,ages,weights,heights)
def show_student(names,student_id,ages,weights,heights):
i = 0
while(i < len(names)):
print("Name :",names[i])
print("Id :",student_id[i])
print("Age :",ages[i])
print("Weight :",weights[i])
print("Height :",heights[i])
print()
i = i + 1
setup()
วันอาทิตย์ที่ 4 ตุลาคม พ.ศ. 2558
[LAB5] my_endswith()
def my_endswith():
my_endswith = 'Thailand'
check = False
word = 'and'
first_index = len(word)-1
second_index = len(my_endswith)-1
count = 0
k = 0
if(len(my_endswith) >= len(word)):
while(k < len(word)):
if(word[first_index] == my_endswith[second_index]):
count = count +1
first_index = first_index - 1
second_index = second_index - 1
k = k + 1
if(count != 0 and count%len(word) == 0):
check = True
return check
print(my_endswith())
my_endswith = 'Thailand'
check = False
word = 'and'
first_index = len(word)-1
second_index = len(my_endswith)-1
count = 0
k = 0
if(len(my_endswith) >= len(word)):
while(k < len(word)):
if(word[first_index] == my_endswith[second_index]):
count = count +1
first_index = first_index - 1
second_index = second_index - 1
k = k + 1
if(count != 0 and count%len(word) == 0):
check = True
return check
print(my_endswith())
[LAB5] my_startswith()
def my_statswith():
my_startswith = 'Thailand'
check = True
word = 'Sun'
count = 0
if(len(my_startswith) > len(word)):
while(count < len(word)):
if(my_startswith[count] == word[count]):
check = True
else:
check = False
count = count + 1
return check
print(my_statswith())
my_startswith = 'Thailand'
check = True
word = 'Sun'
count = 0
if(len(my_startswith) > len(word)):
while(count < len(word)):
if(my_startswith[count] == word[count]):
check = True
else:
check = False
count = count + 1
return check
print(my_statswith())
[LAB5] my_replace()
def my_place1():
my_place1 = "Thai"
return my_place1
def my_place2():
my_place2 = "land"
return my_place2
def my_place():
return my_place1() + my_place2()
def my_replace():
my_replace = "thai"
return my_place1() + my_replace
print(my_place())
print(my_replace())
[LAB5] my_find()
def my_find():
my_find = "Thailand"
count = 0
index = count
while(count < len(my_find)):
if(my_find[count] == "i"):
index = count
count = count + 1
return index
print(my_find())
my_find = "Thailand"
count = 0
index = count
while(count < len(my_find)):
if(my_find[count] == "i"):
index = count
count = count + 1
return index
print(my_find())
[LAB5] my_count()
def my_count():
my_count = "Thailand"
count = 0
unit = count
while(count < len(my_count)):
if(my_count[count] == "a"):
unit = unit + 1
count = count + 1
return unit
print(my_count())
my_count = "Thailand"
count = 0
unit = count
while(count < len(my_count)):
if(my_count[count] == "a"):
unit = unit + 1
count = count + 1
return unit
print(my_count())
[LAB5] Convert Base 10 --> Base 2
def convertBase2(number,base):
convert = "0123456789"
if number < base:
return convert[number]
else:
return convertBase2(number//base,base) + convert[number%base]
print(convertBase2(10,2))
convert = "0123456789"
if number < base:
return convert[number]
else:
return convertBase2(number//base,base) + convert[number%base]
print(convertBase2(10,2))
วันศุกร์ที่ 2 ตุลาคม พ.ศ. 2558
[LAB5] my_strip()
def my_strip():
my_strip = 'Thailand '
current = ' '
my_newstrip = ''
count = 0
while(count < len(my_strip)):
if(count < len(current)):
my_newstrip = my_newstrip + my_strip[count]
count = count + 1
return my_newstrip
print(my_strip())
my_strip = 'Thailand '
current = ' '
my_newstrip = ''
count = 0
while(count < len(my_strip)):
if(count < len(current)):
my_newstrip = my_newstrip + my_strip[count]
count = count + 1
return my_newstrip
print(my_strip())
[LAB5-Draft] INC/DEC VALUE (Fixed value)
def update_value(number):
count = 0
update = 5
while(count < len(number)):
number[count] = number[count] + update
count = count + 1
return number
def setup():
number = [2,10,5,6,1]
print(update_value(number))
setup()
count = 0
update = 5
while(count < len(number)):
number[count] = number[count] + update
count = count + 1
return number
def setup():
number = [2,10,5,6,1]
print(update_value(number))
setup()
วันอังคารที่ 22 กันยายน พ.ศ. 2558
[LAB5-Draft] Average of value in array
def sum_of_value(value):
count = 0
sum = 0
while(count < len(value)):
if(value[count] >= 0):
sum = sum + value[count]
count = count + 1
return sum
def average(value):
average = sum_of_value(value) / len(value)
return average
def setup():
value = [23,25,25,23]
print(average(value))
setup()
count = 0
sum = 0
while(count < len(value)):
if(value[count] >= 0):
sum = sum + value[count]
count = count + 1
return sum
def average(value):
average = sum_of_value(value) / len(value)
return average
def setup():
value = [23,25,25,23]
print(average(value))
setup()
[LAB5-Draft] Find of positive value
def show_positive_value(value):
count = 0
posNumber = 0
while(count < len(value)):
if(value[count] >= 0):
posNumber = value[count]
print(posNumber)
count = count + 1
return posNumber
def setup():
value = [1,-2,3,4,-5]
show_positive_value(value)
setup()
count = 0
posNumber = 0
while(count < len(value)):
if(value[count] >= 0):
posNumber = value[count]
print(posNumber)
count = count + 1
return posNumber
def setup():
value = [1,-2,3,4,-5]
show_positive_value(value)
setup()
[LAB5-Draft] Sum of value (Positive)
def sum_of_value(value):
count = 0
sum = 0
while(count < len(value)):
if(value[count] >= 0):
sum = sum + value[count]
count = count + 1
return sum
def setup():
value = [1,2,3,-4,-5]
print(sum_of_value(value))
setup()
count = 0
sum = 0
while(count < len(value)):
if(value[count] >= 0):
sum = sum + value[count]
count = count + 1
return sum
def setup():
value = [1,2,3,-4,-5]
print(sum_of_value(value))
setup()
[LAB5-Draft] Sum of value in array
def sum_of_value(value):
count = 0
sum = 0
while(count < len(value)):
sum = sum + value[count]
count = count + 1
return sum
def setup():
value = [1,2,3,4,5]
print(sum_of_value(value))
setup()
count = 0
sum = 0
while(count < len(value)):
sum = sum + value[count]
count = count + 1
return sum
def setup():
value = [1,2,3,4,5]
print(sum_of_value(value))
setup()
[LAB5-Draft] MAXVALUE (LAST)
def find_max_value_index(number):
count = 0
Max_Value = 0
Index_Value = 0
while(count < len(number)):
if(number[count] > Max_Value):
Max_Value = number[count]
if(number[count] == Max_Value):
Index_Value = count
count = count + 1
return Index_Value
def setup():
number = [-2,6,5,6,3,-5,8,3,5,8]
print(find_max_value_index(number))
setup()
count = 0
Max_Value = 0
Index_Value = 0
while(count < len(number)):
if(number[count] > Max_Value):
Max_Value = number[count]
if(number[count] == Max_Value):
Index_Value = count
count = count + 1
return Index_Value
def setup():
number = [-2,6,5,6,3,-5,8,3,5,8]
print(find_max_value_index(number))
setup()
[LAB5-Draft] MAXVALUE (FIRST)
def find_max_value_index(number):
count = 0
Max_Value = 0
Index_Value = 0
while(count < len(number)):
if(number[count] > Max_Value):
Max_Value = number[count]
#if(number[count] == Max_Value):
Index_Value = count
count = count + 1
return Index_Value
def setup():
number = [-2,6,5,6,3,-5,8,3,5,8]
print(find_max_value_index(number))
setup()
count = 0
Max_Value = 0
Index_Value = 0
while(count < len(number)):
if(number[count] > Max_Value):
Max_Value = number[count]
#if(number[count] == Max_Value):
Index_Value = count
count = count + 1
return Index_Value
def setup():
number = [-2,6,5,6,3,-5,8,3,5,8]
print(find_max_value_index(number))
setup()
[LAB5-Draft] MAXVALUE
def find_max_value(number):
count = 0
Max_Value = 0
while(count < len(number)):
if(number[count] > Max_Value):
Max_Value = number[count]
count = count + 1
return Max_Value
def setup():
number = [6,5,5,6,5]
print(find_max_value(number))
setup()
count = 0
Max_Value = 0
while(count < len(number)):
if(number[count] > Max_Value):
Max_Value = number[count]
count = count + 1
return Max_Value
def setup():
number = [6,5,5,6,5]
print(find_max_value(number))
setup()
[LAB5-Draft] Display element of array and index
def setup():
n = [5,8,7,5,3,2,9]
print(n)
print("First =",n[0])
print("Second =",n[1])
print("Third =",n[2])
print("Fourth =",n[3])
print("Fifth =",n[4])
print("sixth =",n[5])
print("seventh =",n[6])
setup()
n = [5,8,7,5,3,2,9]
print(n)
print("First =",n[0])
print("Second =",n[1])
print("Third =",n[2])
print("Fourth =",n[3])
print("Fifth =",n[4])
print("sixth =",n[5])
print("seventh =",n[6])
setup()
วันเสาร์ที่ 19 กันยายน พ.ศ. 2558
[LAB4X] Sum of integers
def setup():
display()
def display():
countNumber = 1
ansNumber = 0
maxNumber = 3
while(countNumber <= maxNumber):
ansNumber += countNumber
print("+",countNumber," = ",ansNumber)
countNumber = countNumber + 1
setup()
display()
def display():
countNumber = 1
ansNumber = 0
maxNumber = 3
while(countNumber <= maxNumber):
ansNumber += countNumber
print("+",countNumber," = ",ansNumber)
countNumber = countNumber + 1
setup()
[LAB4X] GRADE
def setup():
valScore = 87
if(valScore >= 80):
print("Grade A")
elif(valScore >= 70):
print("Grade B")
elif(valScore >= 60):
print("Grade C")
elif(valScore >= 50):
print("Grade D")
else:
print("Grade F")
setup()
valScore = 87
if(valScore >= 80):
print("Grade A")
elif(valScore >= 70):
print("Grade B")
elif(valScore >= 60):
print("Grade C")
elif(valScore >= 50):
print("Grade D")
else:
print("Grade F")
setup()
[LAB4X] BMI
def setup():
weight = 50.0
height_CM = 180.0
height_M = 0.0
main_height = 0.0
bmi = 0.0
height_M = height_CM / 100.00
main_height = height_M * height_M
bmi = weight / main_height
print (weight)
print (height_CM)
print (height_M)
print (bmi)
setup()
weight = 50.0
height_CM = 180.0
height_M = 0.0
main_height = 0.0
bmi = 0.0
height_M = height_CM / 100.00
main_height = height_M * height_M
bmi = weight / main_height
print (weight)
print (height_CM)
print (height_M)
print (bmi)
setup()
[LAB4X] Sum of prime number
def setup():
display_sum_prime()
def display_sum_prime():
countNumber = 0
primeNumber = countNumber
maxNumber = 9
sumNumber = 0
while(primeNumber <= maxNumber):
if(check_primeNumber(primeNumber)):
sumNumber += primeNumber
print("+",primeNumber," = ",sumNumber)
primeNumber = primeNumber + 1
def check_primeNumber(maxNumber):
start = 2
while(start <= maxNumber):
if(start == maxNumber):
return True
if(maxNumber%start == 0):
return False
start = start + 1
return False
setup()
display_sum_prime()
def display_sum_prime():
countNumber = 0
primeNumber = countNumber
maxNumber = 9
sumNumber = 0
while(primeNumber <= maxNumber):
if(check_primeNumber(primeNumber)):
sumNumber += primeNumber
print("+",primeNumber," = ",sumNumber)
primeNumber = primeNumber + 1
def check_primeNumber(maxNumber):
start = 2
while(start <= maxNumber):
if(start == maxNumber):
return True
if(maxNumber%start == 0):
return False
start = start + 1
return False
setup()
[LAB4X] Multi-table
def setup():
display_multitable(4)
def display_multitable(myNumber):
startCount = 1
limitCount = 12
ansNumber = 0
while(startCount <= limitCount):
ansNumber = myNumber * startCount
print(myNumber," X ",startCount," = ",ansNumber)
startCount = startCount + 1
setup()
display_multitable(4)
def display_multitable(myNumber):
startCount = 1
limitCount = 12
ansNumber = 0
while(startCount <= limitCount):
ansNumber = myNumber * startCount
print(myNumber," X ",startCount," = ",ansNumber)
startCount = startCount + 1
setup()
[LAB4X] Calculate circumference and area of a circle
import math
def setup():
rad = 7
cir = 0
cir = 2 * math.pi * rad
A = math.pi * rad * rad
print(rad)
print(cir)
print(A)
setup()
def setup():
rad = 7
cir = 0
cir = 2 * math.pi * rad
A = math.pi * rad * rad
print(rad)
print(cir)
print(A)
setup()
วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558
[LAB 4] SYNTAX ERROR
1.
ERROR!
ERROR!
- This method must return a resuly of type boolean
Cause of Problem
- ลืมกำหนดค่า Return type boolean
FIXED
- ใส่ค่า Return (Boolean)
2.
ERROR!
- Found one too many { character withotua } to match it.
Cause of Problem
- ลืมใส่วง {} อีกขั้นหนึ่ง
FIXED
- ใส่วง {} ให้ถูกต้องงงง
- ใส่วง {} ให้ถูกต้องงงง
[LAB 4] Loan payment
void setup()
{
size(600,700);
loan_Payment(1);
}
float loan_Payment(int year)
{
background(0);
int mouth = year*12;
float money = 5000;
float percent = 0.12/mouth;
float interest = percent * money;
float principal = 0;
float total_Interest = 0;
int startMouth = 1;
float remain_money = money;
float remain_principal ;
text("NO"+" "+"Interest"+" "+"Principal"+" "+"Unpaid Balance"+" "+"total interest to date",width/6,height/14);
principal = money * (percent/(1-pow(1+percent,-mouth))) ;
remain_principal = principal;
while(startMouth <= mouth)
{
total_Interest += interest ;
remain_principal = principal - interest ;
remain_money -= remain_principal ;
interest = remain_money * percent ;
text(nf(startMouth,2)+" "+nf(interest,2,2)+" "+nf(remain_principal,3,2)+" "+nf(remain_money,4,2)+" "+nf(total_Interest,3,2),width/6,(startMouth*50)+height/14);
startMouth++;
}
if(remain_money <= 0)
{
remain_money = 0;
}
return total_Interest;
}
{
size(600,700);
loan_Payment(1);
}
float loan_Payment(int year)
{
background(0);
int mouth = year*12;
float money = 5000;
float percent = 0.12/mouth;
float interest = percent * money;
float principal = 0;
float total_Interest = 0;
int startMouth = 1;
float remain_money = money;
float remain_principal ;
text("NO"+" "+"Interest"+" "+"Principal"+" "+"Unpaid Balance"+" "+"total interest to date",width/6,height/14);
principal = money * (percent/(1-pow(1+percent,-mouth))) ;
remain_principal = principal;
while(startMouth <= mouth)
{
total_Interest += interest ;
remain_principal = principal - interest ;
remain_money -= remain_principal ;
interest = remain_money * percent ;
text(nf(startMouth,2)+" "+nf(interest,2,2)+" "+nf(remain_principal,3,2)+" "+nf(remain_money,4,2)+" "+nf(total_Interest,3,2),width/6,(startMouth*50)+height/14);
startMouth++;
}
if(remain_money <= 0)
{
remain_money = 0;
}
return total_Interest;
}
[LAB 4] Sum of prime numbers (Use Boolean Function)
void setup()
{
size(500,500);
}
int countNumber = 0;
int maxNumber = 56;
int primeNumber = countNumber;
int count =0;
int sumNumber = 0;
void draw()
{
background(0);
while(primeNumber <= maxNumber)
{
if(check_primeNumber(primeNumber))
{
sumNumber += primeNumber;
}
primeNumber++;
}
textSize(25);
text(countNumber,width/4,height/4);
text(maxNumber,width/4,3*(height/4));
textSize(60);
text(sumNumber,3*(width/5),height/2);
}
boolean check_primeNumber(int maxNumber)
{
int start = 2;
while(start <= maxNumber)
{
if(start == maxNumber)
{
return true;
}
if(maxNumber%start == 0)
{
return false;
}
start++;
}
return false;
}
{
size(500,500);
}
int countNumber = 0;
int maxNumber = 56;
int primeNumber = countNumber;
int count =0;
int sumNumber = 0;
void draw()
{
background(0);
while(primeNumber <= maxNumber)
{
if(check_primeNumber(primeNumber))
{
sumNumber += primeNumber;
}
primeNumber++;
}
textSize(25);
text(countNumber,width/4,height/4);
text(maxNumber,width/4,3*(height/4));
textSize(60);
text(sumNumber,3*(width/5),height/2);
}
boolean check_primeNumber(int maxNumber)
{
int start = 2;
while(start <= maxNumber)
{
if(start == maxNumber)
{
return true;
}
if(maxNumber%start == 0)
{
return false;
}
start++;
}
return false;
}
[LAB 4] Display multiplication table
void setup()
{
size(500,700);
}
void draw()
{
background(0);
show_display();
}
void show_display()
{
int myNumber = 3;
int startCount = 1;
int maxCount = 12;
int ansNumber = 0;
while(startCount <= maxCount)
{
ansNumber = myNumber * startCount ;
text(myNumber+" X "+startCount+" = "+ansNumber,50,startCount*50);
startCount++;
}
}
{
size(500,700);
}
void draw()
{
background(0);
show_display();
}
void show_display()
{
int myNumber = 3;
int startCount = 1;
int maxCount = 12;
int ansNumber = 0;
while(startCount <= maxCount)
{
ansNumber = myNumber * startCount ;
text(myNumber+" X "+startCount+" = "+ansNumber,50,startCount*50);
startCount++;
}
}
[LAB 4] Calculate Sum of integers
void setup()
{
size(500,500);
frameRate(0.7);
}
void draw()
{
background(0);
display_Addition();
}
void display_Addition()
{
int countNumber = 1;
int ansNumber = 0;
int maxNumber = frameCount;
int text_plus = 3*(width/4);
while(countNumber <= maxNumber)
{
ansNumber += countNumber ;
countNumber++;
}
textSize(40);
text("+"+maxNumber,text_plus,text_plus);
text("ANSWER : "+ansNumber,width/4,height/2);
}
{
size(500,500);
frameRate(0.7);
}
void draw()
{
background(0);
display_Addition();
}
void display_Addition()
{
int countNumber = 1;
int ansNumber = 0;
int maxNumber = frameCount;
int text_plus = 3*(width/4);
while(countNumber <= maxNumber)
{
ansNumber += countNumber ;
countNumber++;
}
textSize(40);
text("+"+maxNumber,text_plus,text_plus);
text("ANSWER : "+ansNumber,width/4,height/2);
}
[LAB 4] METRO
void setup()
{
size(500,500);
frameRate(30);
}
void draw()
{
background(255);
float count = 1;
float moveX = 0;
float moveY = 0;
float picSize = 300;
while(count < 4)
{
moveX = mouseX+(count*140)-175;
moveY = random(50)+(count*90)-100;
draw_Logo(moveX ,moveY ,picSize );
count++;
}
}
void draw_Logo(float posX ,float posY ,float picSize )
{
float scale = picSize / 500 ;
strokeWeight(scale * 15);
noFill();
ellipse(scale * 250+posX,scale * 300+posY,scale * 100,scale * 100);
fill(255);
stroke(255);
rect(scale * 0+posX,scale * 249+posY,scale * 500,scale * 18);
stroke(0);
line(scale * 200+posX,scale * 230+posY,scale * 235+posX,scale * 180+posY); // MLeft
line(scale * 200+posX,scale * 230+posY,scale * 160+posX,scale * 175+posY);
line(scale * 159+posX,scale * 175+posY,scale * 159+posX,scale * 300+posY);
line(scale * 265+posX,scale * 180+posY,scale * 300+posX,scale * 230+posY); // MRight
line(scale * 300+posX,scale * 230+posY,scale * 340+posX,scale * 175+posY);
line(scale * 340+posX,scale * 175+posY,scale * 340+posX,scale * 300+posY);
stroke(#FF0000);
line(scale * 240+posX,scale * 300+posY,scale * 240+posX,scale * 100+posY); //line Left
line(scale * 260+posX,scale * 300+posY,scale * 260+posX,scale * 100+posY); //line Right
line(scale * 240+posX,scale * 100+posY,scale * 215+posX,scale * 80+posY); //Head
line(scale * 215+posX,scale * 80+posY,scale * 240+posX,scale * 50+posY);
strokeWeight(scale * 6);
point(scale * 230+posX,scale * 45+posY);
point(scale * 225+posX,scale * 50+posY);
point(scale * 221+posX,scale * 55+posY);
}
{
size(500,500);
frameRate(30);
}
void draw()
{
background(255);
float count = 1;
float moveX = 0;
float moveY = 0;
float picSize = 300;
while(count < 4)
{
moveX = mouseX+(count*140)-175;
moveY = random(50)+(count*90)-100;
draw_Logo(moveX ,moveY ,picSize );
count++;
}
}
void draw_Logo(float posX ,float posY ,float picSize )
{
float scale = picSize / 500 ;
strokeWeight(scale * 15);
noFill();
ellipse(scale * 250+posX,scale * 300+posY,scale * 100,scale * 100);
fill(255);
stroke(255);
rect(scale * 0+posX,scale * 249+posY,scale * 500,scale * 18);
stroke(0);
line(scale * 200+posX,scale * 230+posY,scale * 235+posX,scale * 180+posY); // MLeft
line(scale * 200+posX,scale * 230+posY,scale * 160+posX,scale * 175+posY);
line(scale * 159+posX,scale * 175+posY,scale * 159+posX,scale * 300+posY);
line(scale * 265+posX,scale * 180+posY,scale * 300+posX,scale * 230+posY); // MRight
line(scale * 300+posX,scale * 230+posY,scale * 340+posX,scale * 175+posY);
line(scale * 340+posX,scale * 175+posY,scale * 340+posX,scale * 300+posY);
stroke(#FF0000);
line(scale * 240+posX,scale * 300+posY,scale * 240+posX,scale * 100+posY); //line Left
line(scale * 260+posX,scale * 300+posY,scale * 260+posX,scale * 100+posY); //line Right
line(scale * 240+posX,scale * 100+posY,scale * 215+posX,scale * 80+posY); //Head
line(scale * 215+posX,scale * 80+posY,scale * 240+posX,scale * 50+posY);
strokeWeight(scale * 6);
point(scale * 230+posX,scale * 45+posY);
point(scale * 225+posX,scale * 50+posY);
point(scale * 221+posX,scale * 55+posY);
}
[LAB 4] PLAYBOY
void setup()
{
size(500,500);
frameRate(30);
}
void draw()
{
background(255);
int startCount = 0;
int endCount = 2;
int moveX = 0;
int moveY = 0;
float picSize = 200;
while(startCount <= endCount)
{
moveX = startCount*150;
draw_rabbit(moveX,moveY,picSize,random(255));
startCount++;
}
}
void draw_rabbit(int posX ,int posY ,float picSize , float random_color )
{
float scale = picSize / 500;
noStroke();
fill(random_color);
ellipse(scale * 270+posX,scale * 300+posY,scale * 250,scale * 180); //Face
ellipse(scale * 320+posX,scale * 430+posY,scale * 250,scale * 200); //Throat
//fill(255);
//triangle(scale * 500,scale * -750,scale * 500,scale * 500,scale * 350,scale * 500); //blockbackground
fill(random_color); //ribbon
stroke(255); //ribbon
strokeWeight(5); //ribbon
triangle(scale * 180+posX,scale * 480+posY,scale * 250+posX,scale * 440+posY,scale * 240+posX,scale * 500+posY); //ribbon
//line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 350+posY); //ribbon
//line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 390+posY); //ribbon
noStroke();
triangle(scale * 230+posX,scale * 480+posY,scale * 175+posX,scale * 450+posY,scale * 175+posX,scale * 490+posY); //ribbon
fill(255);
ellipse(scale * 240+posX,scale * 260+posY,scale * 50,scale * 50); //Eye
fill(random_color);
ellipse(scale * 360+posX,scale * 200+posY,scale * 50,scale * 300); //EarLeft
ellipse(scale * 320+posX,scale * 200+posY,scale * 50,scale * 300); //EarRight
}
{
size(500,500);
frameRate(30);
}
void draw()
{
background(255);
int startCount = 0;
int endCount = 2;
int moveX = 0;
int moveY = 0;
float picSize = 200;
while(startCount <= endCount)
{
moveX = startCount*150;
draw_rabbit(moveX,moveY,picSize,random(255));
startCount++;
}
}
void draw_rabbit(int posX ,int posY ,float picSize , float random_color )
{
float scale = picSize / 500;
noStroke();
fill(random_color);
ellipse(scale * 270+posX,scale * 300+posY,scale * 250,scale * 180); //Face
ellipse(scale * 320+posX,scale * 430+posY,scale * 250,scale * 200); //Throat
//fill(255);
//triangle(scale * 500,scale * -750,scale * 500,scale * 500,scale * 350,scale * 500); //blockbackground
fill(random_color); //ribbon
stroke(255); //ribbon
strokeWeight(5); //ribbon
triangle(scale * 180+posX,scale * 480+posY,scale * 250+posX,scale * 440+posY,scale * 240+posX,scale * 500+posY); //ribbon
//line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 350+posY); //ribbon
//line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 390+posY); //ribbon
noStroke();
triangle(scale * 230+posX,scale * 480+posY,scale * 175+posX,scale * 450+posY,scale * 175+posX,scale * 490+posY); //ribbon
fill(255);
ellipse(scale * 240+posX,scale * 260+posY,scale * 50,scale * 50); //Eye
fill(random_color);
ellipse(scale * 360+posX,scale * 200+posY,scale * 50,scale * 300); //EarLeft
ellipse(scale * 320+posX,scale * 200+posY,scale * 50,scale * 300); //EarRight
}
[LAB 4] Pirate
void setup()
{
size(500,500);
frameRate(27);
}
void draw_Pirate(int posX,int posY ,float picSize)
{
float scale = picSize / 500 ;
noStroke();
fill(255);
rect(scale * 50+posX,scale * 50+posY,scale * 400,scale * 400); //Face
strokeWeight(5);
stroke(0);
line(scale * 50+posX,scale * 300+posY,scale * 250+posX,scale * 50+posY); //Blindfolds
strokeWeight(1);
fill(0);
rect(scale * 120+posX,scale * 125+posY,scale * 80,scale * 80); //EyeLeft
rect(scale * 300+posX,scale * 125+posY,scale * 80,scale * 80); //EyeRight
fill(255);
ellipse(scale * 340+posX,scale * 165.5+posY,scale * 30,scale * 30);
fill(0);
rect(scale * 220+posX,scale * 200+posY,scale * 50,scale * 100); //Nose
rect(scale * 120+posX,scale * 350+posY,scale * 250,scale * 50); //Mouth
fill(255);
rect(scale * 120+posX,scale * 350+posY,scale * 25,scale * 25);//Teeth
rect(scale * 145+posX,scale * 350+posY,scale * 25,scale * 25); //Teeth
rect(scale * 195+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 345+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 120+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 145+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 170+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 270+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 375+posY,scale * 25,scale * 25); //teeth
}
void draw()
{
background(#DF013A);
int startUnit = 0;
int endUnit = 10;
int posX =250;
int posY =200;
int scale = 75;
while(startUnit <= endUnit)
{
posX = (mouseX/4)*startUnit;
draw_Pirate(posX,posY,scale);
startUnit++;
}
}
{
size(500,500);
frameRate(27);
}
void draw_Pirate(int posX,int posY ,float picSize)
{
float scale = picSize / 500 ;
noStroke();
fill(255);
rect(scale * 50+posX,scale * 50+posY,scale * 400,scale * 400); //Face
strokeWeight(5);
stroke(0);
line(scale * 50+posX,scale * 300+posY,scale * 250+posX,scale * 50+posY); //Blindfolds
strokeWeight(1);
fill(0);
rect(scale * 120+posX,scale * 125+posY,scale * 80,scale * 80); //EyeLeft
rect(scale * 300+posX,scale * 125+posY,scale * 80,scale * 80); //EyeRight
fill(255);
ellipse(scale * 340+posX,scale * 165.5+posY,scale * 30,scale * 30);
fill(0);
rect(scale * 220+posX,scale * 200+posY,scale * 50,scale * 100); //Nose
rect(scale * 120+posX,scale * 350+posY,scale * 250,scale * 50); //Mouth
fill(255);
rect(scale * 120+posX,scale * 350+posY,scale * 25,scale * 25);//Teeth
rect(scale * 145+posX,scale * 350+posY,scale * 25,scale * 25); //Teeth
rect(scale * 195+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 345+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 120+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 145+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 170+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 270+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 375+posY,scale * 25,scale * 25); //teeth
}
void draw()
{
background(#DF013A);
int startUnit = 0;
int endUnit = 10;
int posX =250;
int posY =200;
int scale = 75;
while(startUnit <= endUnit)
{
posX = (mouseX/4)*startUnit;
draw_Pirate(posX,posY,scale);
startUnit++;
}
}
[LAB 4] Flocks of Birds
int flying_bird;
void setup()
{
size(500,500);
}
void draw()
{
int countBird = 0;
int unitBird = 3;
int xContral = mouseX;
int yContral = mouseY;
background(255);
if(frameCount%10 < 5)
{
flying_bird = 30;
}
else
{
flying_bird = -30;
}
while(countBird < unitBird)
{
xContral = mouseX+(countBird*100)+100;
yContral = (countBird*150)+100;
draw_BodyBird(xContral,yContral);
countBird++;
}
}
void draw_BodyBird(int xContral ,int yContral)
{
int sizeBody = 100;
int xMouth1 = 0;
int yMouth1 = 55;
int xMouth2 = -25;
int yMouth2 = 5;
int xMouth3 = 25;
int yMouth3 = 5;
int xEyeL = -25;
int yEyeL = -25;
int xEyeR = 25;
int yEyeR = -25;
int sizeEye =50;
int length_Fly = 100;
line(xContral,yContral,xContral +length_Fly ,flying_bird+yContral);
line(xContral,yContral,xContral -length_Fly ,flying_bird+yContral);
strokeWeight(1);
fill(0);
ellipse(xContral,yContral,sizeBody,sizeBody);
fill(#FFF92C);
triangle(xContral,yMouth1+yContral,xMouth2+xContral,yMouth2+yContral,xMouth3+xContral,yMouth3+yContral);
fill(255);
ellipse(xEyeL+xContral,yEyeL+yContral,sizeEye,sizeEye);
fill(255);
ellipse(xEyeR+xContral,yEyeR+yContral,sizeEye,sizeEye);
strokeWeight(5);
point(xEyeL+xContral,yEyeL+yContral);
point(xEyeR+xContral,yEyeR+yContral);
}
void setup()
{
size(500,500);
}
void draw()
{
int countBird = 0;
int unitBird = 3;
int xContral = mouseX;
int yContral = mouseY;
background(255);
if(frameCount%10 < 5)
{
flying_bird = 30;
}
else
{
flying_bird = -30;
}
while(countBird < unitBird)
{
xContral = mouseX+(countBird*100)+100;
yContral = (countBird*150)+100;
draw_BodyBird(xContral,yContral);
countBird++;
}
}
void draw_BodyBird(int xContral ,int yContral)
{
int sizeBody = 100;
int xMouth1 = 0;
int yMouth1 = 55;
int xMouth2 = -25;
int yMouth2 = 5;
int xMouth3 = 25;
int yMouth3 = 5;
int xEyeL = -25;
int yEyeL = -25;
int xEyeR = 25;
int yEyeR = -25;
int sizeEye =50;
int length_Fly = 100;
line(xContral,yContral,xContral +length_Fly ,flying_bird+yContral);
line(xContral,yContral,xContral -length_Fly ,flying_bird+yContral);
strokeWeight(1);
fill(0);
ellipse(xContral,yContral,sizeBody,sizeBody);
fill(#FFF92C);
triangle(xContral,yMouth1+yContral,xMouth2+xContral,yMouth2+yContral,xMouth3+xContral,yMouth3+yContral);
fill(255);
ellipse(xEyeL+xContral,yEyeL+yContral,sizeEye,sizeEye);
fill(255);
ellipse(xEyeR+xContral,yEyeR+yContral,sizeEye,sizeEye);
strokeWeight(5);
point(xEyeL+xContral,yEyeL+yContral);
point(xEyeR+xContral,yEyeR+yContral);
}
[LAB 4] Balloons
void setup()
{
size(300,300);
frameRate(27);
}
void draw()
{
background(255);
int posX = mouseX;
int posY = mouseY;
int countBalloon = 0;
int unitBalloon = 3;
int range = 1;
if(mouseButton == LEFT)
{
while(countBalloon < unitBalloon)
{
posX = countBalloon*75+50;
draw_ballon(posX ,posY ,75);
countBalloon++;
}
}
if(mouseButton == RIGHT)
{
while(countBalloon < unitBalloon)
{
int moveY = frameCount;
posX = (countBalloon*75)+50;
posY = mouseY+(-moveY);
if(posY < 0)
{
posY = 0;
}
draw_ballon(posX ,posY ,75);
countBalloon++;
}
}
}
void draw_ballon(int posX ,int posY ,int radius )
{
fill(#FC0000);
line(posX,posY,posX,100+posY);
ellipse(posX,posY,radius,radius);
}
{
size(300,300);
frameRate(27);
}
void draw()
{
background(255);
int posX = mouseX;
int posY = mouseY;
int countBalloon = 0;
int unitBalloon = 3;
int range = 1;
if(mouseButton == LEFT)
{
while(countBalloon < unitBalloon)
{
posX = countBalloon*75+50;
draw_ballon(posX ,posY ,75);
countBalloon++;
}
}
if(mouseButton == RIGHT)
{
while(countBalloon < unitBalloon)
{
int moveY = frameCount;
posX = (countBalloon*75)+50;
posY = mouseY+(-moveY);
if(posY < 0)
{
posY = 0;
}
draw_ballon(posX ,posY ,75);
countBalloon++;
}
}
}
void draw_ballon(int posX ,int posY ,int radius )
{
fill(#FC0000);
line(posX,posY,posX,100+posY);
ellipse(posX,posY,radius,radius);
}
วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558
[LAB3] DeliveryCharge
void setup()
{
size(300,300);
background(0);
boolean type_Package = true;
int day_Priority = 1;
int day_Standard = 2;
int twoDay = 3;
int choiceDay = twoDay;
float charge = 0;
float weight =8;
if(type_Package)
{
if(choiceDay == day_Priority)
{
if(weight >= 8)
{
charge = 12;
}
}
else if(choiceDay == day_Standard)
{
if(weight >= 8)
{
charge = 10.50;
}
}
else if(choiceDay == twoDay)
{
textSize(24);
text("Not Available",width/3,height-20);
textSize(12);
}
}
else
{
if(choiceDay == day_Priority)
{
charge = AddPriority(weight);
}
else if(choiceDay == day_Standard)
{
charge = AddStandard(weight);
}
else if(choiceDay == twoDay)
{
charge = AddtwoDay(weight);
}
}
if(type_Package)
{
text("Your Package type is LETTER",width/3,height/4);
}
else
{
text("Your Package type is BOX",width/3,height/4);
}
if(choiceDay == day_Priority)
{
text("Next Day Priority",width/3,height/2);
}
else if(choiceDay == day_Standard)
{
text("Next Day Standard",width/3,height/2);
}
else if(choiceDay == twoDay)
{
text("2-DAY",width/3,height/2);
}
text("Charge = $"+charge,width/3,height*0.75);
}
float AddPriority(float weight)
{
float Pcharge = 15.75 ;
if(weight > 1.00)
{
float weightTrue = weight - 1 ;
float add = weightTrue * 1.25 ;
Pcharge = Pcharge + add ;
}
return Pcharge ;
}
float AddStandard(float weight)
{
float Scharge = 13.75 ;
if(weight > 1.00)
{
float weightTrue = weight - 1 ;
float add = weightTrue * 1.00 ;
Scharge = Scharge + add ;
}
return Scharge ;
}
float AddtwoDay(float weight)
{
float TDcharge = 7.00;
if(weight > 1.00)
{
float weightTrue = weight - 1 ;
float add = weightTrue * 1.00 ;
TDcharge = TDcharge + add ;
}
return TDcharge ;
}
{
size(300,300);
background(0);
boolean type_Package = true;
int day_Priority = 1;
int day_Standard = 2;
int twoDay = 3;
int choiceDay = twoDay;
float charge = 0;
float weight =8;
if(type_Package)
{
if(choiceDay == day_Priority)
{
if(weight >= 8)
{
charge = 12;
}
}
else if(choiceDay == day_Standard)
{
if(weight >= 8)
{
charge = 10.50;
}
}
else if(choiceDay == twoDay)
{
textSize(24);
text("Not Available",width/3,height-20);
textSize(12);
}
}
else
{
if(choiceDay == day_Priority)
{
charge = AddPriority(weight);
}
else if(choiceDay == day_Standard)
{
charge = AddStandard(weight);
}
else if(choiceDay == twoDay)
{
charge = AddtwoDay(weight);
}
}
if(type_Package)
{
text("Your Package type is LETTER",width/3,height/4);
}
else
{
text("Your Package type is BOX",width/3,height/4);
}
if(choiceDay == day_Priority)
{
text("Next Day Priority",width/3,height/2);
}
else if(choiceDay == day_Standard)
{
text("Next Day Standard",width/3,height/2);
}
else if(choiceDay == twoDay)
{
text("2-DAY",width/3,height/2);
}
text("Charge = $"+charge,width/3,height*0.75);
}
float AddPriority(float weight)
{
float Pcharge = 15.75 ;
if(weight > 1.00)
{
float weightTrue = weight - 1 ;
float add = weightTrue * 1.25 ;
Pcharge = Pcharge + add ;
}
return Pcharge ;
}
float AddStandard(float weight)
{
float Scharge = 13.75 ;
if(weight > 1.00)
{
float weightTrue = weight - 1 ;
float add = weightTrue * 1.00 ;
Scharge = Scharge + add ;
}
return Scharge ;
}
float AddtwoDay(float weight)
{
float TDcharge = 7.00;
if(weight > 1.00)
{
float weightTrue = weight - 1 ;
float add = weightTrue * 1.00 ;
TDcharge = TDcharge + add ;
}
return TDcharge ;
}
[LAB 3] Syntex ERROR ~!
1.
ERROR!
Found one too many { characters without a } to match it.
Cause of problems
ใส่ { } ไม่ถูกต้อง
How you fixed it
แก้ใส่ {} ให้ถูกต้อง
2.
ERROR!
The method value_leapyear(int) int the type [namefile] is not applicable for the arguments()
Cause of problems
ไม่ได้กำหนดตัวแปรของค่า int
How you fixed it
แก้ไข เรากำหนดตัวแปรเป็นค่า int เอง
ERROR!
Found one too many { characters without a } to match it.
Cause of problems
ใส่ { } ไม่ถูกต้อง
How you fixed it
แก้ใส่ {} ให้ถูกต้อง
2.
ERROR!
The method value_leapyear(int) int the type [namefile] is not applicable for the arguments()
Cause of problems
ไม่ได้กำหนดตัวแปรของค่า int
How you fixed it
แก้ไข เรากำหนดตัวแปรเป็นค่า int เอง
วันศุกร์ที่ 4 กันยายน พ.ศ. 2558
[LAB3] METROMUSIC
void setup()
{
size(500,500);
frameRate(30);
}
void draw()
{
int posX = 0;
int posY = 0;
if(key == 'a')
{
posX = posX - 100;
}
else if(key == 'd')
{
posX = posX + 100;
}
else if(key == 'w')
{
posY = posY - 100;
}
else if(key == 's')
{
posY = posY + 100;
}
draw_Logo(posX,posY,300);
}
void draw_Logo(int posX ,int posY ,float picSize )
{
float scale = picSize / 500 ;
background(255);
strokeWeight(scale * 15);
noFill();
ellipse(scale * 250+posX,scale * 300+posY,scale * 100,scale * 100);
fill(255);
stroke(255);
rect(scale * 0+posX,scale * 249+posY,scale * 500,scale * 18);
stroke(0);
line(scale * 200+posX,scale * 230+posY,scale * 235+posX,scale * 180+posY); // MLeft
line(scale * 200+posX,scale * 230+posY,scale * 160+posX,scale * 175+posY);
line(scale * 159+posX,scale * 175+posY,scale * 159+posX,scale * 300+posY);
line(scale * 265+posX,scale * 180+posY,scale * 300+posX,scale * 230+posY); // MRight
line(scale * 300+posX,scale * 230+posY,scale * 340+posX,scale * 175+posY);
line(scale * 340+posX,scale * 175+posY,scale * 340+posX,scale * 300+posY);
stroke(#FF0000);
line(scale * 240+posX,scale * 300+posY,scale * 240+posX,scale * 100+posY); //line Left
line(scale * 260+posX,scale * 300+posY,scale * 260+posX,scale * 100+posY); //line Right
line(scale * 240+posX,scale * 100+posY,scale * 215+posX,scale * 80+posY); //Head
line(scale * 215+posX,scale * 80+posY,scale * 240+posX,scale * 50+posY);
strokeWeight(scale * 6);
point(scale * 230+posX,scale * 45+posY);
point(scale * 225+posX,scale * 50+posY);
point(scale * 221+posX,scale * 55+posY);
println("METROMUSICCENTER");
}
{
size(500,500);
frameRate(30);
}
void draw()
{
int posX = 0;
int posY = 0;
if(key == 'a')
{
posX = posX - 100;
}
else if(key == 'd')
{
posX = posX + 100;
}
else if(key == 'w')
{
posY = posY - 100;
}
else if(key == 's')
{
posY = posY + 100;
}
draw_Logo(posX,posY,300);
}
void draw_Logo(int posX ,int posY ,float picSize )
{
float scale = picSize / 500 ;
background(255);
strokeWeight(scale * 15);
noFill();
ellipse(scale * 250+posX,scale * 300+posY,scale * 100,scale * 100);
fill(255);
stroke(255);
rect(scale * 0+posX,scale * 249+posY,scale * 500,scale * 18);
stroke(0);
line(scale * 200+posX,scale * 230+posY,scale * 235+posX,scale * 180+posY); // MLeft
line(scale * 200+posX,scale * 230+posY,scale * 160+posX,scale * 175+posY);
line(scale * 159+posX,scale * 175+posY,scale * 159+posX,scale * 300+posY);
line(scale * 265+posX,scale * 180+posY,scale * 300+posX,scale * 230+posY); // MRight
line(scale * 300+posX,scale * 230+posY,scale * 340+posX,scale * 175+posY);
line(scale * 340+posX,scale * 175+posY,scale * 340+posX,scale * 300+posY);
stroke(#FF0000);
line(scale * 240+posX,scale * 300+posY,scale * 240+posX,scale * 100+posY); //line Left
line(scale * 260+posX,scale * 300+posY,scale * 260+posX,scale * 100+posY); //line Right
line(scale * 240+posX,scale * 100+posY,scale * 215+posX,scale * 80+posY); //Head
line(scale * 215+posX,scale * 80+posY,scale * 240+posX,scale * 50+posY);
strokeWeight(scale * 6);
point(scale * 230+posX,scale * 45+posY);
point(scale * 225+posX,scale * 50+posY);
point(scale * 221+posX,scale * 55+posY);
println("METROMUSICCENTER");
}
[LAB3] PLAYBOY
void setup()
{
size(500,500);
frameRate(30);
}
void draw()
{
int posX = 1;
if(keyCode == RIGHT)
{
posX = posX + 100;
}
if(keyCode == LEFT)
{
posX = posX - 100;
}
draw_rabbit(posX,0,300);
}
void draw_rabbit(int posX ,int posY ,float picSize )
{
float scale = picSize / 500;
background(255);
noStroke();
fill(0);
ellipse(scale * 270+posX,scale * 300+posY,scale * 250,scale * 180); //Face
ellipse(scale * 320+posX,scale * 430+posY,scale * 250,scale * 200); //Throat
fill(255);
//triangle(scale * 500,scale * -750,scale * 500,scale * 500,scale * 350,scale * 500); //blockbackground
fill(0); //ribbon
stroke(255); //ribbon
strokeWeight(5); //ribbon
triangle(scale * 180+posX,scale * 480+posY,scale * 250+posX,scale * 440+posY,scale * 240+posX,scale * 500+posY); //ribbon
//line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 350+posY); //ribbon
//line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 390+posY); //ribbon
noStroke();
triangle(scale * 230+posX,scale * 480+posY,scale * 175+posX,scale * 450+posY,scale * 175+posX,scale * 490+posY); //ribbon
fill(255);
ellipse(scale * 240+posX,scale * 260+posY,scale * 50,scale * 50); //Eye
fill(0);
ellipse(scale * 360+posX,scale * 200+posY,scale * 50,scale * 300); //EarLeft
ellipse(scale * 320+posX,scale * 200+posY,scale * 50,scale * 300); //EarRight
}
{
size(500,500);
frameRate(30);
}
void draw()
{
int posX = 1;
if(keyCode == RIGHT)
{
posX = posX + 100;
}
if(keyCode == LEFT)
{
posX = posX - 100;
}
draw_rabbit(posX,0,300);
}
void draw_rabbit(int posX ,int posY ,float picSize )
{
float scale = picSize / 500;
background(255);
noStroke();
fill(0);
ellipse(scale * 270+posX,scale * 300+posY,scale * 250,scale * 180); //Face
ellipse(scale * 320+posX,scale * 430+posY,scale * 250,scale * 200); //Throat
fill(255);
//triangle(scale * 500,scale * -750,scale * 500,scale * 500,scale * 350,scale * 500); //blockbackground
fill(0); //ribbon
stroke(255); //ribbon
strokeWeight(5); //ribbon
triangle(scale * 180+posX,scale * 480+posY,scale * 250+posX,scale * 440+posY,scale * 240+posX,scale * 500+posY); //ribbon
//line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 350+posY); //ribbon
//line(scale * 250+posX,scale * 480+posY,scale * 400,scale * 390+posY); //ribbon
noStroke();
triangle(scale * 230+posX,scale * 480+posY,scale * 175+posX,scale * 450+posY,scale * 175+posX,scale * 490+posY); //ribbon
fill(255);
ellipse(scale * 240+posX,scale * 260+posY,scale * 50,scale * 50); //Eye
fill(0);
ellipse(scale * 360+posX,scale * 200+posY,scale * 50,scale * 300); //EarLeft
ellipse(scale * 320+posX,scale * 200+posY,scale * 50,scale * 300); //EarRight
}
[LAB3] PIRATE
void setup()
{
size(500,500);
frameRate(27);
}
void draw_Pirate(int posX,int posY ,float picSize)
{
float scale = picSize / 500 ;
noStroke();
background(#DF013A);
fill(255);
rect(scale * 50+posX,scale * 50+posY,scale * 400,scale * 400); //Face
strokeWeight(5);
stroke(0);
line(scale * 50+posX,scale * 300+posY,scale * 250+posX,scale * 50+posY); //Blindfolds
strokeWeight(1);
fill(0);
rect(scale * 120+posX,scale * 125+posY,scale * 80,scale * 80); //EyeLeft
rect(scale * 300+posX,scale * 125+posY,scale * 80,scale * 80); //EyeRight
fill(255);
ellipse(scale * 340+posX,scale * 165.5+posY,scale * 30,scale * 30);
fill(0);
rect(scale * 220+posX,scale * 200+posY,scale * 50,scale * 100); //Nose
rect(scale * 120+posX,scale * 350+posY,scale * 250,scale * 50); //Mouth
fill(255);
rect(scale * 120+posX,scale * 350+posY,scale * 25,scale * 25);//Teeth
rect(scale * 145+posX,scale * 350+posY,scale * 25,scale * 25); //Teeth
rect(scale * 195+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 345+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 120+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 145+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 170+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 270+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 375+posY,scale * 25,scale * 25); //teeth
}
float setSize = 1;
void draw()
{
draw_Pirate(mouseX,mouseY,setSize);
if(mouseButton == LEFT)
{
setSize++ ;
}
else if(mouseButton == RIGHT)
{
setSize-- ;
}
text(setSize,width*0.9,height*0.9);
}
{
size(500,500);
frameRate(27);
}
void draw_Pirate(int posX,int posY ,float picSize)
{
float scale = picSize / 500 ;
noStroke();
background(#DF013A);
fill(255);
rect(scale * 50+posX,scale * 50+posY,scale * 400,scale * 400); //Face
strokeWeight(5);
stroke(0);
line(scale * 50+posX,scale * 300+posY,scale * 250+posX,scale * 50+posY); //Blindfolds
strokeWeight(1);
fill(0);
rect(scale * 120+posX,scale * 125+posY,scale * 80,scale * 80); //EyeLeft
rect(scale * 300+posX,scale * 125+posY,scale * 80,scale * 80); //EyeRight
fill(255);
ellipse(scale * 340+posX,scale * 165.5+posY,scale * 30,scale * 30);
fill(0);
rect(scale * 220+posX,scale * 200+posY,scale * 50,scale * 100); //Nose
rect(scale * 120+posX,scale * 350+posY,scale * 250,scale * 50); //Mouth
fill(255);
rect(scale * 120+posX,scale * 350+posY,scale * 25,scale * 25);//Teeth
rect(scale * 145+posX,scale * 350+posY,scale * 25,scale * 25); //Teeth
rect(scale * 195+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 345+posX,scale * 350+posY,scale * 25,scale * 25);//teeth
rect(scale * 120+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 145+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 170+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 220+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 245+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 270+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 295+posX,scale * 375+posY,scale * 25,scale * 25);//teeth
rect(scale * 320+posX,scale * 375+posY,scale * 25,scale * 25); //teeth
}
float setSize = 1;
void draw()
{
draw_Pirate(mouseX,mouseY,setSize);
if(mouseButton == LEFT)
{
setSize++ ;
}
else if(mouseButton == RIGHT)
{
setSize-- ;
}
text(setSize,width*0.9,height*0.9);
}
[LAB3] LEAPYEAR
void setup()
{
size(500,500);
background(0);
textSize(30);
value_leapYear(1800);
}
void value_leapYear(int year)
{
text("Year = "+year,width/3,height/3);
if(year%4 == 0 && year%100 != 0)
{
text("LEAPYEA!",width/3,height/2);
}
else
{
text("NOT LEAPYEAR !",width/3,height/2);
}
}
{
size(500,500);
background(0);
textSize(30);
value_leapYear(1800);
}
void value_leapYear(int year)
{
text("Year = "+year,width/3,height/3);
if(year%4 == 0 && year%100 != 0)
{
text("LEAPYEA!",width/3,height/2);
}
else
{
text("NOT LEAPYEAR !",width/3,height/2);
}
}
[LAB3] POWER OF 10
void setup()
{
size(500,500);
background(0);
textSize(20);
valuePower(10);
}
void valuePower(int number_Exponent)
{
text("Power of 10 = "+number_Exponent,width/3,height/3);
if(number_Exponent == 6)
{
text("Word Number is Million",width/3,height/2);
}
else if(number_Exponent == 9)
{
text("Word Number is Billion",width/3,height/2);
}
else if(number_Exponent == 12)
{
text("Word Number is Trillion",width/3,height/2);
}
else if(number_Exponent == 15)
{
text("Word Number is Quadrillion",width/3,height/2);
}
else if(number_Exponent == 18)
{
text("Word Number is Quintillion",width/3,height/2);
}
else if(number_Exponent == 21)
{
text("Word Number is Sextillion",width/3,height/2);
}
else if(number_Exponent == 30)
{
text("Word Number is Nonillion",width/3,height/2);
}
else if(number_Exponent == 100)
{
text("Word Number is googol",width/3,height/2);
}
else
{
text("ERROR!",width/3,height/2);
}
}
{
size(500,500);
background(0);
textSize(20);
valuePower(10);
}
void valuePower(int number_Exponent)
{
text("Power of 10 = "+number_Exponent,width/3,height/3);
if(number_Exponent == 6)
{
text("Word Number is Million",width/3,height/2);
}
else if(number_Exponent == 9)
{
text("Word Number is Billion",width/3,height/2);
}
else if(number_Exponent == 12)
{
text("Word Number is Trillion",width/3,height/2);
}
else if(number_Exponent == 15)
{
text("Word Number is Quadrillion",width/3,height/2);
}
else if(number_Exponent == 18)
{
text("Word Number is Quintillion",width/3,height/2);
}
else if(number_Exponent == 21)
{
text("Word Number is Sextillion",width/3,height/2);
}
else if(number_Exponent == 30)
{
text("Word Number is Nonillion",width/3,height/2);
}
else if(number_Exponent == 100)
{
text("Word Number is googol",width/3,height/2);
}
else
{
text("ERROR!",width/3,height/2);
}
}
วันพุธที่ 2 กันยายน พ.ศ. 2558
[LAB3] FlyingBird
int flying_bird;
void setup()
{
size(500,500);
}
void draw()
{
background(255);
if(frameCount%10 < 5)
{
flying_bird = 30;
}
else
{
flying_bird = -30;
}
draw_BodyBird(mouseX,mouseY);
}
void draw_BodyBird(int xContral ,int yContral)
{
int sizeBody = 100;
int xMouth1 = 0;
int yMouth1 = 55;
int xMouth2 = -25;
int yMouth2 = 5;
int xMouth3 = 25;
int yMouth3 = 5;
int xEyeL = -25;
int yEyeL = -25;
int xEyeR = 25;
int yEyeR = -25;
int sizeEye =50;
int length_Fly = 100;
line(xContral,yContral,xContral +length_Fly ,flying_bird+mouseY);
line(xContral,yContral,xContral -length_Fly ,flying_bird+mouseY);
strokeWeight(1);
fill(0);
ellipse(xContral,yContral,sizeBody,sizeBody);
fill(#FFF92C);
triangle(xContral,yMouth1+yContral,xMouth2+xContral,yMouth2+yContral,xMouth3+xContral,yMouth3+yContral);
fill(255);
ellipse(xEyeL+xContral,yEyeL+yContral,sizeEye,sizeEye);
fill(255);
ellipse(xEyeR+xContral,yEyeR+yContral,sizeEye,sizeEye);
strokeWeight(5);
point(xEyeL+xContral,yEyeL+yContral);
point(xEyeR+xContral,yEyeR+yContral);
}
void setup()
{
size(500,500);
}
void draw()
{
background(255);
if(frameCount%10 < 5)
{
flying_bird = 30;
}
else
{
flying_bird = -30;
}
draw_BodyBird(mouseX,mouseY);
}
void draw_BodyBird(int xContral ,int yContral)
{
int sizeBody = 100;
int xMouth1 = 0;
int yMouth1 = 55;
int xMouth2 = -25;
int yMouth2 = 5;
int xMouth3 = 25;
int yMouth3 = 5;
int xEyeL = -25;
int yEyeL = -25;
int xEyeR = 25;
int yEyeR = -25;
int sizeEye =50;
int length_Fly = 100;
line(xContral,yContral,xContral +length_Fly ,flying_bird+mouseY);
line(xContral,yContral,xContral -length_Fly ,flying_bird+mouseY);
strokeWeight(1);
fill(0);
ellipse(xContral,yContral,sizeBody,sizeBody);
fill(#FFF92C);
triangle(xContral,yMouth1+yContral,xMouth2+xContral,yMouth2+yContral,xMouth3+xContral,yMouth3+yContral);
fill(255);
ellipse(xEyeL+xContral,yEyeL+yContral,sizeEye,sizeEye);
fill(255);
ellipse(xEyeR+xContral,yEyeR+yContral,sizeEye,sizeEye);
strokeWeight(5);
point(xEyeL+xContral,yEyeL+yContral);
point(xEyeR+xContral,yEyeR+yContral);
}
วันอังคารที่ 1 กันยายน พ.ศ. 2558
[LAB3] Battery Charge/Discharge
void setup()
{
size(500,500);
frameRate(15);
background(0);
}
void draw_Electrode(int posX , int posY)
{
int xAnode = 380;
int yAnode = 235;
int xAnode2 = 370;
int yAnode2 = 245;
int xCathode = 100;
int yCathode = 245;
int xSizeanode = 10;
int ySizeanode = 30;
int xSizenode =30;
int ySizenode =10;
noStroke(); //noline
fill(#FF0000); //red
rect(xAnode+posX,yAnode+posY, xSizeanode,ySizeanode); //anode
rect(xAnode2+posX,yAnode2+posY,xSizenode,ySizenode);
rect(xCathode+posX,yCathode+posY,xSizenode,ySizenode); //cathode
}
void draw_battery (int posX , int posY)
{
int xBig = 100;
int yBig = 200;
int xSizebig = 300;
int ySizebig = 100;
int xSmall = 400;
int ySmall = 240;
int Sizesmall =20;
stroke(255); //linewrite
strokeWeight(4);
fill(#D8D8D8);
rect(xBig+posX,yBig+posY,xSizebig,ySizebig); //rect BIG
fill(#D8D8D8);
rect(xSmall+posX,ySmall+posY,Sizesmall,Sizesmall); // rect SMALL
}
void draw_energy(int incX , int incY)
{
int xEnergy = 100;
int yEnergy = 200;
fill(#FE2E2E);
rect(xEnergy,yEnergy,incX,incY);
}
int incX=0;
void draw()
{
int xText = 250;
int yText = 350;
draw_battery(0,0);
draw_energy(incX,100);
if(key == 'a')
{
incX = incX+7;
text("Charge",xText,yText);
if(incX > 300)
{
incX = 300;
}
}
else if(key == 'b')
{
incX = incX-7;
text("Discharge",xText,yText);
if(incX < 0)
incX = 0;
}
draw_Electrode(0,0);
}
{
size(500,500);
frameRate(15);
background(0);
}
void draw_Electrode(int posX , int posY)
{
int xAnode = 380;
int yAnode = 235;
int xAnode2 = 370;
int yAnode2 = 245;
int xCathode = 100;
int yCathode = 245;
int xSizeanode = 10;
int ySizeanode = 30;
int xSizenode =30;
int ySizenode =10;
noStroke(); //noline
fill(#FF0000); //red
rect(xAnode+posX,yAnode+posY, xSizeanode,ySizeanode); //anode
rect(xAnode2+posX,yAnode2+posY,xSizenode,ySizenode);
rect(xCathode+posX,yCathode+posY,xSizenode,ySizenode); //cathode
}
void draw_battery (int posX , int posY)
{
int xBig = 100;
int yBig = 200;
int xSizebig = 300;
int ySizebig = 100;
int xSmall = 400;
int ySmall = 240;
int Sizesmall =20;
stroke(255); //linewrite
strokeWeight(4);
fill(#D8D8D8);
rect(xBig+posX,yBig+posY,xSizebig,ySizebig); //rect BIG
fill(#D8D8D8);
rect(xSmall+posX,ySmall+posY,Sizesmall,Sizesmall); // rect SMALL
}
void draw_energy(int incX , int incY)
{
int xEnergy = 100;
int yEnergy = 200;
fill(#FE2E2E);
rect(xEnergy,yEnergy,incX,incY);
}
int incX=0;
void draw()
{
int xText = 250;
int yText = 350;
draw_battery(0,0);
draw_energy(incX,100);
if(key == 'a')
{
incX = incX+7;
text("Charge",xText,yText);
if(incX > 300)
{
incX = 300;
}
}
else if(key == 'b')
{
incX = incX-7;
text("Discharge",xText,yText);
if(incX < 0)
incX = 0;
}
draw_Electrode(0,0);
}
สมัครสมาชิก:
บทความ (Atom)