void setup(){
size(800,300);
}
void draw(){
rect(mouseX,mouseY,50,20);
}
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);
}
if(mousePressed && mouseButton==LEFT){
fill(0);
rect(nowX,nowY,16,30);
}
else if(mousePressed && mouseButton==RIGHT){
fill(255);
rect(nowX,nowY,16.,30);
}
Part 3 加入圖片
PImage img;
void setup(){
size(500,500);
img=loadImage("http://i.imgur.com/ZVvVWH6.jpg");
}
void draw(){
image(img,mouseX,mouseY,100,100);
}
Part 3-1 快速存取圖片
把檔案存檔,在資料夾裡面建立一個新的資料夾 data,把所需圖片放在裡面。
Part 4 完整打字機
PImage imgBG;
int [][] table = new int [45][10];
void setup(){
size(711,377);
imgBG=loadImage("card.jpg");
}
void draw(){
background(imgBG);
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);
}
}
}





沒有留言:
張貼留言