Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. int[] dataX = new int[100];//number of pin
  2. int[] dataY = new int[100];
  3.  
  4. int x=0;
  5. int y=0;
  6.  
  7. int i=1;
  8. int k=1;
  9.  
  10. int pixcel = 50;//box size
  11.  
  12. void setup() {
  13. size(800, 800);//window size
  14. background(100,100,100);
  15.  
  16.  
  17. stroke(255,255,255);
  18. for(int i=0 ; i < 7+1 ; i++){
  19. line( 0, i*pixcel ,13*pixcel, i*pixcel );//horizon line
  20. }
  21. for(int i=0 ; i < 13+1 ; i++){
  22. line( i*pixcel , 0 ,i*pixcel,7*pixcel );//horizon line
  23. }
  24.  
  25. textSize(16);
  26. text("Press any key then change image to data.",10,400);
  27. text("Copy data on console and paste to Arduino skeche.",10,420);
  28.  
  29.  
  30.  
  31.  
  32. }
  33.  
  34. void draw() { // do not need???
  35. }
  36.  
  37.  
  38. //draw black box
  39.  
  40. void mousePressed() {
  41. noStroke();
  42. int pinX;
  43. int pinY;
  44. pinX = mouseX/pixcel;
  45. pinY = mouseY/pixcel;
  46.  
  47.  
  48. loadPixels();
  49. color cell_color =pixels[pinY*width*pixcel + pinX*pixcel];
  50. color black = color(0,0,0);
  51. color white = color(255,255,255);
  52. color gray = color(100,100,100);
  53.  
  54. if(cell_color != black){
  55. fill(0,0,0);
  56. noStroke();
  57. rect(pinX*pixcel, pinY*pixcel, pixcel, pixcel);
  58.  
  59. }else{
  60. fill(100,100,100);
  61. stroke(255,255,255);
  62. rect(pinX*pixcel, pinY*pixcel, pixcel, pixcel);
  63. }
  64.  
  65. }
  66.  
  67.  
  68.  
  69. //when key pressed ,read data
  70.  
  71. void keyPressed() {
  72. loadPixels();
  73.  
  74.  
  75. //sono seru no tenn ga kuro nara x ni namber wo ireru
  76.  
  77.  
  78. for (y=0;y<13+1;y++){
  79.  
  80. for (x=0;x<7+1;x++){
  81. color black = color(0,0,0);
  82. color cell_color =pixels[y*width*pixcel + x*pixcel+1];
  83.  
  84.  
  85. if (cell_color == black){
  86. dataX[i] = x+1;
  87. i=i+1;
  88.  
  89. dataY[k] = y+1;
  90. k=k+1;
  91. }
  92. }
  93.  
  94. x=0;///caution!!
  95.  
  96. color black = color(0,0,0);
  97. color cell_color =pixels[y*width*pixcel + x*pixcel+1];
  98.  
  99.  
  100. if (cell_color == black){
  101. dataY[k] = y+1;
  102. k=k+1;
  103.  
  104. dataX[i] = x+1;
  105. i=i+1;
  106. }
  107. }
  108.  
  109.  
  110.  
  111.  
  112. //export
  113. text("x :",10,500);
  114. text("y :",10,520);
  115.  
  116. print("dataX{");
  117. for(int j =0 ;j<i;j++){
  118. text(dataY[j],30+j*18,500);
  119. print(dataY[j]);
  120. print(",");
  121. }
  122.  
  123. println("}");
  124.  
  125. print("dataY{");
  126. for(int j =0 ;j<k;j++){
  127. text(dataX[j],30+j*18,520);
  128. print(dataX[j]);
  129. print(',');
  130. }
  131. println("}");
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement