실시간 레이더 그리기
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(); } |