We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
Answers
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?
maybe this can help you
storing all distance readings in an ArrayLIst and display from there....
;-)