Step01 製作彈珠檯
void setup(){
size(500,500);
}
int x=250, y=250;
void draw(){
ellipse ( x, y, 10, 10);
x = x + 1;
y = y - 1;
}
step01-2使他反彈
void setup(){
size(500,500);
}
float x=250 , y=250;
float vx=1.0 , vy = -0.5;
void draw(){
ellipse ( x, y, 10, 10 );
x = x + vx;
y = y + vy;
if( x > 500 ) vx = -vx;
if( y < 0 ) vy = -vy;
}
step01-3做一個板子給他反彈
void setup(){
size(500,500);
}
float x=250 , y=250;
float vx=1.0 , vy = -0.5;
void draw(){
background(#9EFCF7);
int boardX = mouseX;
rect(boardX, 470, 100, 20);
ellipse ( x, y, 10, 10 );
x = x + vx;
y = y + vy;
if( x > 500 ) vx = -vx;
if( y < 0 ) vy = -vy;
if( x < 0 ) vx = -vx;
if( y>470 && x>boardX && x<boardX+100 ) vy = -vy;
}
step01-4
void setup(){
size(500,500);
}
float x=250 , y=250;
float vx=1.0 , vy = -0.5;
float boardX, boardY=470, boardW=100, boardH=20;
void draw(){
background(#9EFCF7);
int boardX = mouseX;
rect(boardX, 470, 100, 20);
ellipse ( x, y, 10, 10 );
x = x + vx;
y = y + vy;
if( x > 500 ) vx = -vx;
if( y < 0 ) vy = -vy;
if( x < 0 ) vx = -vx;
if((y>boardY && y<boardY+boardH)&&
(x>boardX && x<boardX+boardW) ){
vy = -vy;
vx += (mouseX-pmouseX)/2;
}
if(mousePressed && mouseButton==LEFT) boardW *= 1.01;
if(mousePressed && mouseButton==RIGHT) boardW *= 0.99;
}
Step02-1劃一個棋盤void setup(){
size(500,500);
}
void draw(){
for(int x=50; x<=450; x+=50){
for(int y=50; y<=450; y+=50){
ellipse(x, y, 50, 50);
}
}
}
step02-2黑棋塗上去
void setup(){
size(500,500);
}
int [][] go ={
{0,0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,1},
{0,1,0,0,0,0,0,0,1},
{0,0,0,0,0,0,1,0,1},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
};
void draw(){
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
if( go[i][j]==1)fill(0);
else fill(255);
ellipse(50+j*50, 50+i*50, 50, 50);
}
}
}
step02-3劃出一個棋盤
void setup(){
size(500,500);
}
int [][] go ={
{0,0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,1},
{0,1,0,0,0,0,0,0,1},
{0,0,0,0,0,0,1,0,1},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
};
void draw(){
background(246, 194, 108);
for(int i=0; i<9; i++){
line(50, 50*i, 450, 50*i);
line(50*i, 50, 50*i, 450);
}
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
if( go[i][j]==1){
fill(0);
ellipse(50+j*50, 50+i*50, 40, 40);
}else if(go[i][j]==2){
fill(255);
ellipse(50+j*50, 50+i*50, 40, 40);
}
}
}
}
step02-4
void setup(){
size(500,500);
}
int [][] go ={
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
};
int N=0;
void mousePressed(){
int j = (mouseX-25)/50;
int i = (mouseY-25)/50;
go[i][j] = (N%2==0) ? 1 : 2;
N++;
}
void draw(){
background(246, 194, 108);
for(int i=1; i<=9; i++){
line(50, 50*i, 450, 50*i);
line(50*i, 50, 50*i, 450);
}
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
if( go[i][j]==1){
fill(0);
ellipse(50+j*50, 50+i*50, 40, 40);
}else if(go[i][j]==2){
fill(255);
ellipse(50+j*50, 50+i*50, 40, 40);
}
}
}
}
沒有留言:
張貼留言