2020年3月26日 星期四

程式設計 week04

int []x=new int [1000];///java語言宣告
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], 30);
        y[i]+=2;
    }
}
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(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;///半徑最大設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++;
}

class Bubble{
    int x;
    int y;
    int r;
    color c;
     Bubble (int _x, int _y,int _r){
       x=_x; y=_y; r=_r;
       c=color(random(255), random(255), random(255));
}
void drawAndUpdate(){
    fill(c);
    circle(x,y,r);
    y--;
  }

}



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);///i=y, j=x
    }
}

void setup(){
size(300,300);
}
void draw(){
    background(128);
    for(int i=0;i<6;i++){
        for(int j=0;j<6;j++){
            if(table[i][j]==1) fill(255,0,0);
            else fill(128);
            rect(j*50,i*50,50,50);
        }
    }
   }
  void mousePressed(){
      int x = (mouseX)/50;
      int y = (mouseY)/50;
      table[y][x]=1;
  }

沒有留言:

張貼留言