2020年3月27日 星期五

柯基 week_04

1.

                                        PImage imgBG;
                            void setup()
                           {
                                              size(800,470);      (圖片大小要跟背景一樣)
                                           imgBG=loadImage("11.png");
                            }
                            void draw()
                           {
                                           background(imgBG);
                            }

2.


                                        (藍色是新加的城市)

                           PImage imgBG;
                           int []x={0,0,0,0,0};  (使用陣列)
                           int []y={0,0,0,0,0};
                           void setup()
                           {
                             size(800,470);
                           imgBG=loadImage("11.png");
                           }
                           void draw()
                           {
                             background(imgBG);
                             circle( x[0], y[0], 40)(畫圓)
                           }
                           void mousePressed()
                           {
                             x[0] =mouseX;    (滑鼠的座標)
                             y[0] =mouseY;
                           }


3.


                            PImage imgBG;
                            int []x={0,0,0,0,0};
                            int []y={0,0,0,0,0};
                            int n=0;   (子彈n,現在子彈是0)
                            void setup()
                           {
                              size(800,470);
                              imgBG=loadImage("11.png");
                            }
                            void draw()
                           {
                               background(imgBG);
                               for(int i=0;i<5;i++) (只有for裡才用 i )
                              {
                               circle( x[i], y[i], 40);
                               }
                            }
                            void mousePressed()
                            {
                               if(n>5) return;
                               x[n] =mouseX;  (滑鼠的這邊要用n,不用i)
                               y[n] =mouseY;
                               n = (n+1)%5;  (到第六顆時,會拿第一個來                                                           用)
                            }

4.


                              int[]a={1,1,1,0};  (1就會是紅色)
                              size(400,100);
                              for(int i=0;i<4;i++)
                              {
                                 if(a[i]==1)fill(255,0,0);
                                 else fill(128);
                                 rect(i*100,0,   100,100);
                              }


5.


                           int[][]a={
                           {1,1,1,1,0},
                           {0,1,0,1,0},          (5*5的陣列)
                           {0,1,0,1,0},
                           {0,1,0,0,0},
                           {0,1,0,0,0} };
                           size(500,500);

                           for(int i=0;i<5;i++)   (Y軸是i,X軸是j)

                           {
                              for(int j=0;j<5;j++)
                              {
                                 if(a[i][j]==1)fill(255,0,0);
                                 else fill(128);
                                 rect(j*100,i*100,   100,100);
                              }
                           }

6.


PImage imgBG;
int []x={0, 0, 0, 0, 0};
int []y={0, 0, 0, 0, 0};
int []r={5, 5, 5, 5, 5};    (球的陣列)
int n=0;   
void setup()
{
  size(800, 470);
  imgBG=loadImage("11.png");
}
void draw()
{
  background(imgBG);
  for (int i=0; i<5; i++)
  {
    circle( x[i], y[i], r[i]);
  }
  if(mousePressed) r[now]++;
}
int now=0;
void mousePressed()
{
  x[n] =mouseX;  
  y[n] =mouseY;
  r[n]=5;
  now=n;
  n = (n+1)%5; 
}


沒有留言:

張貼留言