2016 :: 아두이노 기초

프로젝트:: 무작정 프로세싱 (3)

실시간 레이더 그리기

 

void drawLine(){
  pushMatrix();
  translate(width/2, height);
  strokeWeight(4);
  stroke(98, 245, 31);
  line(0, 0, width/2*cos(radians(angle)), -width/2*sin(radians(angle)));
  popMatrix();
}

 

void drawObject(){
  pushMatrix();
  translate(width/2, height);
  strokeWeight(4);
  stroke(255, 10, 10); // red color
  float d = (width/2.0/30.0)*(float)distance;
  
  if( d < width/2)
    line(d*cos(radians(angle)), -d*sin(radians(angle)), width/2*cos(radians(angle)), -width/2*sin(radians(angle)));
  popMatrix();
}

 

중간코드

import processing.serial.*;

Serial myPort;
String myString = null;
int angle;
int distance;

void setup(){
  size(1200, 700);
  background(0);
  myPort = new Serial(this, "COM14", 9600);
}

void draw(){
  noStroke();
  fill(0, 7);
  rect(0, 0, width, height);
  
  //drawLine();
  drawObject();
}

void serialEvent(Serial p){
    try{
      myString = p.readStringUntil('.');
      if(myString != null){
        String[] list = split(myString, ',');
        angle = int(list[0]);
        distance = int(list[1].replace(".",""));
        
        print("Angle : "+angle);
        println(" Distance : "+distance + "cm");
      }
    }catch(Exception e){
    }
}

void drawLine(){
  pushMatrix();
  translate(width/2, height);
  strokeWeight(4);
  stroke(98, 245, 31);
  line(0, 0, width/2*cos(radians(angle)), -width/2*sin(radians(angle)));
  popMatrix();
}

void drawObject(){
  pushMatrix();
  translate(width/2, height);
  strokeWeight(4);
  stroke(255, 10, 10); // red color
  float d = (width/2.0/30.0)*(float)distance;
  
  if( d < width/2)
    line(d*cos(radians(angle)), -d*sin(radians(angle)), width/2*cos(radians(angle)), -width/2*sin(radians(angle)));
  popMatrix();
}

 

댓글

댓글 본문
작성자
비밀번호
  1. JustStudy
    고맙습니다
버전 관리
YJ
현재 버전
선택 버전
graphittie 자세히 보기