int posX = 300;
int R = 255, G = 0, B = 0;
int x_axis_moved;
void setup() {
size(600, 400);
}
void draw() {
background(0);
logo(posX, 200);
}
Building Software Systems I & II
&
Computer Fundamentals
By Thakdanai Khunsaen
OS : Ubuntu GNOME 17.04 64-bit
วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558
Lab3-Bird
int wingFly;
int x= 30;
int birdSize = 150;
void setup() {
size(700, 500);
}
void draw() {
background(255);
wingFly = mouseY;
if (frameCount%x > x/2) {
wingFly += birdSize/3;
} else {
wingFly -= birdSize/3;
}
flybird(mouseX, mouseY, birdSize);
}
void keyPressed() {
if (key == 'z' || key == 'Z') {
birdSize -= 10;
if (birdSize <= 0) {
birdSize = 0;
}
}
if (key == 'x' || key == 'X') {
birdSize += 10;
if (birdSize >= height) {
birdSize = height;
}
}
}
void mouseClicked() {
if (mouseButton == LEFT) {
x -= 8;
if (x <= 0) {
x =4;
}
} else if (mouseButton == RIGHT) {
x += 8;
if (x >= 60) {
x = 60;
}
}
}
void flybird(int x, int y, int birdSize) {
strokeWeight(3);
fill(#FF00FF);
ellipse(x, y, birdSize, birdSize);
fill(0);
ellipse(x-(birdSize/5), y, birdSize/4, birdSize/3);
ellipse(x+(birdSize/5), y, birdSize/4, birdSize/3);
fill(255);
ellipse(x-(birdSize/5), y, birdSize/6, birdSize/5);
ellipse(x+(birdSize/5), y, birdSize/6, birdSize/5);
fill(#FFFF00);
triangle(x-(birdSize/4), y+(birdSize/4), x+(birdSize/4), y+(birdSize/4), x, y+birdSize/1.5);
line(x-(birdSize/2), y, x-birdSize, wingFly);
line(x+(birdSize/2), y, x+birdSize, wingFly);
}
LAb3-balloon
void setup(){
size(300,500);
}
void draw(){
background(255);
draw_balloon(mouseX,mouseY,100,100);
}
void draw_balloon(int x,int y,int balloonSize,int string){
fill(255);
if(x < 20 || x > 280 || y < 20 || y > 480){
fill(#DD0000);
}else{
fill(255);
}
ellipse(x,y,balloonSize,balloonSize);
line(x,y+balloonSize/2,x,(y+balloonSize/2)+string);
}
วันอังคารที่ 1 กันยายน พ.ศ. 2558
Lab2-Example Error
ปัญหา 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 (ชื่อตัวแปร);" ออก
สาเหตุ : เกิดจากการที่เราลืมใส่วงเล็บไม่ครบ มีวงเล็บเปิดไม่มีวงเล็บปิด เป็นต้น
วิธีแก้ : ใส่วงเล็บให้ครบ
ปัญหา 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 (ชื่อตัวแปร);" ออก
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);
}
สมัครสมาชิก:
บทความ (Atom)