今天要做的是在卡片上面打洞的互動程式
這是隨著滑鼠移動打洞

畫個格子
──────────────────────
│ size(800,300);
│ for(int x=0;x<800;x+=16){
│ for(int y=0;y<300;y+=30){
│ rect(x,y,16,30);
│ }
│ }
──────────────────────
成品
void setup(){
size(800,300);
for(int x=0;x<800;x+=16){
for(int y=0;y<300;y+=30){
rect(x,y,16,30);
}
}
}
void draw(){
int nowX=mouseX/16*16, nowY=mouseY/30*30;
if(mousePressed && mouseButton==LEFT){ ///控制滑鼠左鍵填色
fill(0);
rect(nowX,nowY,16,30);
//rect(mouseX,mouseY, 50,20);
}
else if(mousePressed && mouseButton==RIGHT){ ///控制滑鼠右鍵把畫錯的格子恢復顏色
fill(255);
rect(nowX,nowY,16,30);
}
}

放圖片
size(500,500);
PImage img=loadImage("maxresdefault.jpg");
image( img, 0,0,200,200);

PImage img;
void setup(){
size(500,500);
img=loadImage("maxresdefault.jpg");
}
void draw(){
image( img, mouseX,mouseY, 200,200);
}
沒有留言:
張貼留言