int posX=35, posY=30;
float resize=150; //changeable
float charge=100;
boolean charging=false;
void draw() {
size(350,250);
background(130,120,240); //light_blue
batteryTank();
positive();
negative();
if(charging){
charge++;
draw_lightning();
}
else if(charge<=20) draw_exclamation();
if(charge>=100){
charge=100;
charging=false;
}
}
void batteryTank(){
float chargeW;
fill(255);
textSize(resize/10);
text("Battery: "+charge+"%",posX+resize/100*25*2.25,posY+resize/100*125);
//tank
strokeWeight(3);
fill(130); //gray
rect(posX,posY,resize/100*80*2.25,resize/100*100,resize/100*5*2.25);
rect(posX+resize/100*80*2.25,posY+resize/100*30,resize/100*3*2.25,resize/100*40);
fill(150);
rect(posX+resize/100*2.5*2.25,posY,resize/100*75*2.25,resize,resize/100*2*2.25);
//power
chargeW=charge/100*resize/100*75*2.25;
fill(#38E82C); //green
rect(posX+resize/100*2.5*2.25,posY,chargeW,resize,resize/100*2*2.25);
}
void positive(){
noStroke();
fill(#DE1F1F); //red
rect(posX+1.75*resize,posY+resize,resize/10,resize*0.4);
rect(posX-75*resize/500+1.75*resize,posY+75*resize/500+resize,resize*0.4,resize/10);
stroke(0);
}
void negative(){
noStroke();
fill(#1752CE); //blue
rect(posX-75*resize/500+0.1*resize,posY+75*resize/500+resize,resize*0.4,resize/10);
stroke(0);
}
void draw_lightning(){
noStroke();
fill(#FFE000);
beginShape();
vertex(posX+resize*0.9,posY+resize/2-resize*0.35); //posX+resize*0.9 = 105 ,,, posY+resize/2
vertex(posX+resize*0.9,posY+resize/2-resize*0.07);
vertex(posX+resize*0.9+resize/10,posY+resize/2-resize*0.07);
vertex(posX+resize*0.9,posY+resize/2+resize*0.35);
vertex(posX+resize*0.9,posY+resize/2+resize*0.07);
vertex(posX+resize*0.9-resize/10,posY+resize/2+resize*0.07);
endShape();
stroke(0);
}
void draw_exclamation(){
noStroke();
fill(#FF0000);
if(frameCount%40>20){
quad(posX+resize-resize/6,posY+resize/2-resize/5,posX+resize-resize/30,posY+resize/2-resize/5,
posX+resize-resize/15,posY+resize/2+resize/15,posX+resize-resize/7.5,posY+resize/2+resize/15);
rect(posX+resize-resize/7.5,posY+resize/2+resize/7.5,resize/15,resize/15);
}
stroke(0);
}
void mouseMoved(){
if(!charging){
charge-=0.5;
if(charge<=0) charge=0;
}
}
void mouseClicked(){
charging=true;
}
กันยายน 06, 2558
กันยายน 01, 2558
Lab3_balloon(lecture)
void draw(){
size(150,400);
background(255);
draw_balloon();
}
void draw_balloon(){
int posY=mouseY;
color ball;
if(mouseY<=50){
posY=50;
ball=#00FF00;
}
else if(mouseY>=300){
posY=300;
ball=#FF0000;
}
else ball=255;
strokeWeight(1.5);
fill(ball);
line(width/2,posY,width/2,posY+100);
ellipse(width/2,posY,50,50);
}
size(150,400);
background(255);
draw_balloon();
}
void draw_balloon(){
int posY=mouseY;
color ball;
if(mouseY<=50){
posY=50;
ball=#00FF00;
}
else if(mouseY>=300){
posY=300;
ball=#FF0000;
}
else ball=255;
strokeWeight(1.5);
fill(ball);
line(width/2,posY,width/2,posY+100);
ellipse(width/2,posY,50,50);
}
Lab2_book
int wink=1;
void setup(){
size(300,400);
frameRate(3);
}
void draw(){
background(0); //colorBlack
draw_book();
}
void draw_book(){
int posX=155, posY=150;
wink %= 2;
//bones
fill(255); //colorWhite
noStroke();
beginShape();
vertex(posX-90,posY-110);
vertex(posX+110,posY+90);
vertex(posX+110,posY+110);
vertex(posX+90,posY+110);
vertex(posX-110,posY-90);
vertex(posX-110,posY-110);
endShape();
beginShape();
vertex(posX+90,posY-110);
vertex(posX-110,posY+90);
vertex(posX-110,posY+110);
vertex(posX-90,posY+110);
vertex(posX+110,posY-90);
vertex(posX+110,posY-110);
endShape();
ellipse(posX-100,posY-120,30,30);
ellipse(posX-120,posY-100,30,30);
ellipse(posX+100,posY-120,30,30);
ellipse(posX+120,posY-100,30,30);
ellipse(posX+120,posY+100,30,30);
ellipse(posX+100,posY+120,30,30);
ellipse(posX-100,posY+120,30,30);
ellipse(posX-120,posY+100,30,30);
//skull & hat
stroke(0);
strokeWeight(4);
ellipse(posX,posY+90,80,90);
fill(145,55,25); //colorBrown
arc(posX,posY,170,170,PI+PI/16,TWO_PI-PI/16);
fill(255,210,50); //colorYellow
arc(posX,posY,170,170,PI+PI/7,TWO_PI-PI/7);
arc(posX,posY+30,320,115,PI+PI/5,TWO_PI-PI/5);
fill(255); //colorWhite
arc(posX,posY,170,170,0,PI);
arc(posX,posY,170,30,PI,TWO_PI);
//detail
fill(0);
ellipse(posX,posY+60,20,20); //nose
ellipse(posX+35,posY+25,50,50*wink); //R-eye
ellipse(posX-35,posY+25,50,50*wink); //L-eye
noFill();
arc(posX,posY,195,195,HALF_PI-PI/8,HALF_PI+PI/8);
arc(posX,posY,220,220,HALF_PI-PI/8+PI/48,HALF_PI+PI/8-PI/48);
line(posX-20,posY+85,posX-23,posY+105);
line(posX,posY+85,posX,posY+110);
line(posX+20,posY+85,posX+23,posY+105);
//book
strokeWeight(3);
stroke(100); //lncolorGray
arc(5,400,16,50,HALF_PI,3*PI/2);
line(8,0,8,375);
line(8,375,300,375);
line(7,380,300,380);
line(6,385,300,385);
line(5,390,300,390);
line(4,395,300,395);
wink++;
}
void setup(){
size(300,400);
frameRate(3);
}
void draw(){
background(0); //colorBlack
draw_book();
}
void draw_book(){
int posX=155, posY=150;
wink %= 2;
//bones
fill(255); //colorWhite
noStroke();
beginShape();
vertex(posX-90,posY-110);
vertex(posX+110,posY+90);
vertex(posX+110,posY+110);
vertex(posX+90,posY+110);
vertex(posX-110,posY-90);
vertex(posX-110,posY-110);
endShape();
beginShape();
vertex(posX+90,posY-110);
vertex(posX-110,posY+90);
vertex(posX-110,posY+110);
vertex(posX-90,posY+110);
vertex(posX+110,posY-90);
vertex(posX+110,posY-110);
endShape();
ellipse(posX-100,posY-120,30,30);
ellipse(posX-120,posY-100,30,30);
ellipse(posX+100,posY-120,30,30);
ellipse(posX+120,posY-100,30,30);
ellipse(posX+120,posY+100,30,30);
ellipse(posX+100,posY+120,30,30);
ellipse(posX-100,posY+120,30,30);
ellipse(posX-120,posY+100,30,30);
//skull & hat
stroke(0);
strokeWeight(4);
ellipse(posX,posY+90,80,90);
fill(145,55,25); //colorBrown
arc(posX,posY,170,170,PI+PI/16,TWO_PI-PI/16);
fill(255,210,50); //colorYellow
arc(posX,posY,170,170,PI+PI/7,TWO_PI-PI/7);
arc(posX,posY+30,320,115,PI+PI/5,TWO_PI-PI/5);
fill(255); //colorWhite
arc(posX,posY,170,170,0,PI);
arc(posX,posY,170,30,PI,TWO_PI);
//detail
fill(0);
ellipse(posX,posY+60,20,20); //nose
ellipse(posX+35,posY+25,50,50*wink); //R-eye
ellipse(posX-35,posY+25,50,50*wink); //L-eye
noFill();
arc(posX,posY,195,195,HALF_PI-PI/8,HALF_PI+PI/8);
arc(posX,posY,220,220,HALF_PI-PI/8+PI/48,HALF_PI+PI/8-PI/48);
line(posX-20,posY+85,posX-23,posY+105);
line(posX,posY+85,posX,posY+110);
line(posX+20,posY+85,posX+23,posY+105);
//book
strokeWeight(3);
stroke(100); //lncolorGray
arc(5,400,16,50,HALF_PI,3*PI/2);
line(8,0,8,375);
line(8,375,300,375);
line(7,380,300,380);
line(6,385,300,385);
line(5,390,300,390);
line(4,395,300,395);
wink++;
}
Lab2_movie
int posX=100,posY=100;
int speed=1,assist=1;
void draw(){
size(250,250);
background(#FA2B2B); //red
draw_movie();
}
void draw_movie(){
strokeWeight(3);
stroke(100); //lnColorGray
fill(0); //colorBlack
quad(posX-95,posY+115,posX+145,posY+115,posX+109,posY+19,posX-59,posY+19); //wing
arc(posX+25,posY-90,550,455,HALF_PI-PI/7,HALF_PI+PI/7); //wing
quad(posX-53,posY+15,posX+103,posY+15,posX+75,posY+125,posX-25,posY+125); //face
arc(posX+25,posY-10,160,160,PI-PI/8,TWO_PI+PI/8); //head
quad(posX+37,posY+21,posX+90,posY+21,posX+145,posY+115,posX+112,posY+15);
quad(posX+13,posY+21,posX-40,posY+21,posX-95,posY+115,posX-63,posY+15);
arc(posX+75,posY+20,75,60,PI,TWO_PI); //R-eyebrow
arc(posX-25,posY+20,75,60,PI,TWO_PI); //L-eyebrow
fill(255); //colorWhite
ellipse(posX+55,posY+45,70,35); //R-eye
ellipse(posX-5,posY+45,70,35); //L-eye
fill(0);
triangle(posX-25,posY+125,posX+75,posY+125,posX+25,posY+65); //mouth
stroke(255); //lnColorWhite
line(posX-9,posY+108,posX-9,posY+125);
line(posX+8,posY+88,posX+8,posY+125);
line(posX+25,posY+80,posX+25,posY+125);
line(posX+42,posY+88,posX+42,posY+125);
line(posX+59,posY+108,posX+59,posY+125);
stroke(100);
fill(255);
rect(posX+13,posY+65,25,15); //nose
fill(0);
rect(posX+15,posY-92,20,145);
quad(posX+15,posY+53,posX+35,posY+53,posX+38,posY+65,posX+13,posY+65);
arc(posX+25,posY+125,100,40,0,PI); //chin
fill(255);
ellipse(posX+70,posY+125,10,10);
ellipse(posX-20,posY+125,10,10);
posX+=speed;
posX %= 250;
}
void mouseClicked(){
assist*=(-1);
speed+=assist;
}
int speed=1,assist=1;
void draw(){
size(250,250);
background(#FA2B2B); //red
draw_movie();
}
void draw_movie(){
strokeWeight(3);
stroke(100); //lnColorGray
fill(0); //colorBlack
quad(posX-95,posY+115,posX+145,posY+115,posX+109,posY+19,posX-59,posY+19); //wing
arc(posX+25,posY-90,550,455,HALF_PI-PI/7,HALF_PI+PI/7); //wing
quad(posX-53,posY+15,posX+103,posY+15,posX+75,posY+125,posX-25,posY+125); //face
arc(posX+25,posY-10,160,160,PI-PI/8,TWO_PI+PI/8); //head
quad(posX+37,posY+21,posX+90,posY+21,posX+145,posY+115,posX+112,posY+15);
quad(posX+13,posY+21,posX-40,posY+21,posX-95,posY+115,posX-63,posY+15);
arc(posX+75,posY+20,75,60,PI,TWO_PI); //R-eyebrow
arc(posX-25,posY+20,75,60,PI,TWO_PI); //L-eyebrow
fill(255); //colorWhite
ellipse(posX+55,posY+45,70,35); //R-eye
ellipse(posX-5,posY+45,70,35); //L-eye
fill(0);
triangle(posX-25,posY+125,posX+75,posY+125,posX+25,posY+65); //mouth
stroke(255); //lnColorWhite
line(posX-9,posY+108,posX-9,posY+125);
line(posX+8,posY+88,posX+8,posY+125);
line(posX+25,posY+80,posX+25,posY+125);
line(posX+42,posY+88,posX+42,posY+125);
line(posX+59,posY+108,posX+59,posY+125);
stroke(100);
fill(255);
rect(posX+13,posY+65,25,15); //nose
fill(0);
rect(posX+15,posY-92,20,145);
quad(posX+15,posY+53,posX+35,posY+53,posX+38,posY+65,posX+13,posY+65);
arc(posX+25,posY+125,100,40,0,PI); //chin
fill(255);
ellipse(posX+70,posY+125,10,10);
ellipse(posX-20,posY+125,10,10);
posX+=speed;
posX %= 250;
}
void mouseClicked(){
assist*=(-1);
speed+=assist;
}
Lab2_song
int limit=0;
int white=255;
int light_brown=#F7DEA7;
color screen;
color line=255;
void draw(){
size(350,185);
background(screen);
limit++;
limit %= 180;
draw_song();
}
void draw_song(){
int posX=100;
posX+=limit;
noStroke();
//draw"THE"
fill(line);
rect(posX-25,10,70,30); //blank"THE"
fill(screen);
rect(posX-25,15,7,25);
rect(posX-13,15,7,25); //T
rect(posX,10,15,12);
rect(posX,27,15,13); //H
rect(posX+20,10,3,30);
rect(posX+28,15,17,7);
rect(posX+28,27,17,8); //E
triangle(posX+33,10,posX+45,45,posX+45,10);
//draw"SCRIPT"
fill(line);
arc(45,75,60,60,HALF_PI,TWO_PI);
arc(45,131,70,70,HALF_PI+PI,TWO_PI+HALF_PI); //S
arc(130,105,110,110,QUARTER_PI+PI/32,TWO_PI-QUARTER_PI-PI/32); //C
rect(165,50,20,10);
rect(165,105,20,10);
arc(185,82.5,60,65,3*PI/2,5*PI/2);
quad(170,115,185,115,215,147,215,163); //R
rect(220,50,10,120); //I
rect(235,50,10,120);
rect(245,50,20,10);
rect(245,105,20,10);
arc(265,82.5,60,65,3*PI/2,5*PI/2); //P
quad(265,50,330,50,335,60,265,60);
rect(300,50,10,120); //T
fill(screen);
arc(45,76,40,40,HALF_PI,TWO_PI);
arc(45,131,50,50,HALF_PI+PI,TWO_PI+HALF_PI); //S
arc(130,105,90,90,QUARTER_PI,TWO_PI-QUARTER_PI); //C
triangle(147,50,155,80,155,50);
arc(185,82.5,40,45,3*PI/2,5*PI/2); //R
quad(220,65,230,60,230,65,220,70); //I
arc(265,82.5,40,45,3*PI/2,5*PI/2); //P
triangle(220,170,310,130,310,170);
fill(line);
rect(155,50,10,97); //R
}
void mouseClicked(){
//line
white*=-1;
line += white;
//screen
screen += light_brown;
light_brown*=-1;
}
int white=255;
int light_brown=#F7DEA7;
color screen;
color line=255;
void draw(){
size(350,185);
background(screen);
limit++;
limit %= 180;
draw_song();
}
void draw_song(){
int posX=100;
posX+=limit;
noStroke();
//draw"THE"
fill(line);
rect(posX-25,10,70,30); //blank"THE"
fill(screen);
rect(posX-25,15,7,25);
rect(posX-13,15,7,25); //T
rect(posX,10,15,12);
rect(posX,27,15,13); //H
rect(posX+20,10,3,30);
rect(posX+28,15,17,7);
rect(posX+28,27,17,8); //E
triangle(posX+33,10,posX+45,45,posX+45,10);
//draw"SCRIPT"
fill(line);
arc(45,75,60,60,HALF_PI,TWO_PI);
arc(45,131,70,70,HALF_PI+PI,TWO_PI+HALF_PI); //S
arc(130,105,110,110,QUARTER_PI+PI/32,TWO_PI-QUARTER_PI-PI/32); //C
rect(165,50,20,10);
rect(165,105,20,10);
arc(185,82.5,60,65,3*PI/2,5*PI/2);
quad(170,115,185,115,215,147,215,163); //R
rect(220,50,10,120); //I
rect(235,50,10,120);
rect(245,50,20,10);
rect(245,105,20,10);
arc(265,82.5,60,65,3*PI/2,5*PI/2); //P
quad(265,50,330,50,335,60,265,60);
rect(300,50,10,120); //T
fill(screen);
arc(45,76,40,40,HALF_PI,TWO_PI);
arc(45,131,50,50,HALF_PI+PI,TWO_PI+HALF_PI); //S
arc(130,105,90,90,QUARTER_PI,TWO_PI-QUARTER_PI); //C
triangle(147,50,155,80,155,50);
arc(185,82.5,40,45,3*PI/2,5*PI/2); //R
quad(220,65,230,60,230,65,220,70); //I
arc(265,82.5,40,45,3*PI/2,5*PI/2); //P
triangle(220,170,310,130,310,170);
fill(line);
rect(155,50,10,97); //R
}
void mouseClicked(){
//line
white*=-1;
line += white;
//screen
screen += light_brown;
light_brown*=-1;
}
สมัครสมาชิก:
ความคิดเห็น (Atom)