ปัญหา Error : Missing right parenthesis ")"
สาเหตุ : เกิดจากการที่เราลืมใส่วงเล็บไม่ครบ มีวงเล็บเปิดไม่มีวงเล็บปิด เป็นต้น
วิธีแก้ : ใส่วงเล็บให้ครบ
ปัญหา Error : Missing a semicolon";"
สาเหตุ : ลืมใส่เครื่องหมาย semicolon(;)
วิธีแก้ : ใส่ semicolon ลงไปและใส่ให้ถูกที่
ปัญหา Error : Missing right curly bracket "}"
สาเหตุ : เกิดจากการที่เราลืมใส่วงเล็บปีกกาไม่ครบ มีวงเล็บปีกกาเปิดไม่มีวงเล็บปีกกาปิด เป็นต้น
วิธีแก้ : ใส่วงเล็บปีกกาให้ครบ
ปัญหา Error : The variable "(ชื่อตัวแปรที่ error)" does not exist
สาเหตุ : ตัวแปรนี้ยังไม่ได้ประกาศ หรือ เกิดจากการที่พิมชื่อตัวแปรผิด
วิธีแก้ : ประกาศตัวแปร หรือ แก้ไขชื่อตัวแปรให้ถูกต้อง
ปัญหา Error : Void methods cannot return a value
สาเหตุ : ฟังก์ชั่น void จะไม่สามารถส่งค่ากลับได้ จึงเกิดการ error
วิธีแก้ : ลบ "return (ชื่อตัวแปร);" ออก
Building Software Systems I & II
&
Computer Fundamentals
By Thakdanai Khunsaen
OS : Ubuntu GNOME 17.04 64-bit
แสดงบทความที่มีป้ายกำกับ Lab2 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ Lab2 แสดงบทความทั้งหมด
วันอังคารที่ 1 กันยายน พ.ศ. 2558
Lab2-Digital Clock
void setup(){
size(500,200);
}
void draw(){
background(#DD0000);
digitalClock(width/2,height/2,50);
}
void digitalClock(int posX,int posY,int textsize){
int sec = second();
int min = minute();
int hr = hour();
int space = 150;
fill(255);
textSize(textsize);
textAlign(CENTER,CENTER);
text(hr+"hr",posX-space,posY);
text(min+"min ",posX,posY);
text(sec+"sec",posX+space,posY);
}
Lab2-Positive(Function)
int resizeW;
int resizeH;
int weight = 100;
int high = 300;
void setup() {
size(500, 500);
}
int resizeH;
int weight = 100;
int high = 300;
void setup() {
size(500, 500);
}
Lab2-SPYAIR(Function)
float spin = 0;
float speed = 0;
int textposX = 360;
int R = 255, G = 255, B = 255;
void setup() {
size(700, 400);
}
float speed = 0;
int textposX = 360;
int R = 255, G = 255, B = 255;
void setup() {
size(700, 400);
}
วันจันทร์ที่ 31 สิงหาคม พ.ศ. 2558
Lab2-Gintama(Color Change)
int eyeSize = 100;
int R = 255;
int G = 255;
int B = 255;
void setup(){
int space = 200;
size(500,600);
background(100);
strokeWeight(5);
}
void draw(){
fill(R,G,B);
rect(50,50,400,500);
eye(150,200,eyeSize);
eye(350,200,eyeSize);
mouth(250,320);
elizabeth_text(250,80);
gintama_text(250,500);
}
void mouseMoved() {
R = R - 5;
G = G - 15;
B = B - 51;
if (R == 0) {
R = 255;
}
if (G == 0) {
G = 255;
}
if (B == 0) {
B = 255;
}
}
void eye(int eyeposX,int eyeposY,int eyeSize){
fill(255);
ellipse(eyeposX,eyeposY,eyeSize,eyeSize);
fill(0);
ellipse(eyeposX,eyeposY,eyeSize/2,eyeSize/2);
/////Eyelashes/////
line(eyeposX-40,eyeposY-60,eyeposX-30,eyeposY-40);
line(eyeposX,eyeposY-70,eyeposX,eyeposY-50);
line(eyeposX+40,eyeposY-60,eyeposX+30,eyeposY-40);
}
void mouth(int mouthposX,int mouthposY){
fill(#FFFF00);
ellipse(mouthposX,mouthposY,250,80);
line(mouthposX-110,mouthposY,mouthposX+110,mouthposY);
}
void elizabeth_text(int x,int y){
fill(0);
textAlign(CENTER);
textSize(20);
text("ELIZABETH",x,y);
}
void gintama_text(int x,int y){
fill(50);
textAlign(CENTER);
textSize(70);
text("GINTAMA",x,y);
}
วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558
Lab2-Jurassic Brown(Moved & Random Color)
int posX = -300 ,posY = 200;
int color_bgCir,colorText,colorOutline;
int right_moved;
int left_moved;
void setup(){
size(600,400);
smooth(4);
frameRate(50);
}
int color_bgCir,colorText,colorOutline;
int right_moved;
int left_moved;
void setup(){
size(600,400);
smooth(4);
frameRate(50);
}
Lab2-BMI(Function)
int posX = 25, posY = 50;
int space = 50;
float high = 173;
float weight = 60;
void setup(){
size(450,200);
background(#99FFFF);
float BMI = cal_BMI(high,weight);
textSize(30);
fill(#008B00);
text("Weight = "+weight+" kg",posX,posY);
text("Height = "+high+" cm",posX,posY+space);
fill(#FF0000);
text("BMI = "+BMI,posX,posY+space*2);
}
float cal_BMI(float high,float weight){
float BMI;
float highM = high/100;
BMI = weight/(highM*highM);
return BMI;
}
Lab2-Circle(Function)
int posX = 25, posY = 50;
int space = 50;
float rad = 15;
void setup(){
size(600,250);
background(#FFCCCC);
float dia = cal_dia(rad);
float cir = cal_cir(rad);
float area = cal_area(rad);
fill(#FF0000);
textSize(30);
text("Radius = "+rad,posX, posY);
text("Diameter = "+dia,posX, posY+space);
text("Area = "+area,posX, posY+space*2);
text("Circumference = " +cir,posX, posY+space*3);
}
float cal_cir(float rad){
float cir;
cir = 2*PI*rad;
return cir;
}
float cal_area(float rad){
float area;
area = PI*rad*rad;
return area;
}
flaot cal_dia(float rad){
float dia;
dia = rad*2;
return dia;
}
Lab2-BATTERY
int volumeposX = 110 ,volumeposY = 110;
int volumeWidth = 180 ,volumeHeight = 380;
int batteryposX = 100 ,batteryposY = 100;
int batt_usage;
int batt_charge;
int posY_change;
int volumeColor = #008B00;
int update = 0;
void setup(){
size(400,600);
}
void draw(){
frameRate(50);
background(0);
battery(batteryposX,batteryposY,200,400,60,20);
positive(batteryposX/2,batteryposY-20);
negative(batteryposX/2,batteryposY+420);
volumeHeight = volumeHeight - batt_usage + batt_charge;
volumeposY = volumeposY + posY_change;
if((volumeHeight == 0 && volumeposY == 490) || (volumeHeight == 380 && volumeposY == 110)){
batt_usage = 0;
batt_charge = 0;
posY_change = 0;
}
int percentage = battPercent(volumeHeight);
if(percentage <= 40){
volumeColor = #FFCC00;
}
if(percentage <= 20){
volumeColor = #FF0000;
}
if(percentage >= 40){
volumeColor = #008B00;
}
}
void mouseClicked() {
if(volumeHeight <= 380 && volumeposY >= 110 && update == 0) {
batt_usage = 2;
batt_charge = 0;
posY_change = 2;
update = 1;
}
else if(volumeHeight >= 0 && volumeposY <= 490 && update == 1) {
batt_usage = 0;
batt_charge = 2;
posY_change = -2;
update = 0;
}
}
void battery(int batteryposX,int batteryposY,int batteryWidth,int batteryHeight,int poleWidth,int poleHeight){
/////BATTERY BODY/////
noFill();
stroke(#FFFFFF);
strokeWeight(5);
rect(batteryposX,batteryposY,batteryWidth,batteryHeight);
fill(255);
rect((batteryposX+(batteryWidth/2))-(poleWidth/2),batteryposY-poleHeight,poleWidth,poleHeight);
/////VOLUME/////
strokeWeight(2);
fill(volumeColor);
rect(volumeposX,volumeposY,volumeWidth,volumeHeight);
}
void positive(int positiveposX,int positiveposY){
fill(#FF0000);
textAlign(CENTER);
text("+",positiveposX,positiveposY);
}
void negative(int negativeposX,int negativeposY){
fill(#FF0000);
textAlign(CENTER);
text("-",negativeposX,negativeposY);
}
int battPercent(int volumeHeight){
int batt_percent = 100;
batt_percent = (volumeHeight*100)/380;
textAlign(CENTER);
textSize(40);
fill(#FFFFFF);
text((int)(batt_percent)+"%",batteryposX+100,batteryposY+200);
return batt_percent;
}
int volumeWidth = 180 ,volumeHeight = 380;
int batteryposX = 100 ,batteryposY = 100;
int batt_usage;
int batt_charge;
int posY_change;
int volumeColor = #008B00;
int update = 0;
void setup(){
size(400,600);
}
void draw(){
frameRate(50);
background(0);
battery(batteryposX,batteryposY,200,400,60,20);
positive(batteryposX/2,batteryposY-20);
negative(batteryposX/2,batteryposY+420);
volumeHeight = volumeHeight - batt_usage + batt_charge;
volumeposY = volumeposY + posY_change;
if((volumeHeight == 0 && volumeposY == 490) || (volumeHeight == 380 && volumeposY == 110)){
batt_usage = 0;
batt_charge = 0;
posY_change = 0;
}
int percentage = battPercent(volumeHeight);
if(percentage <= 40){
volumeColor = #FFCC00;
}
if(percentage <= 20){
volumeColor = #FF0000;
}
if(percentage >= 40){
volumeColor = #008B00;
}
}
void mouseClicked() {
if(volumeHeight <= 380 && volumeposY >= 110 && update == 0) {
batt_usage = 2;
batt_charge = 0;
posY_change = 2;
update = 1;
}
else if(volumeHeight >= 0 && volumeposY <= 490 && update == 1) {
batt_usage = 0;
batt_charge = 2;
posY_change = -2;
update = 0;
}
}
void battery(int batteryposX,int batteryposY,int batteryWidth,int batteryHeight,int poleWidth,int poleHeight){
/////BATTERY BODY/////
noFill();
stroke(#FFFFFF);
strokeWeight(5);
rect(batteryposX,batteryposY,batteryWidth,batteryHeight);
fill(255);
rect((batteryposX+(batteryWidth/2))-(poleWidth/2),batteryposY-poleHeight,poleWidth,poleHeight);
/////VOLUME/////
strokeWeight(2);
fill(volumeColor);
rect(volumeposX,volumeposY,volumeWidth,volumeHeight);
}
void positive(int positiveposX,int positiveposY){
fill(#FF0000);
textAlign(CENTER);
text("+",positiveposX,positiveposY);
}
void negative(int negativeposX,int negativeposY){
fill(#FF0000);
textAlign(CENTER);
text("-",negativeposX,negativeposY);
}
int battPercent(int volumeHeight){
int batt_percent = 100;
batt_percent = (volumeHeight*100)/380;
textAlign(CENTER);
textSize(40);
fill(#FFFFFF);
text((int)(batt_percent)+"%",batteryposX+100,batteryposY+200);
return batt_percent;
}
สมัครสมาชิก:
บทความ (Atom)