顯示具有 06160921_龔書霆 標籤的文章。 顯示所有文章
顯示具有 06160921_龔書霆 標籤的文章。 顯示所有文章

2020年6月18日 星期四

Week17

可以跟著滑鼠移動

會彈回去

會比較平滑的彈回去

變成像彈簧一樣

可以忽快忽慢

用上面的程式來寫餵魚的程式

2020年4月30日 星期四

week10

反敘數字

分式化簡

加分題




void setup(){
  size(300,500);
}
int r=0;
void draw(){
  background(0);
  ellipse(74,200+75,r,r);
  ellipse(74,200+75+150,r,r);
  ellipse(74+150,200+75,r,r);
  ellipse(74+150,200+75+150,r,r);
  if(r<145) r+=2;
  else r=0;
}



void setup(){
  size(300,500);
}
int r=0;
void draw(){
  background(0);
  for(int x=0;x<3;x++){
    for(int y=0;y<3;y++){
      ellipse(50+x*100,200+50+y*100,r,r);
    }
  }
  if(r<100) r+=2;
  else r=0;
}


2020年4月9日 星期四

2020年3月26日 星期四

Week04



程式碼:
int []x=new int[1000];
int []y=new int[1000];
color []c=new color[1000];
int n=0;
void setup(){
  size(400,400);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    fill(c[i]);
    circle(x[i],y[i],30);
    y[i]+=2;
  }
}
void mousePressed(){
  x[n]=mouseX;
  y[n]=mouseY;
  c[n]=color(random(255),random(255),random(255));
  n++;
}



程式碼:
int []x=new int[1000];
int []y=new int[1000];
int []r=new int[1000];
color []c=new color[1000];
int n=0;
void setup(){
  size(400,400);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    fill(c[i]);
    circle(x[i],y[i],r[i]);
    y[i]--;
  }
  if(mousePressed) r[n-1]++;
}
void mousePressed(){
  x[n]=mouseX;
  y[n]=mouseY;
  r[n]=10;
  c[n]=color(random(255),random(255),random(255));
  n++;
}



程式碼:

class Bubble{
  int x;
  int y;
  int r;
  int c;
}
Bubble [] b=new Bubble[1000];
int n=0;
void setup(){
  size(400,400);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    fill(b[i].c);
    circle(b[i].x,b[i].y,b[i].r);
    b[i].y--;
  }
  if(mousePressed) b[n-1].r++;
}
void mousePressed(){
  b[n]=new Bubble();
  b[n].x=mouseX;
  b[n].y=mouseY;
  b[n].r=10;
  b[n].c=color(random(255),random(255),random(255));
  n++;
}

分成兩頁程式碼



程式碼:
(1)
Bubble [] b=new Bubble[1000];
int n=0;
void setup(){
  size(400,400);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    b[i].drawAndUpdate();
  }
  if(mousePressed) b[n-1].r++;
}
void mousePressed(){
  b[n]=new Bubble(mouseX,mouseY,10);
  n++;
}

(2)
class Bubble{
  int x,y;
  int r;
  color c;
  Bubble(int _x,int _y,int _r){
    x=_x; y=_y;r=_r;
    c=color(random(255),random(255),random(255));
  }
  void drawAndUpdate(){
    fill(c);
    circle(x,y,r);
    y--;
  }
}



2020年3月19日 星期四

week03



程式碼:
PImage img0,img1,img2;
void setup(){
  size (900,900);
  img0=loadImage("1.png");
  img1=loadImage("2.png");
  img2=loadImage("3.png");
}
void draw(){
  background(128);
  image(img2,mouseX,mouseY);
}



程式碼:

PImage img0,img1,img2;
void setup(){
  size (900,900);
  img0=loadImage("1.png");
  img1=loadImage("2.png");
  img2=loadImage("3.png");
}
int userX=250,userY=250;
void draw(){
 
  background(128);
  if(keyPressed && keyCode==LEFT){
    image(img2,userX,userY);
    userX--;
  }
  else if(keyPressed && keyCode==RIGHT){
    image(img1,userX,userY);
    userX++;
  }
  else image(img0,userX,userY);
}



程式碼:

PImage img;
void setup(){
  size(484,624);
  img=loadImage("map.jpg");
}
int userX=122,userY=337;
void draw(){
  background(img);
  ellipse(userX,userY,40,55);
}
void keyPressed(){
  if(keyCode==UP)userY--;
  if(keyCode==RIGHT)userX++;
}



程式碼:

PImage img;
void setup(){
  size(484,624);
  img=loadImage("map.jpg");
}
int userX=122,userY=337;
int []bX={0,0,0,0,0};
int []bY={0,0,0,0,0};
int []bF={0,0,0,0,0};
int n=0;
void draw(){
  background(img);
  ellipse(userX,userY,40,55);
  for(int i=0;i<n;i++){
    if(bF[i]==1){
      ellipse(bX[i],bY[i],5,10);
      bY[i]-=2;
    }
  }
}
void keyPressed(){
  if(keyCode==UP)userY-=3;
  if(keyCode==RIGHT)userX+=3;
  if(keyCode==LEFT)userX-=3;
  if(keyCode==DOWN)userY+=3;
}
void mousePressed(){
  bX[n]=userX;
  bY[n]=userY;
  bF[n]=1;
  n++;
}

2020年3月12日 星期四

Week02

Week02

讓球從畫面最上面慢慢掉下來


程式碼:

int x=0,y=0;
void setup(){
  size(300,300);
}
void draw(){
  background(255);
  circle(x,y,10);
  y++;
  if(mousePressed){
    x=mouseX;
    y=mouseY;
 
  }
}

多掉幾顆球


程式碼:

int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int n=0;
void setup(){
  size(300,300);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    circle(x[i],y[i],10);
    y[i]++;
    if(y[i]>=300-5) y[i]=300-5;   
  }
 }
void mousePressed(){
    if(n<5){
      x[n]=mouseX;
      y[n]=mouseY;
      n++;
    }
}