Advertisement
Guest User

Untitled

a guest
May 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. import ketai.camera.*;
  2.  
  3.  
  4. KetaiCamera cam;
  5.  
  6. PFont color_text;
  7.  
  8. color k = color(0,255,0);
  9. color c = color(0,0,0);
  10. color f;
  11. color track = color(255,0,0);
  12. float hue,sat,br;
  13. int x = 0;
  14. int color_obj = 0;
  15. void setup() {
  16. color_text = createFont("SansSerif-Bold",32);
  17. textFont(color_text,32);
  18. textAlign(CENTER,CENTER);
  19. fullScreen();
  20. orientation(LANDSCAPE);
  21. imageMode(CENTER);
  22.  
  23. cam = new KetaiCamera(this, width, height, 60); }
  24. void draw() {
  25. image(cam, width/2, height/2);
  26. c = cam.get(width/2,height/2);
  27. pushStyle();
  28. stroke(k);
  29. noFill();
  30. rect(width/2, height/2, 32, 32);
  31. noFill();
  32. popStyle();
  33. pushMatrix();
  34. translate(width/2, height/2);
  35. rotate(-HALF_PI);
  36. translate(-width/2, -height/2);
  37. if((x > 512) && color_obj == 1) {
  38. pushStyle();
  39. fill(360,0,100);
  40. textSize(64);
  41. text("Красный", (width/2),(height/2)-80);
  42. popStyle();
  43. }
  44. else if((x > 512) && color_obj == 2) {
  45. pushStyle();
  46. fill(360,0,100);
  47. textSize(64);
  48. text("Зелёный", (width/2),(height/2)-80);
  49. textSize(64);
  50. popStyle();
  51. }
  52. else if((x > 512) && color_obj == 3) {
  53. pushStyle();
  54. fill(360,0,100);
  55. textSize(64);
  56. text("Синий", (width/2),(height/2)-80);
  57. textSize(64);
  58. popStyle();
  59. }
  60. else if((x > 512) && color_obj == 4) {
  61. pushStyle();
  62. fill(360,0,100);
  63. textSize(64);
  64. text("Оранжевый", (width/2),(height/2)-80);
  65. textSize(64);
  66. popStyle();
  67. }
  68. else if((x > 512) && color_obj == 5) {
  69. pushStyle();
  70. fill(360,0,100);
  71. textSize(64);
  72. text("Фиолетовый", (width/2),(height/2)-80);
  73. textSize(64);
  74. popStyle();
  75. }
  76. popMatrix();
  77. colorMode(HSB,360, 100,100);
  78. for(int i = (width/2); i < (width/2) + 32; i++) {
  79. for(int j = (height/2); j < (height/2) + 32; j++) {
  80. f = cam.get(i,j) + 0xffffff;
  81. hue = hue(f);
  82. sat = saturation(f);
  83. br = brightness(f);
  84. if(((hue > 300) && (hue < 360) || (hue > 20) && (hue < 40)) && (sat > 50) && (sat < 100) && (br > 20) && (br < 100)) {
  85. x++;
  86. color_obj = 1;
  87. //set(i,j,f);
  88. }
  89. else if(((hue > 60) && (hue < 155)) && (sat > 30) && (sat < 100) && (br > 10) && (br < 100)) {
  90. x++;
  91. color_obj = 2;
  92. //set(i,j,f);
  93. }
  94. else if(((hue > 160) && (hue < 250)) && (sat > 30) && (sat < 100) && (br > 10) && (br < 100)) {
  95. x++;
  96. color_obj = 3;
  97. //set(i,j,f);
  98. }
  99. else if(((hue > 15) && (hue < 60)) && (sat > 50) && (sat < 100) && (br > 10) && (br < 100)) {
  100. x++;
  101. color_obj = 4;
  102. //set(i,j,f);
  103. }
  104. else if(((hue > 260) && (hue < 340)) && (sat > 30) && (sat < 100) && (br > 35) && (br < 100)) {
  105. x++;
  106. color_obj = 5;
  107. //set(i,j,f);
  108. }
  109. else {x = 0;color_obj = 0;}
  110. }
  111. }
  112. pushStyle();
  113. pushMatrix();
  114. translate(width/4, height/4);
  115. rotate(-HALF_PI);
  116. translate(-width/4, -height/4);
  117. textSize(32);
  118. fill(125,100,100, 50);
  119. text((int)hue + " " + (int)sat + " " + (int)br, (width/2) - 500, 10);
  120. popMatrix();
  121. popStyle();
  122. }
  123.  
  124.  
  125. void onCameraPreviewEvent() {
  126. cam.read();
  127. }
  128.  
  129.  
  130. void mousePressed() {
  131. if (cam.isStarted()) {
  132. cam.stop();
  133. } else cam.start();
  134. }
  135. void keyPressed() {
  136. if (key == CODED) {
  137. if (keyCode == MENU) {
  138. if (cam.isFlashEnabled())
  139. cam.disableFlash();
  140. else cam.enableFlash();
  141. }
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement