2020年3月26日 星期四

程式設計重修哦 Week04

下面的color是球球裡面的顏色。(球球掉落)

讓球球往上跑
程式碼:
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++;
 }

下面是簡短程式的樣子。



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);
  }
}



沒有留言:

張貼留言