I just wrote a very simple code to illustrate a question I have as new aspiring processing coder. When I am writing code, I always come to the point that I would like to encapsulate the variables (here: float x = 0.0;) that belong to a function or class into its code to have clean logical groups. Unfortunately I cannot do that as they have to be initialized outside the function to work right!? Is there any way to initialize a variable inside a function just once and not everytime it is triggered by draw() ?
float x = 0.0;
void setup()
{
}
void draw()
{
println(countUp( 0.5));
}
float countUp( float speed){
x = x + speed;
return x;
}
I would like to check if a mouse position is inside the space of an arc shape. To do this I first check if the point is within the radius of the arc. Then I would like to test if the mouse position is within the end- and start degree of the arc.
I used following code and good old trigonometry to get the sinus of the given mouse position:
if (pointLength<= 100)
{
degree = degrees(asin((yenterArcY-mouseY)/pointLength))
}
My problem of course is that i cannot convert sin to radians and I get no precise radians or degree value! :-( Do you know a solution? Hope this is a piece of cake for somebody of you ! :-)