แสดงบทความที่มีป้ายกำกับ Lab2 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ Lab2 แสดงบทความทั้งหมด

31 สิงหาคม 2558

Lab2 Syntax Error


Syntax error,maybe a missing semicolon?
ปัญหา : ไม่พบ semicolon " : "
แก้ไข : ใส่ semicolon หลังคำสั่งที่พบ


Syntax error,maybe a missing right parenthesis?
ปัญหา : ไม่พบวงเล็บปิด " ) "
แก้ไข : ใส่ วงเล็บปิด " ) " ตรงตำแหน่งที่พบ


Cannot find anything named "f"
ปัญหา : อาจเกิดจากเรียกใช้ ชื่อตัวแปร ผิด หรือไม่ได้ประกาศตัวแปรชื่อนั้นไว้
แก้ไข : เรียกใช้ชื่อตัวแปรให้ตรงที่กับประกาศไว้


The function draw_windo() does not exist
ปัญหา : ไม่พบฟังก์ชั่นที่เรียกใช้
แก้ไข : เรียกใช้ฟังก์ชั่นให้ตรงกับฟังก์ชั่นที่สร้างไว้


The method rect(float,float,float,float) in the type PApplet is not applicable for the arguments(int,int,int)
ปัญหา : ใส่ค่าลงในพารามิเตอร์ ไม่ครบตามจำนวนอาร์กิวเม้นท์ของฟังก์ชัน
แก้ไข : ใส่ค่าลงในพารามิเตอร์ ให้ครบตามจำนวนอาร์กิวเม้นท์ของฟังก์ชัน



Lab2 Digital Clock (Function)







void setup(){
size(250,250);
}

void draw(){
background(0);
clock_frame();
time();
date();
}

void time(){
fill(#A4A8CD);
textSize(20);
textAlign(CENTER);
text(nf(hour(), 2)+":"+nf(minute(), 2)+":"+nf(second(), 2), width/2, (height/2)-15);
}

void date(){
fill(#A4A8CD);
textSize(20);
textAlign(CENTER);
text(nf(day(), 2)+"/"+nf(month(), 2)+"/"+nf(year(), 2), width/2, (height/2)+15);
}

void clock_frame(){
rectMode(CENTER);
stroke(#05AAF5);
strokeWeight(5);
noFill();
rect(width/2,height/2-(5),150,100,15);
}

Lab2 Cal BMI (function)







void setup(){
size(250,100);
float bmi;
float weight_;
float height_;
//----- Define value -----//
weight_ = 68;
height_ = 174;

//----- Calculate -----//
bmi = cal_bmi(weight_,height_);

//----- Show Value ----//
fill(0);
textSize(12);
text("weight_ = "+weight_+" Kilograms",0,20);
text("height_ = "+height_+" Centimeters",0,40);
text("Body mass index(BMI) = "+bmi,0,60);
}

float cal_bmi(float w, float h){//Create function BMI calculation
float val_bmi = w/((h/100)*(h/100));//Formula of BMI
return val_bmi;
}

Lab2 Cal Circumference and Area (Function)







void setup(){
size(300,100);
float diameter;
float radius;
float circumference;
float area;

//----- Define value -----//
diameter = 30;
radius = diameter/2;

//----- Calculate -----//
circumference = cal_cir(radius);
area = cal_area(radius);

//----- Show Value ----//
fill(0);
textSize(12);
text("Diametermeter = "+diameter+" cm",0,10);
text("Radius = "+radius+" cm",0,30);
text("Circumferencecumference = "+circumference+" cm",0,50);
text("Area of circumferencecle = "+area+" cm2",0,70);
}

float cal_cir(float r){//Create function circumference calculation
float val_cir = PI*2*r;//Formula of circumference
return val_cir;
}

float cal_area(float r){//Create function area calculation
float val_area = PI*r*r;//Formula of circumferencecle area
return val_area;
}

Lab2 Martin (Function)







int move = 0;
int pos_x_martin = 0;
boolean start_fw;
boolean start_bw;

void setup(){
size (600,400);
background(0);
frameRate(30);
start_fw = true;
}

void draw(){
draw_martin(move);
move = (move+2)%width;
}

void draw_martin(int pos_x){
background(0);
//----- Frame -----//
noStroke();
rect(pos_x+60,+35,480,280,2); // Frame outside
fill(0);
rect(pos_x+100,+75,400,200,2);// Frame inside

//----- Positive Sign -----//
fill(255);
rect(pos_x+140,+155,140,40,2);
rect(pos_x+190,+105,40,140,2);

//----- X Sign -----//
quad(pos_x+349,+105,pos_x+460,+216,pos_x+431,+245,pos_x+320,+134);
quad(pos_x+431,+105,pos_x+460,+134,pos_x+349,+245,pos_x+320,+216);

//----- Tiltle -----//
fill(255);

textSize(52);
text("MAR", pos_x+65 , +365);
text("IN", pos_x+232 , +365);
text("GARRI", pos_x+313 , +365);

//----- Positive Sign Tiltle -----//
rect(pos_x+195,+341,36,10);
rect(pos_x+208,+328,10,36);
//----- X Sign Tiltle -----//
quad(pos_x+503,+328,pos_x+533,+358,pos_x+526,+365,pos_x+496,+335);
quad(pos_x+526,+328,pos_x+533,+335,pos_x+503,+365,pos_x+496,+358);
}

Lab2 Doraemon Book(Function)




int move = 0;
int pos_x_book = 100;
boolean start_fw;
boolean start_bw;

void setup() {
size(500, 500);
background(#F6B0D8);
frameRate(25);
start_fw = true;
}

void draw(){
draw_book(move);
if(start_fw == true){
move +=2;
pos_x_book +=2;
if(pos_x_book >= 200){
start_fw = false;
start_bw = true;
}
}

if(start_bw == true){
move -=2;
pos_x_book -=2;
if(pos_x_book <= 0){
start_fw = true;
start_bw = false;
}
}
}

void draw_book(int pos_x){
background(#F6B0D8);
strokeJoin(ROUND);
//----- front page -----//
strokeWeight(2);
fill(#323C5D);
rect(pos_x_book,100,270,340);

//----- behind doraemon background -----//
noStroke();
fill(#FCE314);
rect(pos_x+125,220,220,205);

//----- name book background -----//
fill(255);
rect(pos_x+125,130,220,50);
//----- name book -----//
fill(0);
textSize(35);
text("DORAEMON", pos_x+133, 167);

//----- book page -----//
strokeWeight(2);
stroke(0);
fill(255);
quad(pos_x+100,100,pos_x+130,80,pos_x+400,80,pos_x+370,100);
quad(pos_x+370,100,pos_x+400,80,pos_x+400,420,pos_x+370,440);
strokeWeight(1);
line(pos_x+106,96,pos_x+376,96);
line(pos_x+112,92,pos_x+382,92);
line(pos_x+118,88,pos_x+388,88);
line(pos_x+124,84,pos_x+394,84);
line(pos_x+376,96,pos_x+376,436);
line(pos_x+382,92,pos_x+382,432);
line(pos_x+388,88,pos_x+388,428);
line(pos_x+394,84,pos_x+394,424);

//----- Doraemon -----//
strokeWeight(3);
stroke(#325D87);
//----- face -----//
fill(#4F81BC);
ellipse(pos_x+235,320,200,175);
fill(255);
ellipse(pos_x+235,334,140,125);

//----- eyes -----//
fill(255);
ellipse(pos_x+215,274,37,50);
ellipse(pos_x+255,274,37,50);
fill(#325D87);
ellipse(pos_x+220,279,8,8);
strokeWeight(4);
arc(pos_x+248,281,6,6,PI,TWO_PI);
strokeWeight(3);

//----- nose -----//
fill(#FE0000);
ellipse(pos_x+235,301,20,20);

//----- mounth -----//
noFill();
arc(pos_x+235,350,100,50,0,PI);
line(pos_x+235,312,pos_x+235,375);

//----- Whiskers -----//
line(pos_x+220,320,pos_x+177,315);
line(pos_x+220,325,pos_x+175,325);
line(pos_x+220,330,pos_x+177,335);

line(pos_x+250,320,pos_x+293,315);
line(pos_x+250,325,pos_x+295,325);
line(pos_x+250,330,pos_x+293,335);

//----- collar -----//
fill(#FD0000);
rect(pos_x+185,395,100,13);

//----- bell -----//
fill(#FCBE0C);
ellipse(pos_x+235,394,20,20);

//----- hands -----//
fill(255);
ellipse(pos_x+180,395,30,28);
ellipse(pos_x+290,395,30,28);

}

Lab2 Capt (Function)

30 สิงหาคม 2558

Lab2 Battery Sign (function)







float move = 0;
float size_draw=80;

void setup(){
size(500,150);
background(0);
frameRate(60);
}

void draw(){
float end_point = width-(size_draw*0.6)-(width/2);
draw_batt(move);
move = (move+2)%width;
if (move>end_point) {
move=-end_point;
}
}

void draw_batt(float pos_x){
background(0);
//-----Battery-----//
rectMode(CENTER);
strokeWeight(size_draw*0.02);
stroke(#4A4A4A);
noFill();
rect(pos_x+width/2,height/2,size_draw,size_draw*0.6,size_draw*0.05);//Batery body
rect(pos_x+(width/2)+(size_draw/2)+((size_draw*0.1)/2),height/2,size_draw*0.1,size_draw*0.2);//Battery terminal
noStroke();
fill(#029AE9);
rect(pos_x+(width/2)-(size_draw*0.7),height/2,size_draw*0.2,size_draw*0.1);//Negative terminal
fill(#E10203);
rect(pos_x+(width/2)+(size_draw*0.8),height/2,size_draw*0.2,size_draw*0.1);//Positive terminal
rect(pos_x+(width/2)+(size_draw*0.8),height/2,size_draw*0.1,size_draw*0.2);

//-----Energy battery-----//
rectMode(CORNER);
noStroke();
fill(#8EF608);
rect(pos_x+(width/2)-((size_draw*0.9)/2),(height/2)-((size_draw*0.5)/2),size_draw*0.9,size_draw*0.5,size_draw*0.02);

}

void mousePressed() {
if (mouseButton == LEFT) {
size_draw+=5;
} else if (mouseButton == RIGHT){
size_draw-=5;
}
}

Lab2 Positive Sign (Function)







float move = 0;
float size_draw=80;

void setup() {
frameRate(30);
size(400, 200);
background(#FCFAD3);
rectMode(CENTER);
}

void draw() {
Positive_Sign(move);
float end_point = width-(size_draw*0.6)-(width/2);
move = (move+2)%width;
if (move>end_point) {
move=-end_point;
}
}



void Positive_Sign(float pos_x) {
//----- Circle 1 -----//
background(#FCFAD3);
noStroke();
fill(0);
ellipse(pos_x+width/2, height/2, size_draw*1.2, size_draw*1.2);

//----- Circle 2 -----//
stroke(#48494C);
strokeWeight((((size_draw*1.2)-size_draw)/2)*0.32);
ellipse(pos_x+width/2, height/2, size_draw*1.1, size_draw*1.1);

//----- Circle 3 -----//
noStroke();
fill(#FD3A3B);
ellipse(pos_x+width/2, height/2, size_draw, size_draw);

//----- Positive Sign -----//
fill(255);
rect(pos_x+width/2, height/2, size_draw*0.8, size_draw*0.2, size_draw*0.02); //Horizontal Rectangle
rect(pos_x+width/2, height/2, size_draw*0.2, size_draw*0.8, size_draw*0.02); //Vertical Rectangle
}