2020年4月19日 星期日

養了一隻小龜叫Oreo_week04

今天的課程是「石頭掉落」

先製造出石頭並讓它往下掉!



int x = 0, y = 0;
void setup(){
  size(400,400);
}
void draw(){
  background(255);
  circle( x, y, 30);
  y+=2; ///控制石頭往下掉的速度 y++是往下掉  y--是往上飛
}
void mousePressed(){
  x = mouseX;
  y = mouseY;
}

變很多石頭往下墜落~




int []x ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;
int []y ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;
int n=0;
void setup(){
  size(400,400);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    circle( x[i], y[i], 30);
    y[i]+=2;
  }
}
void mousePressed(){
  x[n] = mouseX;
  y[n] = mouseY;
  n++;
}

下方為另一種寫法

int []x =new int [1000]; ///這是Java宣告陣列的寫法也是C#的方法
int []y =new int [1000]; /// C不是這樣用的
int n=0;
void setup(){
  size(400,400);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    circle( x[i], y[i], 30);
    y[i]+=2;
  }
}
void mousePressed(){
  x[n] = mouseX;
  y[n] = mouseY;
  n++;
}

最後可以讓石頭變很多顏色




int []x =new int [1000]; ///這是Java宣告陣列的寫法也是C#的方法
int []y =new int [1000]; /// C不是這樣用的
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) ); ///RGB隨機組合成不同顏色
  n++;
}

做一點變化甚至能讓他變成充氣的氣球!!!




int []x =new int [1000]; ///這是Java宣告陣列的寫法也是C#的方法
int []y =new int [1000]; /// C不是這樣用的
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]-=2;
  }
  if(mousePressed) r[n-1]++; /// 按下滑鼠則半徑++
}
void mousePressed(){
  x[n] = mouseX;
  y[n] = mouseY;
  r[n] = 10; \\\ 半徑預設為10
  c[n] = color(random(255) ,random(255) ,random(255) );
  n++;
}

下方為結構寫法

class Bubble{
  int x;
  int y;
  int r;
  color 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++;
}

課程結束。

沒有留言:

張貼留言