#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# How to rotate a line in a circle (radar like), while also plotting distance reading points?

edited February 2015

I am trying to rotate a line around in a circle that represents the direction a sensor is facing, while also plotting distance measurements. So I can't use background() in the draw function to clear the screen, because it erases the plotting of the distance readings. I've tried pggraphics and a few others ways, but can't seem to find a way to do it.

This is what I have right now:

``````void setup() {
background(255,255,255);
size(540, 540);
}

void draw() {
translate(width/2, height/2);
ellipse(0,0,100,100);
newX = x*cos(theta)- y*sin(theta);
newY = x*sin(theta)+ y*cos(theta);

theta = theta + PI/100;
//pushMatrix();
fill(255, 255);
line(0, 0, newX, newY);
rotate(theta);
//popMatrix();
}
``````

I am new to Processing, and coding in general, but can anyone point me in the right direction on how to do this? Thanks

Tagged:

• what are x and y on lines 9 and 10? you haven't defined them...

BUT, you don't need to - they are the radius of the ellipse in line 8 - replace them with 100.

delete line 16 - you don't need to rotate(), you are working out the rotation yourself in lines 9 and 10.

you need to define theta. do it at the top of the file.

• koogs- I forgot to include the top of the file:```int x = 1000; int y = -1000; float newX, newY; float theta; PGraphics pg;```

I can get the line to rotate just fine, its just I can't figure out how to erase the previous line without calling background(). Do you know how I could do this? Possibly using a pushMatrix or pgGraphic?

• just use background

• I see

• you don't do plotting of the distance readings yet, right?

storing all distance readings in an ArrayLIst and display from there....

;-)

``````// to store all distance readings
ArrayList<PVector> list = new ArrayList();

int x;
int y = -1000;
float newX, newY;
float newX2, newY2;
float oldX, oldY;
float theta;
PGraphics pg;

void setup() {
background(255, 255, 255); // white
size(540, 540);
frameRate(5);
}

void draw() {
translate(width/2, height/2);

stroke(0, 0, 243);
ellipse(0, 0, 100, 100);
newX = x*cos(theta)- y*sin(theta);
newY = x*sin(theta)+ y*cos(theta);

float r1 = random(0.0, 120.0);

newX2 = r1*cos(theta);
newY2 = r1*sin(theta);

theta = theta + PI/100;
//pushMatrix();

// delete
strokeWeight(2);
stroke(255);// white
line(0, 0, oldX, oldY);
strokeWeight(1);

/// draw
stroke(0);
line(0, 0, newX, newY);