The rotation of a rectangle

I drew a rectangle in the vision, and when a bool variable is true, the rectangle starts rotating 10 ° every second. What should I do? Thank you very much :star_struck:

1 Like

My original answer was incorrect. toRadians is not required as the angle property uses degrees. Correct version shown below.

2 Likes

While this will probably work for a while, this approach is prone to a cumulative floating point errors that will eventually result in unexpected behaviors. Something with explicitly integer angles, such as the style customizer, a timer component, or evan an expression binding with a case statement are the preferred method for rotating animations in Vision.

1 Like

How come? I appreciate that the now(1000) won't fire on a 0 ms transition so the script could probably do with an int() to fix this, but where is the opportunity for cumulative errors? The % modulo arithmetic should prevent that.

Perhaps you're right. On my phone, I see this in your picture, so it makes me think there is a fractional element to this approach.
Screenshot_20231212-061711-266

That's probably from the toRadians() function.

Because converting to radians requires the use of Pi

A better solution in this instance is to just force the addition of 10 every second. I would probably lean towards a timer component.

1 Like

I also like to use the canvas with a timer component for this sort of thing.

1 Like

Agree particularly for complex shapes. Also prevents the shape from flying off the screen, though if the position isn't changing that shouldn't be an issue.

1 Like

That will definitely cause a creep due to the π rounding error (but see below).

I'm not arguing for my solution in particular. I don't work in Vision anymore and on further inspection the angle is in degrees, not radians! I'll edit my original answer. The new one uses floor() to ensure that the rectangle starts at 0° and there is no creep.

2 Likes

Thank you very much for your enthusiastic help

As a user of traditional scada, I was greatly shocked by the experience with igniton. Once again, thank you and other friends for providing me with ideas

getsecond( now() )*10.
This should be simpler.

1 Like

getsecond( now() ) * 10
should be simpler.

Yes, but gives you 0°, 10°, 20°, ... 340°, 350° 360°, 370° ..., 580°, 590° before resetting with a big jump.