Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. import processing.serial.*;
  2. import java.awt.event.KeyEvent;
  3. import java.io.IOException;
  4.  
  5. Serial myPort;
  6. String angle = "";
  7. String distance = "";
  8. String data = "";
  9. String noObject;
  10. float pixsDistance;
  11. int iAngle, iDistance;
  12. int index1 = 0;
  13. int index2 = 0;
  14. PFont orcFont;
  15. void setup() {
  16.  
  17.  
  18. size (1290, 760); // DISPLAY GRÖßE EINTRAGEN /Auflösung
  19. smooth();
  20. myPort = new Serial(this, "COM3", 9600);
  21. myPort.bufferUntil('.');
  22. orcFont = loadFont("AlbertusMedium-48.vlw");
  23. }
  24. void draw() {
  25.  
  26. fill(98, 245, 31);
  27. textFont(orcFont);
  28. noStroke();
  29. fill(0, 4);
  30. rect(0, 0, width, height - height * 0.065);
  31.  
  32. fill(98, 245, 31);
  33. drawRadar();
  34. drawLine();
  35. drawObject();
  36. drawText();
  37. }
  38. void serialEvent (Serial myPort) {
  39. data = myPort.readStringUntil('.');
  40. data = data.substring(0, data.length() - 1);
  41.  
  42. index1 = data.indexOf(",");
  43. angle = data.substring(0, index1);
  44. distance = data.substring(index1 + 1, data.length());
  45.  
  46. // von String auf Integer
  47. iAngle = int(angle);
  48. iDistance = int(distance);
  49. }
  50. void drawRadar() {
  51. pushMatrix();
  52. translate(width / 2, height - height * 0.074); // start koordinaten werden festgelegt
  53. noFill();
  54. strokeWeight(2);
  55. stroke(#FFFFFF);
  56. arc(0, 0, (width - width * 0.0625), (width - width * 0.0625), PI, TWO_PI);
  57. arc(0, 0, (width - width * 0.27), (width - width * 0.27), PI, TWO_PI);
  58. arc(0, 0, (width - width * 0.479), (width - width * 0.479), PI, TWO_PI);
  59. arc(0, 0, (width - width * 0.687), (width - width * 0.687), PI, TWO_PI);
  60. line(-width / 2, 0, width / 2, 0);
  61. line(0, 0, (-width / 2)*cos(radians(30)), (-width / 2)*sin(radians(30)));
  62. line(0, 0, (-width / 2)*cos(radians(60)), (-width / 2)*sin(radians(60)));
  63. line(0, 0, (-width / 2)*cos(radians(90)), (-width / 2)*sin(radians(90)));
  64. line(0, 0, (-width / 2)*cos(radians(120)), (-width / 2)*sin(radians(120)));
  65. line(0, 0, (-width / 2)*cos(radians(150)), (-width / 2)*sin(radians(150)));
  66. line((-width / 2)*cos(radians(30)), 0, width / 2, 0);
  67. popMatrix();
  68. }
  69. void drawObject() {
  70. pushMatrix();
  71. translate(width / 2, height - height * 0.074);
  72. strokeWeight(9);
  73. stroke(#FF0004);
  74. pixsDistance = iDistance * ((height - height * 0.1666) * 0.025); // von cm auf pixel
  75. // limitierung auf max 40 cm
  76. if (iDistance < 40) {
  77.  
  78. line(pixsDistance * cos(radians(iAngle)), -pixsDistance * sin(radians(iAngle)), (width - width * 0.505)*cos(radians(iAngle)), -(width - width * 0.505)*sin(radians(iAngle)));
  79. }
  80. popMatrix();
  81. }
  82. void drawLine() {
  83. pushMatrix();
  84. strokeWeight(9);
  85. stroke(#00FF0E);
  86. translate(width / 2, height - height * 0.074);
  87. line(0, 0, (height - height * 0.16)*cos(radians(iAngle)), -(height - height * 0.16)*sin(radians(iAngle)));
  88. popMatrix();
  89. }
  90. void drawText() { // text auf display ausgeben
  91.  
  92. pushMatrix();
  93. if (iDistance > 40) {
  94. noObject = "Außer Reichweite";
  95. } else {
  96. noObject = "In Reichweite";
  97. }
  98. fill(0, 0, 0);
  99. noStroke();
  100. rect(0, height - height * 0.0648, width, height);
  101. fill(#FFFFFF);
  102. textSize(25);
  103.  
  104. text("10cm", width - width * 0.4154, height - height * 0.0833);
  105. text("20cm", width - width * 0.3010, height - height * 0.0833);
  106. text("30cm", width - width * 0.1970, height - height * 0.0833);
  107. text("40cm", width - width * 0.1045, height - height * 0.0833);
  108. textSize(40);
  109. text("Winkel: " + iAngle + " °", width - width * 0.48, height - height * 0.0277);
  110. text("Objekt: " + noObject, width - width * 0.875, height - height * 0.0277);
  111. text("Distanz: ", width - width * 0.29, height - height * 0.0277);
  112. if (iDistance < 40) {
  113. text(" " + iDistance + " cm", width - width * 0.225, height - height * 0.0277);
  114. }
  115. textSize(25);
  116. fill(#FFFFFF);
  117. translate((width - width * 0.4994) + width / 2 * cos(radians(30)), (height - height * 0.0907) - width / 2 * sin(radians(30)));
  118. rotate(-radians(-30));
  119. text("30°", 0, 0);
  120. resetMatrix();
  121. translate((width - width * 0.503) + width / 2 * cos(radians(60)), (height - height * 0.0888) - width / 2 * sin(radians(60)));
  122. rotate(-radians(-30));
  123. text("60°", 0, 0);
  124. resetMatrix();
  125. translate((width - width * 0.507) + width / 2 * cos(radians(90)), (height - height * 0.0833) - width / 2 * sin(radians(90)));
  126. rotate(radians(0));
  127. text("90°", 0, 0);
  128. resetMatrix();
  129. translate(width - width * 0.513 + width / 2 * cos(radians(120)), (height - height * 0.07129) - width / 2 * sin(radians(120)));
  130. rotate(radians(-30));
  131. text("120°", 0, 0);
  132. resetMatrix();
  133. translate((width - width * 0.5104) + width / 2 * cos(radians(150)), (height - height * 0.0574) - width / 2 * sin(radians(150)));
  134. rotate(radians(-30));
  135. text("150°", 0, 0);
  136. popMatrix();
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement