2024年12月2日 星期一

w13-coding-processing-programing-note

001. 

PImage [] img = new PImage[3];

void setup() {

  size(550, 370);

  img[0] = loadImage("snail01.png");

  img[1] = loadImage("snail02.png");

  img[2] = loadImage("snail03.png");

}

int I = 0;


void draw() {

background(img[I]);

if (frameCount%20==0) I = (I+1)%3;

}

----------------------------------------------------------------------
002.
PImage img;
void setup() {
  size(500, 300);
  img = loadImage("turkey.png");
  imageMode(CENTER);
}
void turckey(int x, int y) {
  pushMatrix();
  translate(x, y);
  rotate(radians(frameCount));
  image(img, 0, 0);
  popMatrix();
}
void draw() {
  turckey(mouseX, mouseY);
  turckey(100, 100);
  turckey(400, 100);
  turckey(100, 200);
  turckey(400, 200);
}
--------------------------------------------------------------------------------
003.
PShape gundam;
void setup() {
  size(500, 500, P3D);
  gundam = loadShape("Gundam.obj");
}
void draw() {
  pushMatrix();
    background(#BBFF81);
    translate(mouseX, mouseY);
    rotateY(radians(frameCount));
    rotate(radians(180));
    scale(15, 15, 15);
    shape(gundam, 0, 0);
  popMatrix();
}
-------------------------------------------------------------------------------------------
004.
color [] c = {#000000, #777777, #9900CC, #CCCC00, #00B500, #FFFFFF, #CC0000, #00CCCC, #CC0000, #F54600, #FFA91C};
int T = 2;
void setup() {
  size(240, 440);
}
void draw() {
  for (int i=0; i<22; i++) {
    for (int j=0; j<12; j++) {
      int now = grid[i][j];
      fill(c[now]);
      rect(j*20, i*20, 20, 20);
    }
  }
  if (frameCount%50==0) {
    int bad=0;
    for (int i=20; i>=1; i--) {//從下到上的迴圈
      for (int j=1; j<12-1; j++) {
        if (grid[i][j]==9) {
          if (grid[i+1][j]!=0 && grid[i+1][j]!=9) bad=1;
        }
      }
    }
    println(bad);
    if (bad==0) {
      for (int i=20; i>=1; i--) {//從下到上的迴圈
        for (int j=1; j<12-1; j++) {
          if (grid[i][j]==9) {
            grid[i+1][j]=9;
            grid[i][j]=0;
          }
        }
      }
    } else {
      for (int i=20; i>=1; i--) {//從下到上的迴圈
        for (int j=1; j<12-1; j++) {
          if (grid[i][j]==9) {
            grid[i][j]=T;
          }
        }
      }
    }
  }
}
int[][] grid = {
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  {1, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
};


沒有留言:

張貼留言