Processing Radar
Processing Radar
*;
import java.util.ArrayList;
Serial myPort;
String angle = "";
String distance = "";
String data = "";
int iAngle = 0, iDistance = 0;
ArrayList<PVector> points;
PFont myFont;
boolean resetPoints = false;
void setup() {
size(800, 600);
smooth();
myPort = new Serial(this, "COM5", 9600);
myPort.bufferUntil('.');
void draw() {
background(0, 100, 0); // xanh đậm
drawRadar();
drawObjects();
drawSweep();
drawText();
void drawRadar() {
pushMatrix();
translate(width/2, height*0.95);
stroke(0, 255, 0);
strokeWeight(2);
noFill();
popMatrix();
}
void drawObjects() {
pushMatrix();
translate(width/2, height*0.95);
noStroke();
fill(255, 153, 0); // cam
for (int i = 0; i < points.size(); i++) {
ellipse(points.get(i).x, points.get(i).y, 6, 6);
}
popMatrix();
}
void drawSweep() {
pushMatrix();
translate(width/2, height*0.95);
stroke(255);
strokeWeight(2);
float x = (width/2 * 0.9) * cos(radians(iAngle));
float y = -(width/2 * 0.9) * sin(radians(iAngle));
line(0, 0, x, y);
popMatrix();
}
void drawText() {
fill(0, 200);
noStroke();
rect(0, 0, width, 40);
fill(255);
textAlign(LEFT);
text("Angle: " + iAngle + "°", 10, 25);
text("Distance: " + iDistance + " cm", 200, 25);
}