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(500,500);
}
void draw()
{
  background(255);
  for(int i=0;i<n;i++)
  {
    fill(c[i]);
    circle(x[i],y[i],30);
    y[i]--;
  }
}
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(500,500);
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;
  color c;
}
Bubble []b=new Bubble[1000];
int n=0;
void setup()
{
  size(1000,1000);
}
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++;
}











size(300,300);
int [][]table=
{
  {0,0,0,0,0},
  {1,1,1,0,1},
  {0,0,1,1,0},
  {0,0,1,1,0}};
 for(int i=0;i<4;i++)
  { for(int j=0;j<5;j++)
 {
   if(table[i][j]==1)fill(255,0,0);
   else fill(128);
   rect(j*50,i*50,50,50);
 }
  }




今天老師教的程式可以做出很多球挺療癒的!
程式碼不會不好懂,多看幾次便可理解了~

沒有留言:

張貼留言