// week13_01_animated_background_array_I_frameCount
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;
}
// week13_02_animated_background_frameCount_x
void setup() {
size(500, 300); //寬度是500,兩倍是1000
}
void draw() {
background(#FFFFF2);
float x = (frameCount*5 %1000);
if (x>500) x = 1000 -x; // 超過500範圍,就折回來
for (int y=30; y<300; y+=50) {
ellipse(x,y,30,30);
}
}
PImage img;
void setup(){
size(500,300);
img = loadImage("turkey.png");
imageMode(CENTER);
}
void turkey(int x ,int y){
pushMatrix();
translate(x,y);
rotate(radians(frameCount));
image(img ,0, 0);
popMatrix();
}
void draw(){
background(255);
turkey(mouseX,mouseY);
turkey(100,100);
turkey(400,100);
turkey(100,200);
turkey(400,200);
}
// week13_04_obj_mtl_gundam_laodShape_shpae_obj_mtl_jpg
PShape gundam;
void setup(){
size(500,500,P3D); // 小心P3D
gundam = loadShape("Gundam.obj");
}
void draw(){
shape(gundam, 0,0 ,500,500);
}
// week13_05_Pshape_gundam_loadShpae_shpae_pushMatrix_scale_transia
PShape gundam;
void setup() {
size(500, 500, P3D); // 小心P3D
gundam = loadShape("Gundam.obj");
}
void draw() {
background(#BBFF81); //淡綠色
pushMatrix();
translate(mouseX, mouseY);
rotateY(radians(frameCount));
rotate(radians(180));
scale(5, 5, 5);
shape(gundam, 0, 0); // shape(gundam, 0, 0, 250/2, 500/2);
popMatrix();
}
// // week13_06_Pshape_gundam_for_loop
PShape gundam;
void setup() {
size(500, 500, P3D); // 小心P3D
gundam = loadShape("Gundam.obj");
}
void draw() {
background(#BBFF81); //淡綠色
pushMatrix();
translate(mouseX, mouseY);
rotateY(radians(frameCount));
rotate(radians(180));
scale(5, 5, 5);
shape(gundam, 0, 0); // shape(gundam, 0, 0, 250/2, 500/2);
popMatrix();
}
// week13_07_tetris_falling
void setup() {
size(300, 600);
}
float x =50, y= 50;
void draw() {
background(0);
fill(153, 0, 204);
rect(x, y-25, 25, 25);
rect(x+25, y, 25, 25);
rect(x, y, 25, 25);
rect(x, y+25, 25, 25);
if (frameCount%50==0) y+=25;
}
void keyPressed() {
if (keyCode==RIGHT) x+=25;
if (keyCode==LEFT) x-=25;
}
// week13_08_tetris_grid_2d_array_fill_rect
void setup() {
size(240, 440);
}
void draw() {
for (int i =0; i<22; i++) {
for (int j=0; j<12; j++) {
if (grid[i][j]==1) fill(119, 119, 119);
if (grid[i][j]==0) fill(0);
if (grid[i][j]==2) fill(153, 0, 204);
rect(j*20, i*20, 20, 20);
}
}
}
int [][] grid ={
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 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},
};
// week13_09_tetris_color_array_c_now
color [] c = {#000000, #777777, #9900CC, #CCCC00, #00B500,#CC0000}; //將會有10個色彩
//黑,灰,紫,黃,綠,紅
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);
}
}
}
int [][] grid ={
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 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},
};
// week13_10_tetris_falling_if_frameCount_for_for_if
color [] c = {#000000, #777777, #9900CC, #CCCC00, #00B500,#CC0000 ,#0000CC, #CC9900,#0000CC,#FFFFFF}; //將會有10個色彩
int T =2;
void setup() {
size(240, 440);
}
void draw() {
for (int i =0; i<22; i++) {
for (int j=0; j<12; j++) {
if (grid[i][j]==1) fill(119, 119, 119);
if (grid[i][j]==0) fill(0);
if (grid[i][j]==2) fill(153, 0, 204);
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]==2) { //如果是可以移動的主角,活著是9
if (grid[i+1][j]!=0 && grid[i+1][j]!=2) bad=1;
}//不能往下走
}
}
if (bad==0) {
for (int i=20; i>=1; i--) {
for (int j =1; j<12-1; j++) {
if (grid[i][j]==2) {
grid[i+1][j]=2;//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, 2, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 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},
};
// week13_11_tetris_falling_alive_9_freeze_dead_T
color [] c = {#000000, #777777, #9900CC, #CCCC00, #00B500,#CC0000 ,#0000CC, #CC9900,#0000CC,#FFFFFF}; //將會有10個色彩
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) { //如果是可以移動的主角,活著是9
if (grid[i+1][j]!=0 && grid[i+1][j]!=9) bad=1;
}//不能往下走
}
}
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;//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},
};
沒有留言:
張貼留言