import processing.opengl.*;

import meter.*;

import blinkstick.*;

import vsync.*; 

import java.awt.event.KeyEvent;

import java.io.IOException;

import java.io.InputStream;

import java.util.List;

//import java.util.Arrays;

import java.util.*;

//import java.util.arrayList;

import processing.serial.*;

import java.io.File;

import java.io.FileReader;

import java.io.BufferedReader;

import java.io.DataInputStream;

import java.io.EOFException;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.InputStreamReader;


Serial myPort;

//초기값은 null값

String myString = null;

String serialAngle = null;

String serialDistance =null;

String serialData =null;

int objectDistance = 0;

int Angle, Distance;

int point;

int cx,cy;

int x,y;

float d;

int radius = 360;               // 목표물의 반지름                  

int degree = 0;                 // 모터회전각

int value = 0;                  // 초음파 시리얼 데이터

float motion = 0;                 // 모터구동              

int radarDist = 0;              // 레이더의 거리별 수치   

boolean signal = false;

int sizeIncrease = 10;

int initialSize = 70;

int count = 10;

PVector center;

float circleSize = 0;

float angle = 0;

float Radius = 0;

String Dist = null;

int duration = 0; 


 

void setup() 

{

  size (1280, 900,P3D);

  background(0);

  smooth();

  

 // println(Serial.list());

myPort = new Serial(this,"COM5", 19200);//Port 설정

myString = myPort.readStringUntil(',');

print(Serial.list());




}


    

         


void draw() //화면에 레이더를 띄움

{

  

 // draw();

  Radar();

  textDraw();

  drawRadar();

  drawPlot();

  serialEvent(myPort);

 

 

  center = new PVector(width/4, height/4);

  this.radius = 0;

   

  PVector point = new PVector(random(width/4), random(height/4));

  float deltaX = center.x - point.x;

  float deltaY = center.y - point.y;

  angle = atan2(deltaX, deltaY);


  float x = center.x + cos(degree)*180;

  float y = center.y + sin(degree)*180;


  ellipse(x, y, 5, 5);


  if(Distance<20){

  ellipse(center.x, center.y, 5, 5);  

  }

  

  if(Distance>40){

    ellipse(0,0,0,0);

    redraw();

  };


  

   //redraw(float x, float y, float deltaX, float deltaY, float radius){

   // center = PVector point(x, y, deltaX, deltaY);

   

  angle += PI/90;

  

   }


public class serialDistance {

        int serialDistance(int n) {

        int point ;


        while (n != 1) {  // n이 1이 되기 전까지 반복

            if (n % 2 == 1) {  // n이 홀수라면 순간 이동(2배) 불가

                point++;         // : 한 칸 점프해줌.

            }

          

            n /= 2;  // 순간 이동

        }

           

        return ++point;  // 현재 위치가 1이기 때문에 ans + 1을 반환

        exit();


        

}

###########################################################################################


void Radar() //화면구성

{

  

  noStroke();

  

 // fill(0,4); 

  rect(0, 0, 1280, 720);

  fill(10,255,10);

  

  translate(640,660,30); //화면의 좌표

  noFill();

  strokeWeight(1);//선굵기

  stroke(10,255,10);  //녹색선

  //반원을 그린다

  arc(0,0,1200,1200,PI,TWO_PI);

  arc(0,0,934,934,PI,TWO_PI);

  strokeWeight(1);

  stroke(255,10,10);

  arc(0,0,660,660,PI,TWO_PI);

  arc(0,0,400,400,PI,TWO_PI);

  arc(0,0,140,140,PI,TWO_PI);

  strokeWeight(1);

  //선들을 긋는다

  stroke(10,255,10);

  line(+(-640),0,640,0);

  line(0,0,+(-554),+(-320));

  line(0,0,+(-320),+(-554));

  line(0,0,0,+(-640));

  line(0,0,320,+(-554));

  line(0,0,554,+(-320));

  

  

}


void textDraw()

{

  pushMatrix();

  translate(640,660,30); //화면의 좌표

  fill(255);

  stroke(0,255,0);

  strokeWeight(1);

  textSize(25);  

  

  //글쓰기

text("0cm", cx, cy,cx-630,cy-700); 

text("20cm", cx, cy, cx-630,cy-1020); 

text("40cm", cx, cy, cx-630,cy-1280); 

text("Angle: " +Float.toString(Angle) +" °", cx-1200,cy-640,10);

text("Distance: "+Float.toString(Distance)+"cm", cx-900,cy-640); 


text("Ultrasonic Screen",cx-1200,cy-1250,10); 

text("Product by Woo Yong Kim",cx-1200,cy-1220,10);

  //cx와  cy로 좌표를 찾는다


if(Distance<40){

  noFill();

  stroke(255,0,0);

strokeWeight(4);

text("Alarm  : "+Boolean.compare(true,false)+" ",cx-250,cy-640);

}

if (Distance>40){

text("Alarm  : "+Boolean.compare(true,false)+"  ",cx+250,cy-640);

}


  popMatrix();

}


###################################################################################


void serialEvent(Serial p){

    

       

      myString = p.readStringUntil('.');

      if(myString != null){

       String[] list = split(myString, ',');

      }

     


    float length = 340*60;

    //  float Distance = (340*Length)/10000/2;

     // Distance = (duration / 2) * 0.0343;

      float  Distance= duration*0.034/2;

     

    String serialDistance = "Distance";

    String serialAngle = "Angle";

     Distance = Integer.parseInt(serialDistance); 

     Angle = Integer.parseInt(serialAngle); 

     System.out.println(Distance);

     System.out.println(Angle);

     

 //  float D = (width/2.0/30.0)*(float)Distance; //거리계산공식

 //  float circleSize = map(sin(frameCount * .01),-1.0,1.0,0.0,20.0);

    //for (int k = 0; k < count; k++) {

      serialDistance = "serialDistance";

              serialAngle = "Angle";

             int Distance = Integer.parseInt(serialDistance); 

             int Angle = Integer.parseInt(serialAngle);

           System.out.println(serialDistance);

           System.out.println(Angle);

    

      Angle = int(list[0]); 

   Distance = int(list[1]);

   

   stroke(0,255,0);

        println("Angle : "+Angle+"");

       // println(" Distance : "+Float.toString(serialDistance) + "cm");

        println(" Distance : "+Distance + "cm");

        println(" Alarm : "+Boolean.compare(true,false)+"");

    

    }

       

    

    //  float Distance = (width/2.0/30.0)*(float)Distance; //거리계산공식

//     ArrayList<Integer> lists = new ArrayList<>(Arrays.asList(0,1));


 //    if (lists.size() > 0) {

 //        System.out.println(lists.get(1));

//}


    // Distance = int(list[1]);

//serialDistance = int(list[1]);

           // signal = boolean(list[0]);   

    // signal = boolean(list[1].replace("",""));

         

 


 //###############################################################################################

 

  void drawRadar(){

 // pushMatrix();

  translate(cx,cy-10,30);

  strokeWeight(4);//선의 굵기

  stroke(255, 0, 0);//붉은선

  //float d = (width/2.0/30.0)*(float)Distance; //거리계산공식

  //line(0,0, width/2*cos(radians(radarAngle)), -width/2*sin(radians(radarAngle)));

  //int duration = Distance*2;

 // float Distance = duration / 29.0 / 2.0;

  float Distance= duration*0.034/2;

  float circleSize = map(sin(frameCount * .01),-1.0,1.0,0.0,20.0);

 

  // strokeWeight(4);

  //  stroke(0,255,0);

  if(Distance <40){

  stroke(0,255,0);

 line(0,0, width/2*cos(radians(Angle)), -width/2*sin(radians(Angle)));//부채꼴선

  } else{

   stroke(255,0,0);

   line(0,0, width/2*cos(radians(Angle)), -width/2*sin(radians(Angle)));

//  popMatrix();

  }

  

  

  

  for (int j = 0; j < count-8; j++){

    if(Distance<40){

   // circle(width/2, height/2, initialSize + i*sizeIncrease);

   circle(0,-200,(circleSize-5) + j*sizeIncrease);

  

  //balls();

 // ellipse(0,-200, circleSize,j*sizeIncrease);//????

 // balls.endDraw();

  }

  }


#################################################################################

Ball[] balls =  { 

  new Ball(100, 400, 5)

 // new Ball(700, 400, 50) 

};




  for (Ball b : balls) {

    b.update();

    b.display();

    b.checkBoundaryCollision();

  }

  

  balls[0].checkCollision(balls[0]);

}


//#######################################################################################################


void drawPlot()

{

  translate(640,666,30);

  strokeWeight(4);//선의 굵기

  stroke(255, 0, 0);//붉은선

  //float d = (width/2.0/30.0)*(float)Distance; //거리계산공식

 line(0,0,(height-height*0.12),-(height-height*0.12)); 

 // float d =  340*Distance/10000/2;

  float d = duration*0.034/2;

 if (motion == d) {                    

    for (float i = 0; d > Distance; d++) {     

      stroke(255.0, 0);              

      line(0, 0, radius + cos(radians(d)), radius + sin(radians(d))); // line(start x, start y, end x, end y)

    //  ellipse(radius,radius,cos(radians(d)),sin(radians(d)));

    }

  } else {                              

    for (float i = 0; d < Distance ; d--) {     

      stroke(0,200-(20*i), 0);          

      line(radius, radius, radius + cos(radians(360+i)), radius + sin(radians(360+i)));

    }

  } 

}


 //######################################################################################################


public class test {


void main(String args[]) { 


      Integer intObj=Integer.valueOf(args[args.length-2]);

      int i = intObj.intValue();


      if(args.length > 1) 

         System.out.println(i);

      if(args.length > 0)

         System.out.println(i - 1);

      else 

         System.out.println(i - 2);

   }

}


댓글(0) 먼댓글(0) 좋아요(0)
좋아요
l 공유하기 l 북마크하기찜하기