今天教一個類似打洞機的程式
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;
fill(0);
rect(nowX,nowY,16,30);
}
PImage img;
void setup(){
size(500,500);
img=loadImage("https://images.chinatimes.com/newsphoto/2017-12-01/900/A17A00_P_01_01.jpg");
}
void draw(){
image(img,mouseX,mouseY,200,200);
}
PImage img;
void setup(){
size(800,300);
img=loadImage("https://images.chinatimes.com/newsphoto/2017-12-01/900/A17A00_P_01_01.jpg");
for(int x=0;x<800;x+=16){
for(int y=0;y<300;y+=30){
image(img,mouseX,mouseY,16,30);
}
}
}
void draw(){
int nowX=mouseX/16*16, nowY=mouseY/30*30;
if(mousePressed && mouseButton==LEFT){
fill(0);
image(img,nowX,nowY,16,30);
}
else if(mousePressed && mouseButton==RIGHT){
fill(255);
image(img,nowX,nowY,16,30);
}
}
最後做出類似打洞機又可以還原圖片的程式
PImage img;
int [][] table = new int [45][10];
void setup(){
size(711,377);
img=loadImage("123.jpg");
}
void draw(){
background(img);
int nowI=mouseX/16, nowJ=mouseY/30;
if(mousePressed && mouseButton==LEFT){
table[nowI][nowJ]=1;
}
else if(mousePressed && mouseButton==RIGHT){
table[nowI][nowJ]=0;
}
for(int i=0;i<45;i++){
for(int j=0;j<10;j++){
fill(0);
if( table[i][j]==1)rect(i*16,j*30,16,30);
}
}
}





沒有留言:
張貼留言