WEEK13 點播
13-1(動態背景)
//week13_1_animated_background
PImage [] img = new PImage[3];
void setup(){
size(346,408);
img[0] = loadImage("00002.jpg");
img[1] = loadImage("00003.jpg");
}
int I = 0;
void draw(){
background(img[I]);
if(frameCount%24==0) I=(I+1)%2;
}
13-2(動態移動背景)
//week13_2_animated_background_moving
void setup() {
size(500, 300);
}
void draw() {
background(255, 255, 200);
float x = (frameCount*5%1000);
if (x>500) x =1000-x;
for (int y=30; y<300; y+=50) {
ellipse(x, y, 30, 30);
}
}
13-3(動態旋轉背景)
//week13_3_animated_background_moving
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, 255, 200);
turkey(mouseX,mouseY);
turkey(100,100);
turkey(300,300);
}
13-4(讀取3D)
//week13_4_obj_loadshape
PShape gumdam;
void setup(){
size(500,500,P3D);
gumdam = loadShape("Gundam.obj");
}
void draw(){
shape(gumdam,0,0,250,500);
}
13-5(3D展示)
//week13_5_PShape_loadshape_Push
PShape gumdam;
void setup(){
size(500,500,P3D);
gumdam = loadShape("Gundam.obj");
}
void draw(){
background(#BBFF81);
pushMatrix();
translate(mouseX,mouseY);
rotateY(radians(frameCount));
rotate(radians(180));
scale(8,8,8);
shape(gumdam,0,0);
popMatrix();
}
13-6(3D LOOP展示)
//week13_6_PShape_drawloop
PShape gumdam;
void setup(){
size(500,500,P3D);
gumdam = loadShape("Gundam.obj");
}
void draw(){
background(#BBFF81);
drawGundam(mouseX,mouseY);
for(int x=0;x<=500;x+=125){
drawGundam(x,300);
}
}
void drawGundam(int x,int y){
pushMatrix();
translate(x,y);
rotateY(radians(frameCount));
rotate(radians(180));
scale(8,8,8);
shape(gumdam,0,0);
popMatrix();
}
13-7(俄羅斯方塊)
//week13_7_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;
}
13-8(俄羅斯方塊 矩陣)
//week13_8_tetris_falling_rect_grid
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},
};
13-9(俄羅斯方塊 color)
//week13_9_tetris_color
color [] c = {#000000,#777777,#9900CC,#CCCC00};
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,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,1,1,1,1,1,1,1,1,1,1,1},
};
13-a(俄羅斯方塊 for)
//week13_a_tetris_for_for_if
color [] c = {#000000,#777777,#9900CC,#CCCC00,#00B500,#CC0000,#0000CC,#CC9900,#0000CC,#FFFFFF};
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] == 2){
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;
grid[i][j]=0;
}
}
}
}
}
}
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},
};
13-b(俄羅斯方塊 判斷)
//week13_b_tetris_for_for_if
color [] c = {#000000,#777777,#9900CC,#CCCC00,#00B500,#CC0000,#0000CC,#CC9900,#0000CC,#FFFFFF};
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;
}
}
}
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},
};
沒有留言:
張貼留言