2020年5月3日 星期日

孤獨月宮的花園

200501 week10

今天要來做個簡單的舒壓小遊戲


一開始就很複雜
















size(300,500);
ellipse(50,200+50,100,100);
ellipse(50+100,200+50,100,100);
ellipse(50+100+100,200+50,100,100);


ellipse(50,200+50+100,100,100);
ellipse(50+100,200+50+100,100,100);
ellipse(50+100+100,200+50+100,100,100);


ellipse(50,200+50+100+100,100,100);
ellipse(50+100,200+50+100+100,100,100);
ellipse(50+100+100,200+50+100+100,100,100);

先像這樣畫出3*3的的圓




甚麼!!你說太複雜?好吧,來個 3*3超簡單版本

















size(300,500);
for(int y=0;y<3;y++)
{
  for(int x=0;x<3;x++)
  {
    ellipse(50+x*100,200+50+y*100,100,100);
  }
}

我們利用for迴圈來做簡化



N*N個圓















size(300,500);
int n=300;
int R=300/n,w=R/2;
for(int y=0;y<n;y++)
{
  for(int x=0;x<n;x++)
  {
    ellipse(w+x*R,200+w+y*R,R,R);
  }
}













size(300,500);
int n=100;
int R=300/n,w=R/2;
for(int y=0;y<n;y++)
{
  for(int x=0;x<n;x++)
  {
    ellipse(w+x*R,200+w+y*R,R,R);
  }
}


讓球慢慢變
















void setup()
{
  size(300,500);
}
int n=5;
int R=300/n,w=R/2,RR=0;
void draw()
{
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      ellipse(w+x*R,200+w+y*R,RR,RR);
    }
  }
  RR++;
}


阿呀!修但幾勒!
他停不下來,變成很像浮世繪的場景



這才是正確版本(讓圓逐漸膨脹)













void setup()
{
  size(300,500);
}
int n=5;
int R=300/n,w=R/2,RR=0;
void draw()
{
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      ellipse(w+x*R,200+w+y*R,RR,RR);//從小變到大
    }
  }
  if(RR<R)RR++;
}



變得越來越多














void setup()
{
  size(300,500);
}
int n=3,RR=0;//會變動的R直徑,稱為RR
void draw()
{
  background(0);
  int R=300/n,w=R/2;
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      ellipse(w+x*R,200+w+y*R,RR,RR);//從小變到大
    }
  }
  if(RR<R)RR+=R/30;//如果還沒超過範圍,++從小變到大
  else
  {
    n++;下一個數目
    RR=0;//從小開始長
  }
}



知道誰不同














void setup()
{
  size(300,500);
}
int ansX=1,ansY=2;//答案
int n=3,RR=0;///會變動的R直徑,我們叫它RR
void draw()
{
  background(0);
  int R=300/n,w=R/2;
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      if(x==ansX&&y==ansY)fill(71);///答案要有點不同
      else fill(255);
      if( dist( mouseX, mouseY, w+x*R, 200+w+y*R)<w)fill(255,60,40);
      ellipse( w+x*R, 200+w+y*R, RR, RR);//從小變到大
    }
  }
  if(RR<R)RR+=R/30;//如果還沒超過範圍,++從小變到大
}//為了讓速度一致,改成RR+=R/10變成很快



遊戲完成了!!!大家一起來找不同顏色吧!
(有些還真的看不出來)













void setup()
{
  size(300,500);
  colorMode(HSB,256);//TODO:改色彩系統
}
int ansX=1,ansY=2;//答案
int n=3,RR=0;///會變動的R直徑,我們叫它RR
int H=0;
void draw()
{
  background(0);
  int R=300/n,w=R/2;
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      if(x==ansX&&y==ansY)fill(H-10,243,234);///答案要有點不同
      else fill(H,255,255);//TODO:改色彩系統
      if(dist(mouseX,mouseY,w+x*R,200+w+y*R)<w)///現在的mouse選中誰
      {
        if(mousePressed && x==ansX && y==ansY)///他剛好也是答案
        {
          ansX=int (random(n));
          ansY=int (random(n));
          H+=20;//TODO:改色彩系統
          if(H>256)H=0;
        }
      }
      ellipse(w+x*R,200+w+y*R,RR,RR);//從小變到大...
    }
  }
  if(RR<R)RR+=R/30;//如果還沒超過範圍,++從小變到大
}


以上就是今天的療癒小遊戲程式教學


這次又學到了製作一款簡單小遊戲,開心!





沒有留言:

張貼留言