Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ketai.camera.*;
- KetaiCamera cam;
- PFont color_text;
- color k = color(0,255,0);
- color c = color(0,0,0);
- color f;
- color track = color(255,0,0);
- float hue,sat,br;
- int x = 0;
- int color_obj = 0;
- void setup() {
- color_text = createFont("SansSerif-Bold",32);
- textFont(color_text,32);
- textAlign(CENTER,CENTER);
- fullScreen();
- orientation(LANDSCAPE);
- imageMode(CENTER);
- cam = new KetaiCamera(this, width, height, 60); }
- void draw() {
- image(cam, width/2, height/2);
- c = cam.get(width/2,height/2);
- pushStyle();
- stroke(k);
- noFill();
- rect(width/2, height/2, 32, 32);
- noFill();
- popStyle();
- pushMatrix();
- translate(width/2, height/2);
- rotate(-HALF_PI);
- translate(-width/2, -height/2);
- if((x > 512) && color_obj == 1) {
- pushStyle();
- fill(360,0,100);
- textSize(64);
- text("Красный", (width/2),(height/2)-80);
- popStyle();
- }
- else if((x > 512) && color_obj == 2) {
- pushStyle();
- fill(360,0,100);
- textSize(64);
- text("Зелёный", (width/2),(height/2)-80);
- textSize(64);
- popStyle();
- }
- else if((x > 512) && color_obj == 3) {
- pushStyle();
- fill(360,0,100);
- textSize(64);
- text("Синий", (width/2),(height/2)-80);
- textSize(64);
- popStyle();
- }
- else if((x > 512) && color_obj == 4) {
- pushStyle();
- fill(360,0,100);
- textSize(64);
- text("Оранжевый", (width/2),(height/2)-80);
- textSize(64);
- popStyle();
- }
- else if((x > 512) && color_obj == 5) {
- pushStyle();
- fill(360,0,100);
- textSize(64);
- text("Фиолетовый", (width/2),(height/2)-80);
- textSize(64);
- popStyle();
- }
- popMatrix();
- colorMode(HSB,360, 100,100);
- for(int i = (width/2); i < (width/2) + 32; i++) {
- for(int j = (height/2); j < (height/2) + 32; j++) {
- f = cam.get(i,j) + 0xffffff;
- hue = hue(f);
- sat = saturation(f);
- br = brightness(f);
- if(((hue > 300) && (hue < 360) || (hue > 20) && (hue < 40)) && (sat > 50) && (sat < 100) && (br > 20) && (br < 100)) {
- x++;
- color_obj = 1;
- //set(i,j,f);
- }
- else if(((hue > 60) && (hue < 155)) && (sat > 30) && (sat < 100) && (br > 10) && (br < 100)) {
- x++;
- color_obj = 2;
- //set(i,j,f);
- }
- else if(((hue > 160) && (hue < 250)) && (sat > 30) && (sat < 100) && (br > 10) && (br < 100)) {
- x++;
- color_obj = 3;
- //set(i,j,f);
- }
- else if(((hue > 15) && (hue < 60)) && (sat > 50) && (sat < 100) && (br > 10) && (br < 100)) {
- x++;
- color_obj = 4;
- //set(i,j,f);
- }
- else if(((hue > 260) && (hue < 340)) && (sat > 30) && (sat < 100) && (br > 35) && (br < 100)) {
- x++;
- color_obj = 5;
- //set(i,j,f);
- }
- else {x = 0;color_obj = 0;}
- }
- }
- pushStyle();
- pushMatrix();
- translate(width/4, height/4);
- rotate(-HALF_PI);
- translate(-width/4, -height/4);
- textSize(32);
- fill(125,100,100, 50);
- text((int)hue + " " + (int)sat + " " + (int)br, (width/2) - 500, 10);
- popMatrix();
- popStyle();
- }
- void onCameraPreviewEvent() {
- cam.read();
- }
- void mousePressed() {
- if (cam.isStarted()) {
- cam.stop();
- } else cam.start();
- }
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == MENU) {
- if (cam.isFlashEnabled())
- cam.disableFlash();
- else cam.enableFlash();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement