Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Exit

- Home
- After Effects
- Discussions
- Trouble converting negative integers to positive v...

- Trouble converting negative integers to positive v...

0

/t5/after-effects-discussions/trouble-converting-negative-integers-to-positive-values-lt-360/td-p/14068466
Sep 07, 2023
Sep 07, 2023

Copy link to clipboard

Copied

Hello, I'm looking to create an expression that, when/if a value becomes a negative integer, 360 is added to it so that it becomes a positive integer <360. For example, if a certain value is -17 then the displayed value is 343. I'm beginning with this expression. It works fine, except when the slider goes into negative numbers, which, the way things are designed, it has to do sometimes.

val1 = thisComp.layer("Controls").effect("Heading Slider")("Slider")/388.89 val2= val1*100 Math.round(val2)

The slider is set to values 1-1400, hence the /388.89. Much appreciate the help! I'm still an expression newbie.

TOPICS

Expressions

Community guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Community Expert
,
Sep 07, 2023
Sep 07, 2023

Try this:

```
val1 = thisComp.layer("Controls").effect("Heading Slider")("Slider")/388.89;
val2= Math.round(val1*100);
val2 < 0 ? val2 + 360 : val2
```

3
Replies
3

/t5/after-effects-discussions/trouble-converting-negative-integers-to-positive-values-lt-360/m-p/14068723#M236125
Sep 07, 2023
Sep 07, 2023

Copy link to clipboard

Copied

Try this:

```
val1 = thisComp.layer("Controls").effect("Heading Slider")("Slider")/388.89;
val2= Math.round(val1*100);
val2 < 0 ? val2 + 360 : val2
```

Community guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/after-effects-discussions/trouble-converting-negative-integers-to-positive-values-lt-360/m-p/14069112#M236142
Sep 07, 2023
Sep 07, 2023

Copy link to clipboard

Copied

This is how I would approach the problem. I'm assuming you are trying to display heading information, so you need an expression that turns the rotation value into numbers between zero and 359 to give you a compass heading.

You can use an Angle Control instead of a Slider and this expression.

```
v = effect("Angle Control")("Angle").value.toFixed();
rNum = Math.floor(v)/360;
n = Math.floor(rNum);
aFix = 360 * n;
a = v - aFix;
Math.abs(a)
```

You could also use a slider, but if you used an angle control, you could visualize the compass heading.

The rNum sets up a counter that counts the number of 360º rotations, and then n makes the number of rotations a whole number. If you multiply the number of rotations times 360 and subtract that number from the angle value (v), you get a number that varies between plus and minus 360. The Math.abs(a) function always keeps the value positive.

When you get a handle on the basic Math operators in Javascript, sketching the problem out with a pencil and paper will give you the formula always to display a number between zero and 360. No if/else statements are required.

Community guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

lehestro
AUTHOR

Engaged
,

LATEST
/t5/after-effects-discussions/trouble-converting-negative-integers-to-positive-values-lt-360/m-p/14089231#M236546
Sep 15, 2023
Sep 15, 2023

Copy link to clipboard

Copied

Oh man, thanks so much, both of you! I inherited the project, and the previous person had it set up with a slider. I didn't even realize angle control was a possibility. This is so very helpful. Thank you guys!

I really know very little about code or expressions, and it's fun to reverse engineer what you wrote to see how it all works. Much appreciated!

Community guidelines

Resources

Troubleshooting FAQs

After Effects Community Recap

Getting started with After Effects

Copyright © 2023 Adobe. All rights reserved.