int volumeposY = 110;
int volumeHeight = 380;
int batt_usage;
int posY_change;
int volumeColor = #008B00;
int update = 0;
void setup() {
size(400, 600);
}
void draw() {
int batteryposX = 100, batteryposY = 100;
frameRate(50);
background(0);
Building Software Systems I & II
&
Computer Fundamentals
By Thakdanai Khunsaen
OS : Ubuntu GNOME 17.04 64-bit
วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558
Lab3-Delivery Charge
int space = 50;
void setup() {
size(650, 300);
background(#DDFFFF);
int x =50, y =50;
int packageType = 2;
int serviceType = 3;
float weight = 16;
fill(0);
textSize(40);
text("Expressimo Delivery Service", x, y);
charge(x+space, y+space, packageType, serviceType, weight);
}
void charge(int x, int y, int package_type, int service_type, float weight) {
float cost =0;
fill(#FF0000);
textSize(30);
if (package_type == 1) {
text("Package : LETTER", x, y);
if (service_type == 1) {
text("Service : Next day Priority", x, y+space);
if (weight <= 8) {
cost = 12;
} else {
cost = 0;
}
} else if (service_type == 2) {
text("Service : Next day Standard", x, y+space);
if (weight <= 8) {
cost = 10.5;
} else {
cost = 0;
}
} else if (service_type == 3) {
text("Service : No Service", x, y+space);
} else {
text("Service : ERROR", x, y+space);
}
text("Weight : "+weight+" Oz", x, y+space*2);
} else if (package_type == 2) {
text("Package : BOX", x, y);
if (service_type == 1) {
text("Service : Next day Priority", x, y+space);
if (weight <= 1) {
cost = 15.75;
} else {
cost = cal_service1(weight);
}
} else if (service_type == 2) {
text("Service : Next day Standard", x, y+space);
if (weight <= 1) {
cost = 13.75;
} else {
cost = cal_service2(weight);
}
} else if (service_type == 3) {
text("Service : Two-days", x, y+space);
if (weight <= 1) {
cost = 7.00;
} else {
cost = cal_service3(weight);
}
} else {
text("Service : ERROR", x, y+space);
}
text("Weight : "+weight+" Pound", x, y+space*2);
} else {
text("Package : ERROR", x, y);
}
text("Charge : $"+cost, x, y+space*3);
}
float cal_service1(float weight) {
float priority_charge;
float firstCharge = 15.75;
priority_charge = firstCharge + ((weight-1)*1.25);
return priority_charge;
}
float cal_service2(float weight) {
float standard_charge;
float firstCharge = 13.75;
standard_charge = firstCharge + ((weight-1)*1);
return standard_charge;
}
float cal_service3(float weight) {
float twodays_charge;
float firstCharge = 7.00;
twodays_charge = firstCharge + ((weight-1)*0.5);
return twodays_charge;
}
Lab3-Leap Year
void setup() {
int x = 50, y = 50;
int space = 50;
background(#AAFF88);
size(500, 300);
textSize(40);
fill(#FF0000);
text("Leap Year?", x, y);
leapyear(x+space, y+space, 1796);
leapyear(x+space, y+space*2, 2000);
leapyear(x+space, y+space*3, 1800);
leapyear(x+space, y+space*4, 2015);
}
void leapyear(int x, int y, int year) {
fill(#008D00);
textSize(30);
if (is_leapYear(year)) {
text("'"+year+"' is a leap year.", x, y);
} else {
text("'"+year+"' is not a leap year.", x, y);
}
}
boolean is_leapYear(int year) {
boolean result = false;
if((year%4 == 0 && year%100 != 0) || (year%4 == 0 && year%100 == 0 && year%400 == 0)){
result = true;
}else{
result = false;
}
return result;
}
Lab3-Power of 10
int space = 70;
void setup() {
background(#2222FF);
size(400, 250);
int x = width/2, y = 70;
textAlign(CENTER);
textSize(60);
fill(255);
text("Power of 10", x, y);
power_of_ten(x, y+space, 9);
}
void power_of_ten(int x, int y, int power) {
textAlign(CENTER);
textSize(40);
fill(0);
text("10^"+power, x, y);
if (power == 6) {
text("'Million'", x, y+space);
} else if (power == 9) {
text("'Billion'", x, y+space);
} else if (power == 12) {
text("'Trillion'", x, y+space);
} else if (power == 15) {
text("'Quadrillion'", x, y+space);
} else if (power == 18) {
text("'Quintillion'", x, y+space);
} else if (power == 21) {
text("'Sextillion'", x, y+space);
} else if (power == 30) {
text("'Nonillion'", x, y+space);
} else if (power == 100) {
text("'Googol'", x, y+space);
}
}
Lab3-Grade
void setup() {
size(400, 200);
int x = width/2, y = 70;
int space = 80;
int score = 99;
background(#0088CC);
fill(255);
textAlign(CENTER);
textSize(50);
text("Score = "+score, x, y);
grade(x, y+space, score);
}
void grade(int x, int y, int score) {
if (score <= 100 && score >= 80) {
text("Grade A", x, y);
} else if (score <= 79 && score >= 70) {
text("Grade B", x, y);
} else if (score <= 69 && score >= 60) {
text("Grade C", x, y);
} else if (score <= 59 && score >= 50) {
text("Grade D", x, y);
} else if (score < 50) {
text("Grade F", x, y);
textSize(15);
text("See you again next year.", x, y+20);
}
}
Lab3-SPYAIR(Interactive)
float spin = 0;
float speed = 0;
int textposX = 360;
int R = 255, G = 255, B = 255;
int x_axis = -2;
void setup() {
size(700, 400);
}
float speed = 0;
int textposX = 360;
int R = 255, G = 255, B = 255;
int x_axis = -2;
void setup() {
size(700, 400);
}
Lab3-Gintama Elizabeth(Interactive)
int eyeSize = 100;
int R = 255;
int G = 255;
int B = 255;
void setup() {
size(500, 600);
background(100);
strokeWeight(5);
}
int R = 255;
int G = 255;
int B = 255;
void setup() {
size(500, 600);
background(100);
strokeWeight(5);
}
สมัครสมาชิก:
บทความ (Atom)