OPENLABS

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

실시간 레이더 그리기

 

1
2
3
4
5
6
7
8
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();
}

 

1
2
3
4
5
6
7
8
9
10
11
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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. 네! dydwo92@snu.ac.kr로 보내주세요~:)
    대화보기
    • 김영우
      개인적으로 e-mail로 물어볼 수 있을까요 ?
      processing과 아두이노를 처음 접하는데 서로 통신으로 주고받는 부분이 이해가 안됩니다.
    • JustStudy
      고맙습니다
    버전 관리
    YJ
    현재 버전
    선택 버전
    공동공부
    graphittie 자세히 보기