# How to map rotation of 180 degree multiples to scale from +1 to -1?

I have an object that continually rotates on the y-axis. I want to scale it, so that it periodically gets scaled down to -1 and then back up to +1. So at 0° the scale should be 1, at 180° -1, at 360° 1 again and continuing that over 360°.

I tried using a driver, but didn't get anywhere. First I convert the total rotation into the amount over the next lower full multiple of 360 using this function:

((x * 180 / pi) / 180) % 1


It converts radians to degrees, than divides by 180 to find out how many multiples of 180 is inside of x and reduces the result modulo 1. This linearlly maps 0° to 0 and 180° to 1. Now, I moved it down using -0.5 and multiplied it by 2 to get 180° back up to 1, to get this function:

((((x * 180 / pi) / 180) % 1)-0.5)*2


Graphing this function looks like this:

The Problem here is the jarring jump from 1 to -1.

Ideally, I need a function that looks roughly like the green graph in the picture below, however it doesn't need to be linear, the important thing is that 0° matches -1 and 180° 1 etc. as exact as possible to prevent small shifts turning into big shifts at values like 30,000°+: