WEEK09
Step01
顯示出鍵盤圖片(先把鍵盤圖片匯進去processing)
PImage img; void setup(){ size(800,600); img = loadImage("keyboard.png"); } void draw(){ image(img,0,600-266); }
改變一下背景,顯示滑鼠指標(鼠標上有紅色框框),點下去顯示XY位置
PImage img; void setup(){ size(800,600); img = loadImage("keyboard.png"); rectMode(CENTER); } void draw(){ background(#FFFFF2); image(img,0,600-266); fill(255,0,0,128); rect(mouseX,mouseY,28,30,5); } void mousePressed(){ println(mouseX,mouseY); }
先用前面的程式把字母的位置標出來,然後設定字串
用字串百字母標出來
PImage img; int [][] pos={{83,457},{117,456},{151,456},{186,456},{221,457},{254,456},{288,457},{323,457},{356,458},{390,456},{93,491},{128,491},{161,490},{195,490},{230,489},{264,489},{298,491},{332,490},{368,490},{110,523},{144,524},{178,525},{210,525},{245,525},{280,525},{314,524}}; void setup(){ size(800,600); img = loadImage("keyboard.png"); rectMode(CENTER); } void draw(){ background(#FFFFF2); image(img,0,600-266); fill(255,0,0,128); rect(mouseX,mouseY,28,30,6); fill(0,255,0,128); for(int i=0;i<26;i++){ rect(pos[i][0],pos[i][1],28,30,5); } } void mousePressed(){ println(mouseX,mouseY); }
讓鍵盤按字母就顯示什麼字母
PImage img; int [][] pos={{93,490},{246,524},{178,524},{161,490},{151,457},{195,491},{229,491},{263,491},{323,456},{298,490},{333,491}, {366,491},{315,525},{281,524},{358,457},{392,456},{82,456},{186,456},{128,491},{220,456},{288,457},{212,524}, {119,456},{145,524},{253,456},{110,525}}; void setup(){ size(800,600); img = loadImage("keyboard.png"); rectMode(CENTER); } void draw(){ background(#FFFFF2); image(img,0,600-266); fill(255,0,0,128); rect(mouseX,mouseY,28,30,6); fill(0,255,0,128); for(int i=0;i<26;i++){ if(pressed[i])rect(pos[i][0],pos[i][1],28,30,5); } } boolean [] pressed =new boolean[26]; void keyPressed(){ if(key>='a'&&key<='z') pressed[key-'a']=true; } void keyReleased(){ if(key>='a'&&key<='z') pressed[key-'a']=false; } void mousePressed(){ println(mouseX,mouseY); }
Step02
打出的字母就把那個字母的文字顯示出來並記錄
PImage img; int [][] pos={{93,490},{246,524},{178,524},{161,490},{151,457},{195,491},{229,491},{263,491},{323,456},{298,490},{333,491}, {366,491},{315,525},{281,524},{358,457},{392,456},{82,456},{186,456},{128,491},{220,456},{288,457},{212,524}, {119,456},{145,524},{253,456},{110,525}}; void setup(){ size(800,600); img = loadImage("keyboard.png"); rectMode(CENTER); } void draw(){ background(#FFFFF2); image(img,0,600-266); fill(255,0,0,128); rect(mouseX,mouseY,28,30,5); fill(0,255,0,128); for(int i=0;i<26;i++){ if(typing.charAt(0) - 'a' ==i) rect (pos[i][0],pos[i][1], 28,30,5); if(pressed[i])rect(pos[i][0],pos[i][1],28,30,5); } fill(0); textSize(50); text(typing,50,50); text(typing.charAt(0),50,100); } String typing = "printf"; boolean [] pressed =new boolean[26]; void keyPressed(){ if(key>='a'&&key<='z') pressed[key-'a']=true; } void keyReleased(){ if(key>='a'&&key<='z') pressed[key-'a']=false; } void mousePressed(){ println(mouseX,mouseY); }
打出超過字串會當機
PImage img; int [][] pos={{93,490},{246,524},{178,524},{161,490},{151,457},{195,491},{229,491},{263,491},{323,456},{298,490},{333,491}, {366,491},{315,525},{281,524},{358,457},{392,456},{82,456},{186,456},{128,491},{220,456},{288,457},{212,524}, {119,456},{145,524},{253,456},{110,525}}; void setup(){ size(800,600); img = loadImage("keyboard.png"); rectMode(CENTER); } void draw(){ background(#FFFFF2); image(img,0,600-266); fill(255,0,0,128); rect(mouseX,mouseY,28,30,5); fill(0,255,0,128); for(int i=0;i<26;i++){ if(typing.charAt(ID) - 'a' ==i) rect (pos[i][0],pos[i][1], 28,30,5); if(pressed[i])rect(pos[i][0],pos[i][1],28,30,5); } fill(0);//黑色的字 textSize(50); text(typing,50,50);//要打的字 fill(255,0,0);//紅色 text(typed+typing.charAt(ID),50,100);//現在要打的字,是typing.charAt(0) fill(0);//再用黑色,秀出已經打好的字 text(typed,50,100);//已經打好的字 } String typing = "printfprintfprintf"; String typed ="";//一開始打了0個字 int ID=0;//第幾個字母要被打 boolean [] pressed =new boolean[26]; void keyPressed(){ if(key>='a'&&key<='z') pressed[key-'a']=true; typed += key; ID++; } void keyReleased(){ if(key>='a'&&key<='z') pressed[key-'a']=false; } void mousePressed(){ println(mouseX,mouseY); }
Step03
PImage img; int [][] pos={{93,490},{246,524},{178,524},{161,490},{151,457},{195,491},{229,491},{263,491},{323,456},{298,490},{333,491}, {366,491},{315,525},{281,524},{358,457},{392,456},{82,456},{186,456},{128,491},{220,456},{288,457},{212,524}, {119,456},{145,524},{253,456},{110,525}}; void setup(){ size(800,600); img = loadImage("keyboard.png"); rectMode(CENTER); } void draw(){ background(#FFFFF2); image(img,0,600-266); fill(255,0,0,128); rect(mouseX,mouseY,28,30,5); fill(0,255,0,128); for(int i=0;i<26;i++){ if(typing.charAt(ID) - 'a' ==i) rect (pos[i][0],pos[i][1], 28,30,5); if(pressed[i])rect(pos[i][0],pos[i][1],28,30,5); } fill(0);//黑色的字 textSize(50); text(typing,50,50);//要打的字 fill(255,0,0);//紅色 text(typed+typing.charAt(ID),50,100);//現在要打的字,是typing.charAt(0) fill(0);//再用黑色,秀出已經打好的字 text(typed,50,100);//已經打好的字 } String typing = "printfprintfprintf"; String typed ="";//一開始打了0個字 int ID=0;//第幾個字母要被打 boolean [] pressed =new boolean[26]; void keyPressed(){ if(key>='a'&&key<='z') { if(key==typing.charAt(ID)){ pressed[key-'a']=true; typed += key; ID++; }else{ background(255,0,0); } } } void keyReleased(){ if(key>='a'&&key<='z') pressed[key-'a']=false; } void mousePressed(){ println(mouseX,mouseY); }
打出超過文字不會當機
PImage img; int [][] pos = {{94,488},{247,524},{179,524},{160,490},{151,456},{194,489},{231,491},{264,489},{323,456},{300,489},{330,490},{367,491},{315,523},{280,526},{357,454},{389,457},{83,456},{188,457},{129,490},{220,456},{287,457},{211,524},{118,457},{145,525},{252,456},{109,524}}; void setup(){ size(800, 600); img = loadImage("keyboard.png"); rectMode(CENTER); //用中心點,來畫四邊形 } void draw(){ background(#FFFFF2); //淡黃色,清背景 image(img, 0, 600-266); fill(255,0,0, 128); //半透明的紅色 rect(mouseX, mouseY, 28, 30, 5); fill(0,255,0, 128); for(int i=0; i<26; i++){ if(ID< typing.length() && typing.charAt(ID)-'a'==i) rect(pos[i][0], pos[i][1], 28, 30, 5); if(pressed[i]) rect(pos[i][0], pos[i][1], 28, 30, 5); } fill(0); textSize(50); text(typing,50,50); text(typed,50,100); fill(255,0,0); if(ID< typing.length()) text(typed+typing.charAt(ID),50,100); fill(0); text(typed,50,100); } String typing="printfprintfprintf"; String typed=""; int ID = 0; boolean [] pressed = new boolean[26]; void keyPressed(){ if(ID< typing.length() && key==typing.charAt(ID)){ pressed[key-'a'] = true; typed+=key; ID++; }else{ background(255,0,0); } } void keyReleased(){ if(key>='a'&&key<='z') pressed[key-'a'] = false; } void mousePressed(){ print(mouseX, mouseY); //定位、印出mouse座標 }
可以打出空格鍵
PImage img; int [][] pos = {{94,488},{247,524},{179,524},{160,490},{151,456},{194,489},{231,491},{264,489},{323,456},{300,489},{330,490},{367,491},{315,523},{280,526},{357,454},{389,457},{83,456},{188,457},{129,490},{220,456},{287,457},{211,524},{118,457},{145,525},{252,456},{109,524}}; void setup(){ size(800, 600); img = loadImage("keyboard.png"); rectMode(CENTER); //用中心點,來畫四邊形 } void draw(){ background(#FFFFF2); //淡黃色,清背景 image(img, 0, 600-266); fill(255,0,0, 128); //半透明的紅色 rect(mouseX, mouseY, 28, 30, 5); fill(0,255,0, 128); for(int i=0; i<26; i++){ if(ID< typing.length() && typing.charAt(ID)-'a'==i) rect(pos[i][0], pos[i][1], 28, 30, 5); if(pressed[i]) rect(pos[i][0], pos[i][1], 28, 30, 5); } fill(0); textSize(50); text(typing,50,50); text(typed,50,100); fill(255,0,0); if(ID< typing.length()) text(typed+typing.charAt(ID),50,100); fill(0); text(typed,50,100); } String typing="printf is a function"; String typed=""; int ID = 0; boolean [] pressed = new boolean[26]; void keyPressed(){ if(ID< typing.length() && key==typing.charAt(ID)){ if(key>='a'&&key<='z'){ pressed[key-'a'] = true; typed+=key; ID++; }else if(key==' '){ typed+=key; ID++; }else{ background(255,0,0); } } } void keyReleased(){ if(key>='a'&&key<='z') pressed[key-'a'] = false; } void mousePressed(){ print(mouseX, mouseY); //定位、印出mouse座標 }
沒有留言:
張貼留言