วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558
Lab 3 : Balloon
void setup(){
size(300,300);
}
void draw(){
background(#ffffff);
int posX=mouseX;
int posY=mouseY;
if(posY<100){
fill(#F28EED);
}else if(posY>=100 && posY<200){
fill(#B48EF2);
}else{
fill(#486FD8);
}
draw_balloon(posX,posY);
}
void draw_balloon(int posX,int posY){
strokeWeight(4);
stroke(#623936);
int string_length =70;
line(posX,posY,posX,posY+ string_length);
ellipse(posX,posY,50,50);
}
Lab 2 : Syntax Error
สาเหตุ
เกิดจากการลืมใส่เครื่องหมาย " ; "
วิธีแก้ปัญหา
ตรวจสอบบรรทัดที่โปรแกรมเตือน Syntax Error และเติมเครื่องหมายให้ถูกต้อง
2.The variable "PercentBatt" does not exist
สาเหตุ
พิมชื่อตัวแปรผิด ประกาศตัวแปรไว้ไม่ตรงกับ local ที่เราใช้ หรือไม่ได้ประกาศตัวแปร
วิธีแก้ปัญหา
ตรวจสอบชื่อตัวแปร แก้ชื่อตัวแปรให้ตรงกับที่ประกาศไว้ถ้ายังไม่ได้ประกาศตัวแปร ก็ทำการประกาศให้ตรงกับ local ที่ใช้
3.The local variable "posX" may not have been intialized
สาเหตุ
เกิดจากการที่ยังให้ได้กำหนดค่าให้ตัวแปร
วิธีแก้ปัญหา
กำหนดค่าให้ตัวแปรที่โปรแกรมแจ้งเตือน
Lab 2 : Function Positive
void setup(){
size(400,400);
frameRate(10);
}
void draw(){
background(0);
//float fill_pos=random(0,255);
draw_positive(mouseX,mouseY,50);
}
void draw_positive(int X,int Y,int sizePos){
fill(#D8D8D8); //shadow
noStroke();
rect(X+sizePos+3,Y+3,sizePos+3,sizePos*3+3);
rect(X+3,Y+sizePos+3,sizePos*3+3,sizePos+3);
float fill_pos1=random(0,255);
float fill_pos2=random(0,255);
float fill_pos3=random(0,255);
noStroke(); //positive
fill(fill_pos1,fill_pos2,fill_pos3);
rect(X+sizePos,Y,sizePos,sizePos*3);
rect(X,Y+sizePos,sizePos*3,sizePos);
}
Lab 2 : Function Battary
int PercentBatt;
void setup(){
size(600,500);
}
void draw(){
background(#74A3FF);
int posX=100;
int posY=100;
draw_battary(posX,posY);
draw_positive(posX+450,posY);
draw_nagative(posX-70,posY);
textAlign(CENTER); //text
textSize(40);
fill(#ffffff);
text(PercentBatt+" %", 200+posX,270+posY);
}
void mousePressed(){
int increaseX;
int count=PercentBatt;
if(count<100){
increaseX=10;
PercentBatt = (PercentBatt + increaseX);
}if(count>=100){
PercentBatt =0;
}
}
void draw_battary(int posX,int posY) {
strokeWeight(10); //outside battary
stroke(#ffffff);
noFill();
rect(posX,posY,400,200);
rect(400+posX,45+posY,50,100); //battery terminal
noStroke(); //energy of battary
fill(#ffffff);
rect(10+posX,10+posY,PercentBatt*3.8,180);
}
void draw_positive(int posX,int posY){
rect(posX+10,posY, 10 ,30);
rect(posX,posY+10, 30,10);
}
void draw_nagative(int posX,int posY){
rect(posX,posY+10, 30,10);
}
Lab 2 : Clock
void setup(){
size(300, 300);
}
void draw(){
background(0);
draw_clock(width/4,height/3);
draw_time(width/2, height/2-20);
draw_date(width/2, height/2+20);
}
void draw_clock(int x,int y){
noStroke();
fill(#ffffff);
rect(x-5,y-5,150+10,90+10, 7);
fill(#8047FC);
rect(x,y,150,90, 7);
}
void draw_time(int x, int y){
fill(#ffffff);
textSize(20);
textAlign(CENTER);
text(hour()+":"+minute()+":"+second(), x, y);
}
void draw_date(int x, int y){
fill(#ffffff);
textSize(20);
textAlign(CENTER);
text(day()+"/"+month()+"/"+year(), x, y);
}
Lab 2 : Function book
int posX=0;
int posY=0;
void setup(){
size(600,600);
}
void draw(){
background(#FCFDFF);
//int posX=posX+2;
//int posY=posY+2;
draw_book(posX,posY);
posX=(posX+2)% width;
posY=(posY+2)%height;
}
void draw_book(int posX,int posY){
int x=455+posX;
int x2=5+posX;
int y=455+posY;
int y2=5+posY;
println("PUCCA");
print("2015");
strokeWeight(4); //front cover
fill(#FF1A29);
quad(posX,posY,450+posX,posY,450+posX,450+posY,posX,450+posY);
fill(#000000); //bun hair
ellipse(80+posX,100+posY,130,130);
ellipse(370+posX,100+posY,130,130);
fill(#FC4747); //ribbon
ellipse(315+posX,150+posY,80,80);
ellipse(125+posX,150+posY,80,80);
fill(#000000); //hair
ellipse(222+posX,210+posY,300,250);
fill(#FFF6C9); //face
ellipse(222+posX,230+posY,250,200);
strokeWeight(5); //eyes
line(110+posX,220+posY,170+posX,250+posY);
line(335+posX,220+posY,265+posX,250+posY);
noStroke(); //cheek
fill(#FFB6A2);
ellipse(310+posX,275+posY,25,25);
ellipse(133+posX,275+posY,25,25);
stroke(#000000); //mouth
noFill();
arc(220+posX, 280+posY, 40, 50, 0,PI);
fill(#FFF152); //Pucca
textSize(80);
textAlign(RIGHT);
text("PUCCA", 360+posX, 420+posY);
strokeWeight(2); //paper
line(x2,y,x,y);
line(x2+5,y+5,x+5,y+5);
line(x2+10,y+10,x+10,y+10);
line(x2+15,y+15,x+15,y+15);
line(x2+20,y+20,x+20,y+20);
line(x,y2,x,y);
line(x+5,y2+5,x+5,y+5);
line(x+10,y2+10,x+10,y+10);
line(x+15,y2+15,x+15,y+15);
line(x+20,y2+20,x+20,y+20);
line(posX,450+posY,25+posX,475+posY);
line(450+posX,posY,475+posX,25+posY);
}
Lab 2 : Function Music
int posX=0;
int posY=0;
void setup(){
size(600,600);
}
void draw(){
background(0);
//int posX=posX+2;
//int posY=posY+2;
draw_linkin(posX,posY);
}
void keyPressed(){
int dx = 5;
posX = (posX + dx) % width;
int dy = 5;
posY = (posY + dy) % height;
}
void draw_linkin(int posX,int posY){
fill(#ffffff);
ellipse(240+posX,240+posY,450,450); //inside circle
fill(#000000);
ellipse(240+posX,240+posY,400,400);
fill(#ffffff);
triangle(240+posX,70+posY,90+posX,340+posY,390+posX,340+posY); //triangle
fill(#000000);
triangle(240+posX,120+posY,130+posX,320+posY,350+posX,320+posY);
strokeWeight(30); //black line
stroke(#000000);
line(260+posX,posY-10,114+posX,260+posY);
line(287+posX,70+posY,183+posX,260+posY);
line(295+posX,70+posY,185+posX,260+posY);
line(200+posX,360+posY,148+posX,450+posY);
stroke(#ffffff); //white line
line(275+posX,165+posY,138+posX,408+posY);
strokeWeight(5); //outside circle
noFill();
ellipse(240+posX,240+posY,470,470);
}
Lab 2 : Function Movie
void setup() {
size(600,600);
}
void draw(){
background(#FFEC85);
//int posX=posX+2;
//int posY=posY+2;
draw_bear(mouseX,50);
draw_bear(mouseX,400);
}
void draw_bear(int X,int Y){
int x=30;
int x2=270;
int y=170;
strokeWeight(6);
stroke(#624403);
fill(#E09A2C); //outside ear
ellipse(X,Y,130,130);
ellipse(290+X,Y,130,130);
fill(#FFE63D); //inside ear
ellipse(-10+X,20+Y,80,80);
ellipse(300+X,20+Y,80,80);
fill(#E09A2C); //face
ellipse(150+X,120+Y,340,280);
fill(#624403); //eye
ellipse(60+X,130+Y,20,30);
ellipse(235+X,130+Y,20,30);
noStroke(); //nose
fill(#ffffff);
ellipse(150+X,175+Y,110,80);
fill(#624403);
ellipse(150+X,160+Y,25,20);
noFill(); //mouth
stroke(#624403);
arc(178+X,170+Y,55,55,HALF_PI,PI);
arc(122+X,170+Y,55,55,0,HALF_PI);
stroke(#FA4A46); //left cheek
line(x-15+X,y+Y,x-25+X,y+20+Y);
line(x+X,y+Y,x-10+X,y+20+Y);
line(x+15+X,y+Y,x+5+X,y+20+Y);
line(x2-15+X,y+Y,x2-25+X,y+20+Y); //right cheek
line(x2+X,y+Y,x2-10+X,y+20+Y);
line(x2+15+X,y+Y,x2+5+X,y+20+Y);
}
Lab 2 : Function BMI
void setup(){
size(300,200);
float myWeight=50;
float myHeight=160;
float myBMI=BMI(myHeight,myWeight);
textAlign(CENTER); //text
textSize(20);
fill(#ffffff);
text("Height = "+myHeight,150,50);
text("Weight = "+myWeight,150,100);
textAlign(LEFT);
text("Body Mass Index = "+myBMI,20,150);
}
float BMI(float myHeight,float myWeight){
float Height_M=myHeight/100;
float myBMI=myWeight/(Height_M*Height_M);
return myBMI;
}
Lab 2 : Function Circle
void setup() {
size(300, 200);
background(#74A3FF);
float r=10;
float circumference=cal_circumference(r);
float area=cal_area(r);
textAlign(LEFT); //text
textSize(20);
fill(#ffffff);
text("Radius = "+r, 150, 50);
text("Circumference = "+circumference, 150, 100);
text("Area = "+area, 150, 150);
}
float cal_circumference(float r) {
float circumference=PI*r*2;
return circumference;
}
float cal_area(float r) {
float area=PI*r*r;
return area;
}
วันอาทิตย์ที่ 23 สิงหาคม พ.ศ. 2558
Lab1 : Move Book
void setup() {
size(600,600);
background(#ffffff);
int posX=0; //move
int posY=0;
int x=455+posX;
int x2=5+posX;
int y=455+posY;
int y2=5+posY;
println("PUCCA");
print("2015");
strokeWeight(4); //front cover
fill(#FF1A29);
quad(posX,posY,450+posX,posY,450+posX,450+posY,posX,450+posY);
fill(#000000); //bun hair
ellipse(80+posX,100+posY,130,130);
ellipse(370+posX,100+posY,130,130);
fill(#FC4747); //ribbon
ellipse(315+posX,150+posY,80,80);
ellipse(125+posX,150+posY,80,80);
fill(#000000); //hair
ellipse(222+posX,210+posY,300,250);
fill(#FFF6C9); //face
ellipse(222+posX,230+posY,250,200);
strokeWeight(5); //eyes
line(110+posX,220+posY,170+posX,250+posY);
line(335+posX,220+posY,265+posX,250+posY);
noStroke(); //cheek
fill(#FFB6A2);
ellipse(310+posX,275+posY,25,25);
ellipse(133+posX,275+posY,25,25);
stroke(#000000); //mouth
noFill();
arc(220+posX, 280+posY, 40, 50, 0,PI);
fill(#FFF152); //Pucca
textSize(80);
textAlign(RIGHT);
text("PUCCA", 360+posX, 420+posY);
strokeWeight(2); //paper
line(x2,y,x,y);
line(x2+5,y+5,x+5,y+5);
line(x2+10,y+10,x+10,y+10);
line(x2+15,y+15,x+15,y+15);
line(x2+20,y+20,x+20,y+20);
line(x,y2,x,y);
line(x+5,y2+5,x+5,y+5);
line(x+10,y2+10,x+10,y+10);
line(x+15,y2+15,x+15,y+15);
line(x+20,y2+20,x+20,y+20);
line(posX,450+posY,25+posX,475+posY);
line(450+posX,posY,475+posX,25+posY);
}
Lab1 : Move Linkkinpark
void setup() {
size(600,600);
background(#000000);
println("THE");
print("Linkin Park");
int posX=100; //move
int posY=100;
ellipse(240+posX,240+posY,450,450); //inside circle
fill(#000000);
ellipse(240+posX,240+posY,400,400);
fill(#ffffff);
triangle(240+posX,70+posY,90+posX,340+posY,390+posX,340+posY); //triangle
fill(#000000);
triangle(240+posX,120+posY,130+posX,320+posY,350+posX,320+posY);
strokeWeight(30); //black line
stroke(#000000);
line(262+posX,posY-10,116+posX,260+posY);
line(284+posX,70+posY,180+posX,260+posY);
line(295+posX,70+posY,185+posX,260+posY);
line(200+posX,360+posY,148+posX,450+posY);
stroke(#ffffff); //white line
line(275+posX,165+posY,138+posX,408+posY);
strokeWeight(5); //outside circle
noFill();
ellipse(240+posX,240+posY,470,470);
}
Lab1 : Resize Rilakuma
void setup() {
size(600,600);
background(#FFEC85);
println("I");
println("love");
print("Rilakkuma");
int resize=-20;
int x=180;
int x2=420;
int y=370;
strokeWeight(6);
stroke(#624403);
fill(#E09A2C); //outside ear
ellipse(150,200,150+resize,150+resize);
ellipse(440,200,150+resize,150+resize);
fill(#FFE63D); //inside ear
ellipse(140,220,100+resize,100+resize);
ellipse(450,220,100+resize,100+resize);
fill(#E09A2C); //face
ellipse(300,320,360+resize,300+resize);
fill(#624403); //eye
ellipse(210,330,30+resize/2,40+resize/2);
ellipse(385,330,30+resize/2,40+resize/2);
noStroke(); //nose
fill(#ffffff);
ellipse(300,375,120+resize/2,90+resize/2);
fill(#624403);
ellipse(300,360,35+resize/2,30+resize/2);
noFill(); //mouth
stroke(#624403);
arc(328,370,55,55,HALF_PI,PI);
arc(272,370,55,55,0,HALF_PI);
stroke(#FA4A46); //left cheek
line(x-15,y,x-25,y+20);
line(x,y,x-10,y+20);
line(x+15,y,x+5,y+20);
line(x2-15,y,x2-25,y+20); //right cheek
line(x2,y,x2-10,y+20);
line(x2+15,y,x2+5,y+20);
}
วันเสาร์ที่ 22 สิงหาคม พ.ศ. 2558
Lab1 : BMI
void setup(){
size(500,300);
background(#B454F5);
float W=55; //Weight
float H_cm=165; //height(centimeter)
float H_m=H_cm/100; //height(meter)
float BMI; //BMI
BMI=W/(H_m*H_m);
textAlign(CENTER); //text
textSize(30);
fill(#ffffff);
text("Height = "+H_cm,250,50);
text("Weight = "+W,250,150);
textAlign(LEFT);
text("Body Mass Index = "+BMI,50,250);
}
Lab1 : Circle
void setup(){
size(400,500);
background(#FF8774);
float radius=150; //radius
float cir=2*PI*radius; //circumference
float area=PI*radius*radius; //area
ellipse(200,200,radius*2,radius*2); //circle
textAlign(CENTER); //text
textSize(20);
fill(#ffffff);
text("Radius = "+radius,200,420);
text("Circumference = "+cir,200,450);
text("Area = "+area,200,480);
}
Lab1 : Positive
void setup(){
size(400,400);
background(#3A3B3E);
int posX=60; //moveX
int posY=60; //moveY
int Size=50; //resize
int X2=50+Size;
int Y2=X2+120+Size;
fill(#ffffff); //shadow
noStroke();
rect(posX+65+Size/2,posY+5,X2,Y2);
rect(posX+5,posY+65+Size/2,Y2,X2);
fill(#85F5EA); //positive
noStroke();
rect(posX+60+Size/2,posY+3,X2,Y2-3);
rect(posX+3,posY+60+Size/2,Y2-3,X2);
}
Lab1 : Battary
void setup() {
size(600, 500);
background(#36F59A);
int resize=0;
int posX=100; //move
int posY=100;
float PercentBatt=100; //Percent of battary
strokeWeight(10); //outside battary
stroke(#ffffff);
noFill();
rect(posX,posY,400+resize,200+resize);
rect(400+posX+resize,45+posY,50+resize/2,100+resize); //battery terminal
noStroke(); //energy of battary
fill(#ffffff);
rect(10+posX,10+posY,PercentBatt*3.8+resize,180+resize);
textAlign(CENTER); //text
textSize(40+resize/2);
fill(#ffffff);
text(PercentBatt+" %", 200+posX+resize,270+posY+resize);
}
วันอาทิตย์ที่ 16 สิงหาคม พ.ศ. 2558
Lab 0 : My favorite book
void setup() {
size(600,600);
background(#ffffff);
int x=505;
int x2=55;
int y=505;
int y2=55;
println("PUCCA");
print("2015");
strokeWeight(4); //front cover
fill(#FF1A29);
quad(50,50,500,50,500,500,50,500);
fill(#000000); //bun hair
ellipse(130,150,130,130);
ellipse(420,150,130,130);
fill(#FC4747); //ribbon
ellipse(365,200,80,80);
ellipse(175,200,80,80);
fill(#000000); //hair
ellipse(272,260,300,250);
fill(#FFF6C9); //face
ellipse(272,280,250,200);
strokeWeight(5); //eyes
line(160,270,220,300);
line(385,270,315,300);
noStroke(); //cheek
fill(#FFB6A2);
ellipse(360,325,25,25);
ellipse(183,325,25,25);
stroke(#000000); //mouth
noFill();
arc(270, 340, 40, 50, 0,PI);
fill(#FFF152); //Pucca
textSize(80);
textAlign(RIGHT);
text("PUCCA", 410, 470);
strokeWeight(2); //paper
line(x2,y,x,y);
line(x2+5,y+5,x+5,y+5);
line(x2+10,y+10,x+10,y+10);
line(x2+15,y+15,x+15,y+15);
line(x2+20,y+20,x+20,y+20);
line(x,y2,x,y);
line(x+5,y2+5,x+5,y+5);
line(x+10,y2+10,x+10,y+10);
line(x+15,y2+15,x+15,y+15);
line(x+20,y2+20,x+20,y+20);
line(50,500,75,525);
line(500,50,525,75);
}
Lab 0 : My favorite song
void setup() {
size(600,600);
background(#000000);
println("THE");
print("Linkin Park");
ellipse(300,300,450,450); //inside circle
fill(#000000);
ellipse(300,300,400,400);
fill(#ffffff);
triangle(300,130,150,400,450,400); //triangle
fill(#000000);
triangle(300,180,190,380,410,380);
strokeWeight(30); //black line
stroke(#000000);
line(322,50,176,320);
line(344,130,240,320);
line(355,130,245,320);
line(260,420,208,510);
stroke(#ffffff); //white line
line(335,225,198,468);
strokeWeight(5); //outside circle
noFill();
ellipse(300,300,470,470);
}
วันพุธที่ 12 สิงหาคม พ.ศ. 2558
Lab 0 : My Favorite Movie
void setup() {
size(600,600);
background(#FFEC85);
println("I");
println("love");
print("Rilakkuma");
int x=180;
int x2=420;
int y=370;
strokeWeight(6);
stroke(#624403);
fill(#E09A2C); //outside ear
ellipse(150,200,150,150);
ellipse(440,200,150,150);
fill(#FFE63D); //inside ear
ellipse(140,220,100,100);
ellipse(450,220,100,100);
fill(#E09A2C); //face
ellipse(300,320,360,300);
fill(#624403); //eye
ellipse(210,330,30,40);
ellipse(385,330,30,40);
noStroke(); //nose
fill(#ffffff);
ellipse(300,375,120,90);
fill(#624403);
ellipse(300,360,35,30);
noFill(); //mouth
stroke(#624403);
arc(328,370,55,55,HALF_PI,PI);
arc(272,370,55,55,0,HALF_PI);
stroke(#FA4A46); //left cheek
line(x-15,y,x-25,y+20);
line(x,y,x-10,y+20);
line(x+15,y,x+5,y+20);
line(x2-15,y,x2-25,y+20); //right cheek
line(x2,y,x2-10,y+20);
line(x2+15,y,x2+5,y+20);
}
สมัครสมาชิก:
บทความ (Atom)


