Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] dataX = new int[100];//number of pin
- int[] dataY = new int[100];
- int x=0;
- int y=0;
- int i=1;
- int k=1;
- int pixcel = 50;//box size
- void setup() {
- size(800, 800);//window size
- background(100,100,100);
- stroke(255,255,255);
- for(int i=0 ; i < 7+1 ; i++){
- line( 0, i*pixcel ,13*pixcel, i*pixcel );//horizon line
- }
- for(int i=0 ; i < 13+1 ; i++){
- line( i*pixcel , 0 ,i*pixcel,7*pixcel );//horizon line
- }
- textSize(16);
- text("Press any key then change image to data.",10,400);
- text("Copy data on console and paste to Arduino skeche.",10,420);
- }
- void draw() { // do not need???
- }
- //draw black box
- void mousePressed() {
- noStroke();
- int pinX;
- int pinY;
- pinX = mouseX/pixcel;
- pinY = mouseY/pixcel;
- loadPixels();
- color cell_color =pixels[pinY*width*pixcel + pinX*pixcel];
- color black = color(0,0,0);
- color white = color(255,255,255);
- color gray = color(100,100,100);
- if(cell_color != black){
- fill(0,0,0);
- noStroke();
- rect(pinX*pixcel, pinY*pixcel, pixcel, pixcel);
- }else{
- fill(100,100,100);
- stroke(255,255,255);
- rect(pinX*pixcel, pinY*pixcel, pixcel, pixcel);
- }
- }
- //when key pressed ,read data
- void keyPressed() {
- loadPixels();
- //sono seru no tenn ga kuro nara x ni namber wo ireru
- for (y=0;y<13+1;y++){
- for (x=0;x<7+1;x++){
- color black = color(0,0,0);
- color cell_color =pixels[y*width*pixcel + x*pixcel+1];
- if (cell_color == black){
- dataX[i] = x+1;
- i=i+1;
- dataY[k] = y+1;
- k=k+1;
- }
- }
- x=0;///caution!!
- color black = color(0,0,0);
- color cell_color =pixels[y*width*pixcel + x*pixcel+1];
- if (cell_color == black){
- dataY[k] = y+1;
- k=k+1;
- dataX[i] = x+1;
- i=i+1;
- }
- }
- //export
- text("x :",10,500);
- text("y :",10,520);
- print("dataX{");
- for(int j =0 ;j<i;j++){
- text(dataY[j],30+j*18,500);
- print(dataY[j]);
- print(",");
- }
- println("}");
- print("dataY{");
- for(int j =0 ;j<k;j++){
- text(dataX[j],30+j*18,520);
- print(dataX[j]);
- print(',');
- }
- println("}");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement