2020年3月26日 星期四

我要寫幾次部落格qq_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],r[i]);
  y[i]+=2;
  }
}
void mousePressed()
{
  x[n]=mouseX;
  y[n]=mouseY;
  c[n]=color(random(255),random(255),random(255));  ///RBG顏色隨機,最大值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]--;         ///y值減少向上,隕石往上飄
  }
  if(mousePressed) r[n-1]++;     //if滑鼠點擊,隕石半徑增加
}
void mousePressed()
{
  x[n]=mouseX;
  y[n]=mouseY;
  r[n]=10;
  c[n]=color(random(255),random(255),random(255));
  n++;
}


沒有留言:

張貼留言