virtual wind vane
in
Programming Questions
•
9 months ago
i m creating a virtual wind vane on processing using a potentiometer .Using an Arduino for the same .
So the data to the processing program would be a number between 0 and 360 ( 0 corresponds to north exact ).
Say 0 is North exactly ,so a line starting from origin will point to 0 on a background picture of a degree wheel Im using .
I want the line to rotate by an angle according to the incoming data .
One way of doing this is to find the co-ordinates where i want the line to end on the picture and use switch() .But this makes the program too long .....imagine 360 cases .
Please tell me if u have an alternate idea to implement this .I hav included a sample code using switch() that I tried out and also the picture.
Thanks!!!
So the data to the processing program would be a number between 0 and 360 ( 0 corresponds to north exact ).
Say 0 is North exactly ,so a line starting from origin will point to 0 on a background picture of a degree wheel Im using .
I want the line to rotate by an angle according to the incoming data .
One way of doing this is to find the co-ordinates where i want the line to end on the picture and use switch() .But this makes the program too long .....imagine 360 cases .
Please tell me if u have an alternate idea to implement this .I hav included a sample code using switch() that I tried out and also the picture.
Thanks!!!
- int i=0;
PImage img;
void setup()
{
size(500,500);
img = loadImage("degree-wheel.png");
}
void draw()
{
println(mouseX);
println(mouseY);
image(img, 0, 0);
i++;
drawNow();
delay(1000);
}
void drawNow()
{
if(i>4)
{
i=0;
}
switch(i)
{
case 1:
line(250, 250, 249, 5);
break;
case 2:
line(250, 250, 292, 9);
break;
case 3:
line(250, 250, 372, 38);
break;
case 4:
line(250, 250, 407, 62);
break;
}
}
1