2020年3月27日 星期五

week04

Processing

發射子彈
PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
void setup()
{
  size (261,435);
  imgBG=loadImage("background.jpg");
}
void draw()
{
   background(imgBG);
   circle(x[0],y[0],40);
}
void mousePressed()
{
  x[0]=mouseX;
  y[0]=mouseY;
}

5顆子彈,但第六顆射不出來
PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int n=0;
void setup()
{
  size (261,435);
  imgBG=loadImage("background.jpg");
}
void draw()
{
   background(imgBG);
   for(int i=0;i<5;i++)
   {
     circle(x[i],y[i],40);
   }
}
void mousePressed()
{
  if(n>=5)return;
  x[n]=mouseX;
  y[n]=mouseY;
  n++;
}

PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int n=0;
void setup()
{
  size (261,435);
  imgBG=loadImage("background.jpg");
}
void draw()
{
   background(imgBG);
   for(int i=0;i<5;i++)
   {
     circle(x[i],y[i],40);
   }
}
void mousePressed()
{
  //if(n>=5)return;
  x[n]=mouseX;
  y[n]=mouseY;
  n=(n+1)%5;
}


int []a={1,1,1,0};
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);
}

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


沒有留言:

張貼留言